AgileVentures / WebsiteOne

A website for Agile Ventures

Home Page:https://www.agileventures.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document and test deployment to google cloud

mattlindsey opened this issue · comments

Google gives you $300 for a 90 day trial of Google cloud.
Sign up for that, then follow first 3 steps here to create a new project and install the google cloud CLI:
https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-ruby-service

Then follow these steps to deploy the site in a docker image on google cloud:
https://gist.github.com/iEv0lv3/8f877bbd3d27f6a670435bda0650d7d8

Use this page to help configure your build:
https://cloud.google.com/build/docs/deploying-builds/deploy-cloud-run

I almost have this working, but wanted to put my notes so far here:

  1. Only a few 'regions' support the build process, so use some combination of these commands:
    gcloud config set compute/region us-central1
    gcloud builds submit --region=us-central1
    gcloud compute project-info add-metadata --metadata google-compute-default-zone=us-centra11\n

  2. Sample cloudbuild.yaml

steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/websiteone-372019/websiteone-web', '.']
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
  args: ['push', 'gcr.io/websiteone-372019/websiteone-web']
# Deploy container image to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
  entrypoint: gcloud
  args: ['run', 'deploy', 'websiteone-web', '--image', 'gcr.io/websiteone-372019/websiteone-web', '--region', 'us-central1']
images:
- gcr.io/websiteone-372019/websiteone-web
  1. In the sample file above, I put the name of the Google Service that I created called 'websiteone-web' which should create a permanent URL.

Notes on some other changes that may be needed.

Dockerfile:

# Expose Puma port
EXPOSE 8080

# Designate the initial sript to run on container startup
RUN chmod +x /WebsiteOne/entrypoint.sh
ENTRYPOINT ["/WebsiteOne/entrypoint.sh"]

entrypoint.sh

#!/usr/bin/env bash

cd /WebsiteOne

# Create the Rails production DB on first run
RAILS_ENV=production bundle exec rake db:create

# Make sure we are using the most up to date
# database schema
RAILS_ENV=production bundle exec rake db:migrate

# Do some protective cleanup
> log/production.log
rm -f tmp/pids/server.pid

# Run the web service on container startup
# $PORT is provided as an environment variable by Cloud Run
bundle exec rails server -e production -b 0.0.0.0 -p $PORT

fixed by #3821