Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Deploying Elixir/Phoenix with Distillery - Yaroslav Martsynuyk

42 views

Published on

Elixir Club 8
Peremoga Space, Kyiv
21.10.2017

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Deploying Elixir/Phoenix with Distillery - Yaroslav Martsynuyk

  1. 1. Deploying Elixir/Phoenix w/ Distillery Elixir Club 8 21 October | Kyiv Yaroslav Martsynyuk
  2. 2. What is Distillery and What it Does [not]? Does: - Elixir release manager - Builds release package - Builds upgrade/downgrade package Doesn`t: - Deploy package to server - Start/upgrade/downgrade app
  3. 3. 1 defp deps do 2 [ 3 {:phoenix, "~> 1.3.0"}, 4 {:phoenix_pubsub, "~> 1.0"}, 5 {:phoenix_ecto, "~> 3.2"}, 6 {:phoenix_html, "~> 2.10"}, 7 {:phoenix_live_reload, "~> 1.0", only: :dev}, 8 {:gettext, "~> 0.11"}, 9 {:cowboy, "~> 1.0"}, 10 {:distillery, "~> 1.5.2"} 11 ] 12 end Add Distillery As Dependency
  4. 4. $> mix release.init 1 use Mix.Releases.Config, 2 default_release: :web, 3 default_environment: Mix.env() 4 5 environment :prod do 6 set include_erts: true 7 set cookie: “ M*~{1amT9B(cG9qoi3I*a>BUS{AkC;Lb<hh~BG[g ” 8 end 9 10 release :web do 11 set version: current_version(:web) 12 end Init Release
  5. 5. $> MIX_ENV=prod mix deps.get --only prod $> MIX_ENV=prod mix release.init $> MIX_ENV=prod mix release [--upgrade] --env=prod VERSION - 1 => VERSION => VERSION + 1 Create Release/Upgrade
  6. 6. 1 #! /usr/bin/env 2 3 V=$(grep 'version' mix.exs | cut -d'"' -f2) 4 5 if["$(ssh user@host /tmp/bin/demo ping)" = "pong" ]; then 6 bash ./upgrade.sh 7 else 8 cd ~/demo 9 MIX_ENV=prod mix deps.get --only prod 10 MIX_ENV=prod mix release.init 11 MIX_ENV=prod mix release --env=prod 12 scp ./releases/${V}/demo.tar.gz user@host:/tmp 13 ssh user@host tar -xf demo.tar.gz -C /tmp 14 ssh user@host /tmp/bin/demo start 15 fi Install Script
  7. 7. 1 #! /usr/bin/env 2 3 V=$(grep 'version' mix.exs | cut -d'"' -f2) 4 5 cd ~/demo 6 MIX_ENV=prod mix deps.get --only prod 7 MIX_ENV=prod compile 8 MIX_ENV=prod mix release --env=prod --upgrade 9 scp ./releases/${V}/demo.tar.gz user@host:/tmp/releases/${V} 10 ssh user@host /tmp/bin/demo upgrade ${VERSION} Upgrade Script
  8. 8. FROM elixir:1.5.2 ENV APP_NAME /web EXPOSE 4000 ... RUN mix deps.get RUN cd $APP_NAME/assets && npm install && node $APP_NAME/assets/node_modules/brunch/bin/brunch build RUN MIX_ENV=prod mix release.init RUN MIX_ENV=prod mix release CMD MIX_ENV=prod _build/prod/rel/web/bin/web foreground Docker/Kubernetes
  9. 9. 104.131.48.219 CI Node 104.131.65.78 Production Node http://104.131.65.78:4000 Demo Time
  10. 10. ?

×