Slide 1

Slide 1 text

Martin Kavalar @mkvlr Martin Schurrer @msch Deploying Elixir

Slide 2

Slide 2 text

PSPDFKit

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

OTP Applications

Slide 7

Slide 7 text

def application do [applications: [:logger], mod: {BoldPoker, []}] end

Slide 8

Slide 8 text

defmodule BoldPoker do use Application def start(_type, _args) do import Supervisor.Spec children = [ worker(BP.TableManager, []), supervisor(BP.Client.Supervisor, []), supervisor(BP.Table.Supervisor, []) ] opts = [strategy: :one_for_one] Supervisor.start_link(children, opts) end end

Slide 9

Slide 9 text

iex> :observer.start

Slide 10

Slide 10 text

iex> :observer.start

Slide 11

Slide 11 text

OTP Releases

Slide 12

Slide 12 text

‣ rebar ‣ relx ‣ exrm

Slide 13

Slide 13 text

% mix release ==> Building release with MIX_ENV=prod. ==> Generating relx configuration... ==> Generating sys.config... ==> Generating boot script... ==> Performing protocol consolidation... ==> Generating revision file ==> Generating release... ==> Generating nodetool... ==> Deleting revision file ==> Packaging release... ==> The release for boldpoker_game-1.2.4 is ready!

Slide 14

Slide 14 text

boldpoker_game-1.2.4.tar.gz ├── bin │ ├── boldpoker_game │ └── nodetool ├── erts-6.4 ├── lib │ ├── boldpoker_game-1.2.4 │ ├── cowboy-1.0.0 │ ├── elixir-1.0.4 │ ├── stdlib-2.4 │ └── ... └── releases ├── 1.2.4 └── RELEASES

Slide 15

Slide 15 text

bin/boldpoker_game start bin/boldpoker_game attach bin/boldpoker_game stop

Slide 16

Slide 16 text

Hot Code Upgrades

Slide 17

Slide 17 text

1. suspend processes 2. update code and state (code_change) 3. resume processes

Slide 18

Slide 18 text

use GenServer def code_change(old_vsn, state, extra) do new_state = Map.put(state, :hand_history, []) {:ok, new_state} end

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

You might want to write a few scripts to automate this.

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

% mix release ==> Building release with MIX_ENV=prod. ==> Generating relx configuration... ==> Generating sys.config... ==> Generating boot script... ==> Performing protocol consolidation... ==> Generating revision file ==> Generating release... ==> Generated .appup for boldpoker_game 1.2.4 -> 1.2.5 ==> relup successfully created! ==> Generating nodetool... ==> Deleting revision file ==> Packaging release... ==> The release for boldpoker_game-1.2.5 is ready!

Slide 24

Slide 24 text

