📎 Webclip
Deploy on Ubuntu with mix release and Github Actions (without Docker)
The author describes a simple setup to deploy an Elixir/Phoenix application on a low-cost Ubuntu server using mix release and GitHub Actions without Docker. The process relies on a deploy.sh script on the server that pulls master, builds a production release, runs migrations, and restarts the app, triggered remotely via an SSH GitHub Action when code is pushed to the master branch.
Reading notes#
- mix release can assemble self-contained releases for an Elixir project, making deployment on a small Ubuntu server straightforward.
- Once Elixir and mix are installed on the server, a manual deploy can be done with
cd,git pull, andMIX_ENV=prod mix release. - GitHub Actions can run tests or SSH scripts after pushing code to a repository.
- The author wants to automate the link between pushing to master and deploying to the server.
- A
deploy.shscript is placed in the project root on the server, starting by sourcing~/.profileto load environment variables. - The script uses
set -eso it stops if any command fails. - It changes to the project folder, stashes local changes so master takes precedence, then pulls from
origin master. - The script runs
mix deps.getandmix phx.digestusing the asdf-managed mix binary under/root/.asdf/shims/mix. - It builds a production release with
MIX_ENV=prod /root/.asdf/shims/mix release --overwrite. - After building, the script runs database migrations via a release command that calls
ProjectNameRuntime.Release.migratethrough the release binary. - The script restarts the application using the release’s
restartcommand and prints “Deployment done!”. - A GitHub Actions workflow named “Deployment on master” is configured to trigger on pushes to the
masterbranch. - The workflow defines a
deployjob that runs onubuntu-latestand usesgarygrossgarten/github-action-ssh@releaseto connect to the server over SSH. - Environment variables in the workflow include SSH username and host, the private deployment key, and secrets such as signing salt, secret key base, project port, and
MIX_ENVset toprod. - The SSH action is configured with
script_stop: true, the server hostname, usernameroot, the private key secret, and a command that executes./your-project/deploy.shon the server. - With this setup, every merge to master automatically deploys the Elixir/Phoenix application to the server.
- The author contrasts this approach with heavier setups like CI pipelines, Kubernetes, or complex configurations and mentions fast deploy times as a benefit.
- The post closes by inviting feedback and suggestions for improving the deployment approach.
