简体   繁体   中英

Google cloud ruby deployment and ruby-docker

I am trying to put my rails project on the google cloud engine for the first time and I have a lot of trouble. I've wanted to upload my project with a custom runtime app.yaml (because I would like yarn to install the dependencies as well), but the deployment command fails with this error:

Error Response: [4] Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.

PS: the app runs locally (development and production env).

My app.yaml looks like this:

entrypoint: bundle exec rails s -b '0.0.0.0' --port $PORT
env: flex
runtime: custom
env_variables:
  My Environment variables

beta_settings:
  cloud_sql_instances: ekoma-app:us-central1:ekoma-db

readiness_check:
  path: "/_ah/health"
  check_interval_sec: 5
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 1
  app_start_timeout_sec: 120

And my Dockerfile looks like this:

FROM l.gcr.io/google/ruby:latest

RUN apt-get update -qq && apt-get install apt-transport-https

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev imagemagick yarn
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
COPY package.json /app/package.json
COPY yarn.lock /app/yarn.lock

RUN gem install pkg-config -v "~> 1.1"
RUN bundle install && npm install

COPY . /app

When deploying with a ruby runtime I realized that the dockerfile generated was much more complex and probably complete and google provide a repo to generate it. So, I tried to look into the ruby-docker public repo that google shared but I don't know how to use their generated docker images and therefore fix my Dockerfile issue

https://github.com/GoogleCloudPlatform/ruby-docker

Could someone help me figure what's wrong in my setup and how to run these ruby-docker image (seems very useful!)?

Thank you!

The "entrypoint" field in app.yaml is not used when a custom runtime is in play. Instead, set the CMD in your Dockerfile. eg:

CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0", "--port", "8080"]

That probably will get your application running. (Remember that environment variables are not interpolated in exec form, so I replaced your $PORT with the hard-coded port 8080, which is the port App Engine expects.)

As an alternative:

It may be possible to use the Ruby runtime images in the ruby-docker repo, and not have to use a custom runtime (ie you may not need to write your own Dockerfile), even if you have custom build steps like doing yarn installs. Most of the build process in runtime: ruby is customizable, but it's not well-documented. If you want to try this path, the TL;DR is:

  1. Use runtime: ruby in your app.yaml and don't provide your own Dockerfile. (And reinstate the entrypoint of course.)

  2. If you want to install ubuntu packages not normally present in runtime: ruby , list them in app.yaml under runtime_config : packages . For example:

     runtime_config: packages: - libgeos-dev - libproj-dev 
  3. If you want to run custom build steps, list them in app.yaml under runtime_config : build . They get executed in the Dockerfile after the bundle install step (which cannot itself be modified). For example:

     runtime_config: build: - npm install - bundle exec rake assets:precompile - bundle exec rake setup_my_stuff 

    Note that by default, if you don't provide custom build steps, the ruby runtime behaves as if there is one build step: bundle exec rake assets:precompile || true bundle exec rake assets:precompile || true . That is, by default, runtime: ruby will attempt to compile your assets during app engine deployment. If you do modify the build steps and you want to keep this behavior, make sure you include that rake task as part of your custom build steps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM