An example project for deploying Elixir
Repo cogini/elixir-deploy-template, read from GitHub 13 h ago. cogini has not joined Take My Repo.
cogini/elixir-deploy-template is a public repo on GitHub by cogini. An example project for deploying Elixir. It declares the MIT license on GitHub. It is written mainly in Python, has 83 stars and last changed on 2018-08-24. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-24.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
This is a working example app which shows how to deploy a Phoenix app using
the principles from my blog post "Best practices for deploying Elixir
apps".
The blog post "Deploying your Phoenix app to Digital Ocean for
beginners"
has similar content, but is simplified for beginners. If you have any
questions, open an issue here or ping me on the #elixir-lang IRC channel on
Freenode, I am reachfh. Patches welcome.
It starts with a default Phoenix project with PostgreSQL database. First get the template running, then add the necessary changes to your own project.
It's regularly tested deploying to Digital Ocean with CentOS 7, Ubuntu 16.04, Ubuntu 18.04 and Debian 9.4. Digital Ocean's smallest $5/month Droplet runs Phoenix fine. The approach here works great for dedicated servers and cloud instances as well.
It uses Ansible, which is an easy-to-use standard tool for managing servers. Unlike edeliver, it has reliable and well documented primitives to handle logging into servers, uploading files and executing commands. It can also be used to support more complex deployment scenarios.
The actual work of checking out and deploying is handled by simple shell scripts which you run on the build server or from your dev machine via ssh, e.g.:
# Check out latest code and build release on server
ssh -A deploy@build-server build/deploy-template/scripts/build-release.sh
# Deploy release
ssh -A deploy@build-server build/deploy-template/scripts/deploy-local.sh
Check out the project from git on your local dev machine, same as you normally would:
git clone https://github.com/cogini/elixir-deploy-template
ASDF lets you manage multiple versions of Erlang, Elixir and Node.js. It is safe to install on your machine, it won't conflict with anything else, that's it's whole reason for existing.
Install ASDF as described in the ASDF docs.
After installing, log out of your shell and log back in to activate the
scripts in ~/.bashrc.
Install ASDF plugins for our tools:
asdf plugin-add erlang
asdf plugin-add elixir
asdf plugin-add nodejs
Install build dependencies.
On macOS, first install Homebrew, then run:
# Erlang
brew install autoconf automake libtool openssl wxmac
# Install Java (optional) to avoid popup prompts
# If you already have Java installed, you don't need to do this
brew cask install java
# Node.js
brew install gpg
bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring
For Linux, see the ASDF Erlang docs.
Use ASDF to install the versions of Erlang, Elixir and Node.js specified in the
.tool-versions file:
asdf install
Run this multiple times until everything is installed (should be twice).
Install Elixir libraries into the ASDF dir:
mix local.hex --if-missing --force
mix local.rebar --if-missing --force
# mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez --force
Install node libraries into the ASDF dir:
npm install -g brunch
Confirm that it works by building the app the normal way:
mix deps.get
mix deps.compile
mix compile
You should be able to run the app locally with:
mix ecto.create
(cd assets && npm install && node node_modules/brunch/bin/brunch build)
iex -S mix phx.server
open http://localhost:4000/
Install Ansible on your dev machine. On macOS, use pip, the Python package manager:
sudo pip install ansible
If pip isn’t already installed, run:
sudo easy_install pip
See the Ansible docs for other options.
We use ssh keys to control access to servers instead of passwords. This is more secure and easier to automate.
Generate an ssh key if you don't have one already:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Set a pass phrase to protect access to your key (optional but recommended). macOS and modern Linux desktops will remember your pass phrase in the keyring when you log in so you don't have to enter it every time.
Add the ~/.ssh/id_rsa.pub public key file to your GitHub account.
See the GitHub docs.
Go to Digital Ocean (affiliate link) and create a Droplet (virtual server).
~/.ssh/id_rsa.pub fileThe defaults for everything else are fine. Click the "Create" button.
Add the host to the ~/.ssh/config file on your dev machine:
Host web-server
HostName 123.45.67.89
The file permissions on ~/.ssh/config need to be secure or ssh will be unhappy:
chmod 600 ~/.ssh/config
Test it by connecting to the server:
ssh root@web-server
If it doesn't work, run ssh with -v flags to see what the problem is.
You can add more verbosity, e.g. -vvvv if you need more detail.
ssh -vv root@web-server
File permissions are the most common cause of problems with ssh. Another common problem is forgetting to add your ssh key when creating the Droplet. Destroy the Droplet and create it again.
Add the hosts to the groups in the Ansible inventory ansible/inventory/hosts
file in the project:
[web-servers]
web-server
[build-servers]
web-server
[db-servers]
web-server
[web-servers] is a group of web servers. web-server is the hostname from
the Host line in your .ssh/config file. [build-servers] is the group of
build servers. It can be the same as your web server. [db-servers] is the
group of database servers, which can be the same.
If you are using Ubuntu or Debian, add the host to the [py3-hosts] group, and
it will use the Python 3 interpreter that comes by default on the server.
The repo has multiple hosts in the groups for testing different OS versions, comment them out.
The configuration variables defined in inventory/group_vars/all apply to all hosts in
your project. They are overridden by vars in more specific groups like
inventory/group_vars/web-servers or for individual hosts, e.g.
inventory/host_vars/web-server.
Ansible uses ssh to connect to the server. These playbooks use ssh keys to
control logins to server accounts, not passwords. The users Ansible role
manages accounts.
The inventory/group_vars/all/users.yml file defines a global list of users and
system admins. It has a live user (me!), change it to match your details:
users_users:
- user: jake
name: "Jake Morrison"
github: reachfh
users_global_admin_users:
- jake
The inventory/group_vars/all/elixir-release.yml file specifies the
app settings:
# External name of the app, used to name directories and the systemd process
elixir_release_name: deploy-template
# Internal "Elixir" name of the app, used to by Distillery to name things
elixir_release_name_code: deploy_template
# Name of your organization or overall project, used to make a unique dir prefix
elixir_release_org: myorg
# OS user the app runs under
elixir_release_app_user: foo
# OS user for building and deploying the code
elixir_release_deploy_user: deploy
# Port that Phoenix listens on
elixir_release_http_listen_port: 4001
The inventory/group_vars/build-servers/vars.yml file specifies the build settings.
It specifies the project's git repo, which the Ansible playbook will check out on the build server:
# App git repo
app_repo: https://github.com/cogini/elixir-deploy-template
Run the following Ansible commands from the ansible dir in the project.
Do initial server setup:
ansible-playbook -u root -v -l web-servers playbooks/setup-web.yml -D
In this command, web-servers is the group of servers, but you could also
specify a specific host like web-server. Ansible allows you to work on groups
of servers simultaneously. Configuration tasks are generally written to be
idempotent, so we can run the playbook against all our servers and it will make
whatever changes are needed to get them up to date.
The -u flag specifies which user account to use on the server. We have to use
root to do the initial bootstrap, but you should generally use your own user
account, assuming it has sudo. The -v flag controls verbosity, you can add
more v's to get more debug info. The -D flag shows diffs of the changes
Ansible makes on the server. If you add --check to the Ansible command, it
will show you the changes it is planning to do, but doesn't actually run them.
These scripts are safe to run in check mode, but may give an error during the play
if required OS packages are not installed.
Set up the app (create dirs, etc.):
ansible-playbook -u root -v -l web-servers playbooks/deploy-app.yml --skip-tags deploy -D
Configure runtime secrets, setting the $HOME/.erlang.cookie file and
generate a Conform config file at
/etc/deploy-template/deploy_template.conf:
ansible-playbook -u root -v -l web-servers playbooks/config-web.yml -D
For ease of getting started, this generates secrets on your local machine and
stores them in /tmp. See below for discussion about managing secrets.
At this point, the web server is set up, but we need to build and deploy the app code to it.
This can be the same as the web server or a separate server.
Set up the server:
ansible-playbook -u root -v -l build-servers playbooks/setup-build.yml -D
This sets up the build environment, e.g. installing ASDF.
Install PostgreSQL, assuming we are running the web app on the same server.
ansible-playbook -u root -v -l build-servers playbooks/setup-db.yml -D
Configure config/prod.secret.exs on the build server:
ansible-playbook -u root -v -l build-servers playbooks/config-build.yml -D
Again, see below for discussion about managing secrets.
Log into the deploy user on the build machine:
ssh -A deploy@build-server
cd ~/build/deploy-template
The -A flag on the ssh command gives the session on the server access to your
local ssh keys. If your local user can access a GitHub repo, then the server
can do it, without having to put keys on the server. Similarly, if the prod
server is set up to accept your ssh key, then you can push code from the build server using
Ansible without the web server needing to trust the build server.
If you are using a CI server to build and deploy code, then it runs in the
background. Create a deploy key in GitHub so it can access to your source and
add the ssh key on the build server to the deploy user account on the web
servers so the CI server can push releases.
Build the production release:
scripts/build-release.sh
That script runs:
echo "Pulling latest code from git"
git pull
echo "Updating versions of Erlang/Elixir/Node.js if necessary"
asdf install
echo "Updating Elixir libs"
mix local.hex --if-missing --force
mix local.rebar --if-missing --force
mix deps.get --only "$MIX_ENV"
echo "Compiling"
mix compile
echo "Updating node libraries"
(cd assets && npm install && node node_modules/brunch/bin/brunch build)
echo "Building release"
mix do phx.digest, release
asdf install builds Erlang from source, so the first time it runs it can take
a long time. If it fails due to a lost connection, delete
/home/deploy/.asdf/installs/erlang/20.3 and try again.
You may want to run it under tmux.
If you are building on the web web server, then you can use the custom mix
tasks in lib/mix/tasks/deploy.ex to deploy locally.
In mix.exs, set deploy_dir to match Ansible, i.e.
deploy_dir: /opt/{{ org }}/{{ elixir_release_name }}:
deploy_dir: "/opt/myorg/deploy-template/",
Deploy the release:
scripts/deploy-local.sh
That script runs:
MIX_ENV=prod mix deploy.local
sudo /bin/systemctl restart deploy-template
The build is being done under the deploy
cogini/elixir-deploy-template is a public repo on GitHub by cogini. An example project for deploying Elixir.
It declares the MIT license on GitHub.
Its maker tagged it for macOS and Linux. That is declared by the maker; Take My Repo has not tested it.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2018-08-24. GitHub counts 3 open issues and pull requests. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run elixir-deploy-template. What is known comes from GitHub. It declares the MIT license on GitHub. Its last change was on 2018-08-24. It has 83 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.
Take My Repo has not tested this on your machine. Requirements come from the project's own documentation.