Skip to content

Instantly share code, notes, and snippets.

@vochicong
Last active May 11, 2017 00:27
Show Gist options
  • Save vochicong/8df32ed5c265ce3caec08d9f8b598eeb to your computer and use it in GitHub Desktop.
Save vochicong/8df32ed5c265ce3caec08d9f8b598eeb to your computer and use it in GitHub Desktop.
Deploy Rails app from Google Cloud Source Repo to App Engine

GCP ConsoleでCloud Source Repoに格納されているソースコードをApp Engineにデプロイする手順

Commands

gcloud source repos clone [REPO_NAME] [TARGET_DIR] --project=[PROJECT_ID]

where [REPO_NAME] is Cloud Source Repository name, [TARGET_DIR] is where to put the source code, and [PROJECT_ID] is App Engine Project ID.

Install anything required by your Rails app:

sudo apt-get install libmysqlclient-dev
bundle install

Test the Rails app locally:

bundle exec rails server --port=8080

Runtime configuration

Bellow, [DOMAIN] is your rails app domain, while [SECRET_KEY] is generated by the following command:

bundle exec rails secret

Configuration file: app.yml

runtime: ruby
env: flex
entrypoint: bundle exec rackup -p $PORT

env_variables:
  SECRET_KEY_BASE: [SECRET_KEY]
  DOMAIN_NAME=[DOMAIN]

Configuration file: .ruby-version

2.4.1

Precompile Rails assets before deployment:

SECRET_KEY_BASE=[SECRET_KEY] DOMAIN_NAME=[DOMAIN] RAILS_ENV=production bundle exec rails assets:precompile
gcloud app deploy --project [PROJECT_ID]

Browse your app at https://[PROJECT_ID].appspot.com.

References

TODO

  • Cloud SQL
  • Env vars for App Engine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment