Skip to content

Instantly share code, notes, and snippets.

@saiberz
Last active October 31, 2018 19:37
Show Gist options
  • Save saiberz/19a47f85ae9030cd119e26fc59039a38 to your computer and use it in GitHub Desktop.
Save saiberz/19a47f85ae9030cd119e26fc59039a38 to your computer and use it in GitHub Desktop.
Steps to deploy elixir app

Requirements

Servers

  • Install erlang
  • Install elixir
  • Install mix
  • Port 22

Local

  • Install git
  • Install erlang
  • Install mix
  • SSH to server

Elixir project

  • {:edeliver, "~> 1.4.3"}
  • {:distillery, "~> 1.4"}

Steps

Step 0 (only for phx projects)

Add configuration to web project

config :myproject, MyProjectWeb.Endpoint,
  http: [port: 4000],
  server: true,
  code_reloader: false

Step 1

Upload secret files

scp ~/my_project/config/prod.secret.exs server1:/home/myuser/app_config

Step 2

Config release

mix release.init

Step 3

Config deliver

.deliver/config

APP="my_project"

BUILD_HOST="fredys.site"
BUILD_USER="saiberz"
BUILD_AT="/home/saiberz/app_build"

PRODUCTION_HOSTS="fredys.site" 
PRODUCTION_USER="saiberz" 
DELIVER_TO="/home/saiberz/app_release" 

pre_erlang_get_and_update_deps() {
  local _prod_secret_path="/home/saiberz/app_config/prod.secret.exs"
  if [ "$TARGET_MIX_ENV" = "prod" ]; then
    __sync_remote "
      ln -sfn '$_prod_secret_path' '$BUILD_AT/config/prod.secret.exs'
    "
  fi
}

Update gitignore

echo ".deliver/releases/" >> .gitignore

Commit project

git commit -m "Add files for deployment"

Step 5

cd ~/my_project
mix edeliver build release
mix edeliver deploy release to production
mix edeliver start production

Upgrade

Update version of mix.exs file Commit changes and new version

mix edeliver upgrade production
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment