Cloud-init file to boot a Rails app meant to be used with Google's Container Optimized OS.
See also, My own Heroku in 30 mins - Deploy Rails apps to Google Cloud Compute Engine.
- Use as
user-data
metadata field with a Compute Engine VM. - Search and replace the following variables:
${{DOCKER_IMAGE}}
${{SECRETS_PREFIX}}
- Create Google Secret
<SECRETS_PREFIX>_CLOUDSQL_INSTANCE
with connection string value likemy-project:region:my-sql-instance
.
This boot script installs a couple of helpers which can be accessed from within the VM:
rails
- helps starting docker containersconsole
- Start a Rails consoleproject_id
- Returns the VM's projectaccess_token
- Returns a Access Tokenfetch_secret <secret>
- Fetches a secret from the Secret Managerjq
- Parses JSON.
make build # will build dist/cloud-init.yml
SSH into a machine that was started with this cloud-init file and you'll find the following commands useful for debugging:
sudo journalctl -f
cat /var/log/rails-cmd.log
tail -n100 -f /var/log/cloud-init-output.log