From 6129edce0889d57103628ed4a63ce9579063f57f Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Tue, 28 Sep 2021 20:49:50 +0530 Subject: [PATCH] fix: dialogflow integration in docker environments (#3072) * natively compile ruby gems * add missing compiler tools * add bundler platform ruby to force native compilation * fix bundler env in final docker stage * add comments to DockerFile Co-authored-by: Sojan Jose --- Gemfile.lock | 9 +++++++++ docker/Dockerfile | 8 ++++++++ docker/entrypoints/rails.sh | 1 + 3 files changed, 18 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 45a7b9133..f89baf242 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -247,6 +247,7 @@ GEM google-cloud-core (~> 1.6) googleauth (>= 0.16.2, < 2.a) mini_mime (~> 1.0) + google-protobuf (3.17.3) google-protobuf (3.17.3-universal-darwin) google-protobuf (3.17.3-x86_64-linux) googleapis-common-protos (1.3.11) @@ -264,6 +265,9 @@ GEM signet (~> 0.14) groupdate (5.2.2) activesupport (>= 5) + grpc (1.38.0) + google-protobuf (~> 3.15) + googleapis-common-protos-types (~> 1.0) grpc (1.38.0-universal-darwin) google-protobuf (~> 3.15) googleapis-common-protos-types (~> 1.0) @@ -346,6 +350,7 @@ GEM mime-types-data (3.2021.0704) mini_magick (4.11.0) mini_mime (1.1.1) + mini_portile2 (2.5.3) minitest (5.14.4) mock_redis (0.28.0) ruby2_keywords @@ -360,6 +365,9 @@ GEM netrc (0.11.0) newrelic_rpm (7.2.0) nio4r (2.5.8) + nokogiri (1.11.7) + mini_portile2 (~> 2.5.0) + racc (~> 1.4) nokogiri (1.11.7-arm64-darwin) racc (~> 1.4) nokogiri (1.11.7-x86_64-darwin) @@ -617,6 +625,7 @@ GEM PLATFORMS arm64-darwin-20 + ruby x86_64-darwin-18 x86_64-darwin-20 x86_64-darwin-21 diff --git a/docker/Dockerfile b/docker/Dockerfile index 7b595a111..e51a86379 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -33,6 +33,11 @@ WORKDIR /app COPY Gemfile Gemfile.lock ./ +# natively compile grpc and protobuf to support alpine musl (dialogflow-docker workflow) +# https://github.com/googleapis/google-cloud-ruby/issues/13306 +RUN apk add --no-cache musl ruby-full ruby-dev gcc make musl-dev openssl openssl-dev g++ linux-headers +RUN bundle config set --local force_ruby_platform true + # Do not install development or test gems in production RUN if [ "$RAILS_ENV" = "production" ]; then \ bundle config set without 'development test'; bundle install -j 4 -r 3; \ @@ -71,6 +76,9 @@ ENV EXECJS_RUNTIME ${EXECJS_RUNTIME} ARG RAILS_SERVE_STATIC_FILES=true ENV RAILS_SERVE_STATIC_FILES ${RAILS_SERVE_STATIC_FILES} +ARG BUNDLE_FORCE_RUBY_PLATFORM=1 +ENV BUNDLE_FORCE_RUBY_PLATFORM ${BUNDLE_FORCE_RUBY_PLATFORM} + ARG RAILS_ENV=production ENV RAILS_ENV ${RAILS_ENV} ENV BUNDLE_PATH="/gems" diff --git a/docker/entrypoints/rails.sh b/docker/entrypoints/rails.sh index 8bdf0551c..77657f6ee 100755 --- a/docker/entrypoints/rails.sh +++ b/docker/entrypoints/rails.sh @@ -20,6 +20,7 @@ done echo "Database ready to accept connections." +#install missing gems for local dev as we are using base image compiled for production bundle install BUNDLE="bundle check"