{‘1.2.5', [{'1.2.4', [ {:load_module, Poker} ]}], [{'1.2.4', [ {:load_module, Poker} ]}] } appup

Slide 25

Slide 25 text

{'1.2.5', [{'1.2.4', [], [ {:load_object_code, {:bp_game, '1.2.5', [Poker]}}, :point_of_no_return, {:load, {Poker, :brutal_purge, :brutal_purge}} ]}], [{'1.2.4', [], [ {:load_object_code, {:bp_game, '1.2.4', [Poker]}}, :point_of_no_return, {:load, {Poker, :brutal_purge, :brutal_purge}} ]}] } relup

Slide 26

Slide 26 text

{‘1.2.5', [{'1.2.4', [ {:update, BoldPoker.Table, {:advanced, []}}, [{'1.2.4', [ {:update, BoldPoker.Table, {:advanced, []}}, ]}] } appup

Slide 27

Slide 27 text

{'1.2.5', [{'1.2.4', [], [{:load_object_code, {:bp_game, '1.2.5', [BP.Table]}}, :point_of_no_return, {:suspend, [BP.Table]}, {:load, {BP.Table, :brutal_purge, :brutal_purge}}, {:code_change, :up, [{BP.Table, []}]}, {:resume, [BP.Table]} ]}], [{'1.2.4', [], [{:load_object_code, {:bp_game, '1.2.4', [BP.Table]}}, :point_of_no_return, {:suspend, [BP.Table]}, {:code_change, :down, [{BP.Table, []}]}, {:load, {BP.Table, :brutal_purge, :brutal_purge}}, {:resume, [BP.Table]} ]}]} relup

Slide 28

Slide 28 text

boldpoker_game-1.2.5.tar.gz ├── bin │ ├── boldpoker_game │ └── nodetool ├── erts-6.4 ├── lib │ ├── boldpoker_game-1.2.4 │ ├── boldpoker_game-1.2.5 │ ├── elixir-1.0.4 │ ├── stdlib-2.4 │ └── ... └── releases ├── 1.2.4 ├── 1.2.5 ├── RELEASES └── start_erl.data

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

1. Have previous release available 2. mix release
 → boldpoker_game-1.2.5.tar.gz 3. Server: mkdir -p releases/1.2.5 4. Put the .tar.gz into releases/1.2.5/ boldpoker_game.tar.gz 5. bin/boldpoker_game upgrade "1.2.5"

Slide 31

Slide 31 text

Out of scope for those tools • Where do I store my previous releases so I can build the upgrades? • Releases include native code, no way to cross- compile • Deployment to multiple servers?

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Production Staging Build Host Developer
 with edeliver Release Store
 S3

Slide 34

Slide 34 text

defp deps, do: [ { :edeliver, github: "boldpoker/edeliver" } ] end mix.exs

Slide 35

Slide 35 text

APP="boldpoker_game" BUILD_HOST="builder.boldpoker.net" BUILD_USER="deploy" BUILD_AT="~/build/boldpoker_game" RELEASE_STORE="s3://ACCESS_KEY:SECRET_ACCESS_KEY@bucket" PRODUCTION_HOSTS="app1.boldpoker.net app2.boldpoker.net" PRODUCTION_USER="deploy" DELIVER_TO="/srv/boldpoker-game/" .deliver/config

Slide 36

Slide 36 text

% ./edeliver build release Using local release store. BUILDING RELEASE OF BOLDPOKER_GAME APP ON BUILD HOST -----> Authorizing hosts -----> Ensuring hosts are ready to accept git pushes -----> Pushing new commits with git to: msch@localhost -----> Resetting remote hosts to 7d02ecd8a -----> Stashing build directory on remote build host -----> Fetching / Updating dependencies -----> Compiling sources -----> Generating release -----> Copying release to local release store -----> Copying boldpoker_game-1.2.0.tar.gz to release store RELEASE BUILD OF BOLDPOKER_GAME WAS SUCCESSFUL!

Slide 37

Slide 37 text

Build Host Developer
 with edeliver Release Store
 S3/scp

Slide 38

Slide 38 text

% ./edeliver deploy release to production --version=1.2.0 Using local release store. DEPLOYING RELEASE OF BOLDPOKER_GAME APP TO PRODUCTION HOSTS -----> Authorizing hosts -----> Uploading archive of release 1.2.0 from local release store -----> Extracting archive boldpoker_game_1.2.0.tar.gz DEPLOYED RELEASE TO PRODUCTION!

Slide 39

Slide 39 text

Production Developer
 with edeliver Release Store
 S3/scp

Slide 40

Slide 40 text

% ./edeliver start production Using local release store. EDELIVER BOLDPOKER_GAME WITH START COMMAND -----> starting production servers production node: user : msch host : localhost path : /opt/boldpoker-game/ Connection to localhost closed. START DONE!

Slide 41

Slide 41 text

Production Developer
 with edeliver

Slide 42

Slide 42 text

% ./edeliver build upgrade --from=1.2.0 Using local release store. BUILDING UPGRADE OF BOLDPOKER_GAME APP ON BUILD HOST -----> Authorizing hosts -----> Validating * version 1.2.0 is in local release store -----> Ensuring hosts are ready to accept git pushes -----> Pushing new commits with git to: msch@localhost -----> Resetting remote hosts to 896d81a67 -----> Stashing build directory on remote build host -----> Checking out 896d81a676df3c477689d2c72c5562d5edcf1999 -----> Fetching / Updating dependencies -----> Compiling sources -----> Uploading archive of release 1.2.0 from local release store -----> Extracting archive boldpoker_game_1.2.0.tar.gz -----> Generating release -----> Copying release to local release store -----> Copying boldpoker_game-1.2.4.tar.gz to release store UPGRADE BUILD OF BOLDPOKER_GAME WAS SUCCESSFUL!

Slide 43

Slide 43 text

% ./edeliver deploy upgrade to production Using local release store. DEPLOYING UPGRADE OF BOLDPOKER_GAME APP TO PRODUCTION HOSTS -----> Authorizing hosts -----> Uploading archive of release 1.2.4 from local release store -----> Upgrading release to 1.2.4 DEPLOYED UPGRADE TO PRODUCTION!

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Outlook ‣ fetch version from server ‣ continuous deployment

Slide 46

Slide 46 text

Outlook ‣ Slack Integration ‣ Phoenix Web Interface ‣ Upgrade Testing

Slide 47

Slide 47 text

github.com/boldpoker/edeliver github.com/boldpoker/edeliver Thank you! Questions? Martin Kavalar @mkvlr Martin Schurrer @msch