This is a companion repository for a series of posts I wrote for the Hashrocket blog:
- Automate Your Infrastructure with Pulumi (Part 0)
- Automate Your Elixir Deployments - Part 1 - Ansible
- Automate Your Elixir Deployments - Part 2 - Distillery & eDeliver
-
Get a Digital Ocean API key
-
Export it in your shell:
export DIGITALOCEAN_TOKEN='your token.......'
-
Install dependencies:
$ mix setup
-
Select a stack:
$ mix pulumi stack select prod
Look in
infra/Pulumi.prod.yaml
and change it according to your needs.You will need a domain name with name servers pointed at:
ns1.digitalocean.com ns2.digitalocean.com ns3.digitalocean.com
This may take a bit to propagate.
-
Run
pulumi up
:mix pulumi up --yes
-
Create a vault password file:
$ echo 'topsecret' > ansible/.vault-password
Replace
topsecret
with a password generated by your password manager. -
Remove existing secret files and create your own using the password you specified above:
$ cd ansible $ rm inventories/group_vars/all/secret/all.yml $ ansible-vault create inventories/group_vars/all/secret/all.yml
It should look like this:
--- secret_admin_email: admin@example.com
Replace with your own email, save and exit the file.
Now do the same for the phoenix secrets file:
$ rm inventories/group_vars/application/secret/phoenix.yml $ ansible-vault create inventories/group_vars/application/secret/phoenix.yml
It should look like this:
--- secret_secret_key_base: 'run mix phx.gen.secret to generate' secret_erlang_cookie: 'run mix phx.gen.secret to generate'
In a separate terminal generate the secrets using
mix phx.gen.secret
, paste them into the file, save and exit. -
Change directories back up to the root of the project and run:
$ mix ansible
Once the server is fully provisioned by Pulumi and Ansible, you should be able to build a release:
$ mix edeliver build release
The output should look like:
BUILDING RELEASE OF EXAMPLE APP ON BUILD HOST
-----> Authorizing hosts
-----> Ensuring hosts are ready to accept git pushes
-----> Pushing new commits with git to: deploy@example.com
-----> Resetting remote hosts to 26b6853c000982d80466818c7a1028e392b60483
-----> Cleaning generated files from last build
-----> Updating git submodules
-----> Fetching / Updating dependencies
-----> Build static assets
-----> Compiling sources
-----> Generating release
-----> Copying release 0.1.0+1-26b6853 to local release store
-----> Copying example.tar.gz to release store
RELEASE BUILD OF EXAMPLE WAS SUCCESSFUL!
Copy the release version and use it to deploy the release to production:
$ mix edeliver deploy release to production --version=0.1.0+1-26b6853
When the deploy is finished, restart the production release:
$ mix edeliver restart production
To start your Phoenix server:
- Setup the project with
mix setup
- Start Phoenix endpoint with
mix phx.server
Now you can visit localhost:4000
from your browser.
Deploy Elixir Example is kindly supported by Hashrocket, a multidisciplinary design and development consultancy. If you'd like to work with us or join our team, don't hesitate to get in touch.