What are the key points to focus on before starting to learn ETL Development....
Phoenix 1.3 Umbrella App deployment via Distillery-Docker-Docker_Compose
1. Elixir/Phoenix Umbrella App
Package |> Release |> Deploy
with Distillery Docker Docker-Compose
Yeong Sheng, Tan
tanyeongsheng@gmail.com
@yeongsheng
2. 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!!!
3. 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
4. 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
5. 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
6. 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
7. 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
8. 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
9. Setup
Install phoenix-1.3
1. Setup phoenix umbrella app
2. Fetch and compile hex deps
3. Init distillery rel config
4. Test run app locally
a. http://localhost:4000
10. 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
11. 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 .`
12. 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
13. 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`
14. 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
15. 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
16. 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
18. 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
19. 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
References:
https://www.docker.com/
http://www.tomsitpro.com/articles/docker-container-faq,1-3340.html
http://docker-saigon.github.io/post/Docker-Internals/
Analogy of shipping containers
Share Kernel host
Use kernel ability to group processes for resource control
Ensure isolation through namespace
Docker engine provides the ecosystem to interact and control (build, tag, stop, destroy, revive)
Docker registry (similar to github)
Release profiles, prod: include_erts, cookie, vm_args overwrite with a template file
distillery templating for vm.args e.g. <%= release_name %>
Built artifacts in _build dir
Cross compile release in target deployment OS-architecture to prevent runtime failures due to NIFs (natively implemented functions - BEAM and deps e.g. comeonin)
https://virviil.github.io/
http://blog.firstiwaslike.com/elixir-deployments-with-distillery-running-ecto-migrations/
https://hexdocs.pm/distillery/boot-hooks.html#content
https://github.com/Nebo15/confex,
https://github.com/bitwalker/conform
warning: the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8. Please ensure your locale is set to UTF-8 (which can be verified by running "locale" in your shell)
Bundle NPM assets (brunch build --production)
Assets pipeline - minify/uglify (mix phx.digest)
Expected built/compiled app bundle tarball location per distillery release profile definition in docker build images
UNexpected and hard-coded WORKDIR, and inability to use distillery release profile to pick up app bundle tarball for injection to docker release image build