Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elixir-Phoenix Umbrella App Packaging and Deplo...

Yeong Sheng
December 02, 2020

Elixir-Phoenix Umbrella App Packaging and Deployment with Distillery & Docker

Yeong Sheng

December 02, 2020
Tweet

More Decks by Yeong Sheng

Other Decks in Technology

Transcript

  1. Who Is This Dude? • Ruckus Wireless (now part of

    Brocade) • WiFi Access Points (AP) and AP Controller/Manager • Acquired by Brocade - Campus Switch product offering • WiFi location based device detection and Analytics • Campus Switch Management/Monitoring and Metrics publishing platform • WE ARE HIRING!!!
  2. Intent: Sharing the lessons I learnt packaging and deploying an

    Elixir/Phoenix Application using distillery packaged into docker container and run and orchestrated with docker-compose
  3. Desired Outcome: 1. Configure and build an Elixir/Phoenix release package

    2. Basic understanding of a docker container 3. Build a target env container that packages your app 4. Run your app in the target env container orchestrated using docker-compose
  4. Tools of the Trade • macOS with Homebrew • Erlang

    19.3 + Elixir 1.4.2 + Phoenix 1.3 • docker for macOS • docker-compose • Phoenix Umbrella app • bitwalker/distillery hex package
  5. What is distillery? • Both Exrm and Distillery from Paul

    Schoenfelder: @gotbones • Modern rewrite of Exrm - which relies on Relx (meant for Erlang apps) • Support for umbrella projects and multi-app/per-app release build • Support for release env and profiles • Event hooks, custom commands, EEx overlay templates
  6. What is docker? • DevOps 2016 • Promise of Build,

    Ship, Run any App Anywhere! • Not VMs!!! Feather-lite VMs - smaller & faster • Contract between Dev and Ops/Infra • Infra as code - blurred lines with config management/provisioning eco-system like salt-stack, puppet, terraform, etc • chroot on steroids - runc, lxc, cgroups ◦ likes of FreeBSD/Solaris jails, ◦ AIX mini-partitions
  7. What is docker-compose? • Microservice single-purpose container • Container orchestration

    within a single host - similar to K8 pods • Build-Scale-Heal ◦ docker-compose build ◦ docker-compose scale SERVICE=3 ◦ docker-compose up -d ◦ docker-compose ps ◦ docker-compose stop && docker-compose rm -v • docker-compose.yml • services, networks, dependencies • Multi-host orchestration -> K8 or Mesos
  8. Setup 1. Install phoenix-1.3 2. Setup phoenix umbrella app 3.

    Fetch and compile hex deps 4. Init distillery rel config 5. Test run app locally a. http://localhost:4000
  9. Release Config 1. Init release config 2. Define rel/config.exs a.

    environment :prod b. include_erts: true c. release :umbrella_app_name d. vm.args 3. Execute ‘release’ 4. Built artifacts location _build/:env
  10. Build App Docker Image 1. Demo App context a. SNMP,

    GPB and MQTT 2. Base image elixir:1.4.2 3. ENV a. LANG=en_US.UTF-8, LC_ALL=${LANG} b. MIX_ENV=prod c. REPLACE_OS_VARS=true 4. Execute `docker build -f Dockerfile -t name/tag .`
  11. Run built App Docker Image 1. Execute `docker run -d

    --name app_cont_name -p 1883:1883 -it name/tag /opt/app/bin/rna_umbrella foreground` 2. Check running container status a. `docker logs app_cont_name` 3. What went wrong? 4. docker-compose
  12. Container orchestration 1. docker-compose.yml 2. Docker network 3. Container startup

    dependency chain 4. Execute `docker-compose up -d` 5. Check running containers statuses a. `docker logs app_cont_name` b. `docker logs postgres_1` c. `docker logs mosquitto_broker1_1`
  13. mix_docker Build-Release flow 1. Define new mix hex dep ‘mix_docker’

    2. Execute `mix docker.init` 3. Customise mix_docker config: `mix docker.customise` 4. Define Dockerfile.build and Dockerfile.release 5. Execute `mix docker.build` 6. Execute `docker-compose up -d` 7. Execute `mix docker.release` 8. Run the container
  14. Iterate with smaller images + mix_docker flow 1. What can

    be done better in previous approaches? 2. Alpine Linux - apk vs apt-get/yum 3. Define docker build step to compile and `mix release` 4. Copy release package tarball with ERTS to S3, binary repo, etc 5. Define docker release step 6. Download/Copy release package tarball and explode in release container 7. Use docker-compose to stitch and orchestrate containers to run app suite
  15. Conclusion: 1. Distillery release profiles 2. Size of container matters

    3. Decouple build and release container images 4. Single purpose docker runtime container 5. docker-compose for container orchestration and service dependencies
  16. What next: 1. mix_docker release profiles for docker-release per app

    in umbrella app - rolled my own with bash script 2. Overlay network and DNS Service discovery to enable cross containers and physical machine BEAM processes connectivity 3. Hot upgrade-releases with distillery (still relevant in docker deployments???) 4. Multi-host deployments and service orchestration with K8
  17. Thank you for your time and kind patience Acknowledgements: •

    Zsolt Molnar • Yos Riady • Benjamin Tan W.H • Paul Schoenfelder • Tymon Tobolsk • Paul Lamb • Pete Corey • Dmitry Rubinstein • Michael Klein