Simple test Phoenix app to deploy in a container.
You will need the following:
Google Cloud account Billing setup on Google Cloud account Enable Cloud Run API Enable Google Container Registry (GCR) API
In this example our Agent will be running on our local machine (super low cost). To do this, set up a local agent with Buildkite
Agent requirements:
Bash Docker gcloud CLI
Firstly login to your Google Cloud account with the gcloud CLI
gcloud auth login
First configure docker to use the gcloud command-line tool as a credential helper (only need to run once)
gcloud auth configure-docker
Set any Agent environment variables required for build (Mac OS)
vim /usr/local/etc/buildkite-agent/hooks/environment
Add env vars
export DOCKER_LOGIN_PASSWORD=supersecretpassword
export GCLOUD_PROJECT_ID=project-id
export GCLOUD_SERVICE_NAME=cloud-run-service-name
Start the local agent:
buildkite-agent start
Set the project secret
mix phx.gen.secret
> REALLY_LONG_SECRET
export SECRET_KEY_BASE=REALLY_LONG_SECRET
mix deps.get --only prod
MIX_ENV=prod mix compile
npm run deploy --prefix ./assets
mix phx.digest
MIX_ENV=prod mix release
docker build -t elixir-container .
docker run --publish 4000:4000 --env COOL_TEXT='ELIXIR ROCKS!!!!' --env SECRET_KEY_BASE=SECRET_KEY_BASE --env APP_PORT=4000 elixir-container:latest
- Push to Github
- -> Run tests with BuildKite
- -> Build Docker Image in BuildKite
- -> Push image to Google Cloud Run
- -> Run image deployment from GCR to Cloud Run
- Secure deployment from GCR to Cloud Run rather than an
--allow-unauthenticated
- Split this into steps within a bash/make script
- Get runtime env vars working
https://akoutmos.com/post/multipart-docker-and-elixir-1.9-releases/
MIT Licensed. Use all you like at your own risky fun. Go nuts.
Happy coding λ