https://github.com/dkarter/deploy-elixir-example
⚙️ Automatic server provisioning and configuration for Elixir and Phoenix Deployment
https://github.com/dkarter/deploy-elixir-example
ansible automation configuration-management deployment distillery edeliver elixir liveview phoenix pulumi
Last synced: 7 months ago
JSON representation
⚙️ Automatic server provisioning and configuration for Elixir and Phoenix Deployment
- Host: GitHub
- URL: https://github.com/dkarter/deploy-elixir-example
- Owner: dkarter
- Created: 2020-05-11T14:12:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-09T04:13:20.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T21:42:57.505Z (12 months ago)
- Topics: ansible, automation, configuration-management, deployment, distillery, edeliver, elixir, liveview, phoenix, pulumi
- Language: Elixir
- Homepage: https://deployelixir.xyz
- Size: 1.93 MB
- Stars: 19
- Watchers: 4
- Forks: 3
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Automating Elixir Deployment - Example Repo
## TOC
* [What Is This?](#what-is-this)
* [Demo](#demo)
* [Deployment Instructions](#deployment-instructions)
* [Setup Pulumi](#setup-pulumi)
* [Deploy Using eDeliver](#deploy-using-edeliver)
* [Running Locally](#running-locally)
* [About](#about)## What Is This?
This is a companion repository for a series of posts I wrote for the [Hashrocket](https://hashrocket.com) blog:* [Automate Your Infrastructure with Pulumi (Part 0)](https://hashrocket.com/blog/posts/automate-your-infrastructure-with-pulumi)
* [Automate Your Elixir Deployments - Part 1 - Ansible](https://hashrocket.com/blog/posts/automate-your-elixir-deployments-part-1-ansible)
* [Automate Your Elixir Deployments - Part 2 - Distillery & eDeliver](https://hashrocket.com/blog/posts/automate-your-elixir-deployments-part-2-distillery-edeliver)## Demo
[See it live!](https://deployelixir.xyz)
## Deployment Instructions
### Setup Pulumi1. Get a [Digital Ocean](lhttps://bit.ly/create-digital-ocean-account) API key
2. Export it in your shell:```bash
export DIGITALOCEAN_TOKEN='your token.......'
```3. Install dependencies:
```bash
$ mix setup
```4. Select a stack:
```bash
$ mix pulumi stack select prod
```Look in `infra/Pulumi.prod.yaml` and change it according to your needs.
You will need a [domain name](https://www.namecheap.com/) with name servers
pointed at:```
ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com
```This may take a bit to propagate.
4. Run `pulumi up`:
```bash
mix pulumi up --yes
```### Setup Ansible
1. Create a vault password file:```bash
$ echo 'topsecret' > ansible/.vault-password
```Replace `topsecret` with a password generated by your password manager.
2. Remove existing secret files and create your own using the password you
specified above:```bash
$ 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:
```yaml
---
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:
```bash
$ rm inventories/group_vars/application/secret/phoenix.yml
$ ansible-vault create inventories/group_vars/application/secret/phoenix.yml
```It should look like this:
```yaml
---
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.3. Change directories back up to the root of the project and run:
```bash
$ mix ansible
```### Deploy Using eDeliver
Once the server is fully provisioned by Pulumi and Ansible, you should be able
to build a release:```bash
$ 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 storeRELEASE BUILD OF EXAMPLE WAS SUCCESSFUL!
```Copy the release version and use it to deploy the release to production:
```bash
$ mix edeliver deploy release to production --version=0.1.0+1-26b6853
```When the deploy is finished, restart the production release:
```bash
$ mix edeliver restart production
```## Running Locally
To start your Phoenix server:* Setup the project with `mix setup`
* Start Phoenix endpoint with `mix phx.server`Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
## About
[](https://hashrocket.com)Deploy Elixir Example is kindly supported by [Hashrocket, a multidisciplinary design and development consultancy](https://hashrocket.com). If you'd like to [work with us](https://hashrocket.com/contact-us/hire-us) or [join our team](https://hashrocket.com/contact-us/jobs), don't hesitate to get in touch.