mrkurt

mrkurt

Hello! I run a cloud company, we want to build the best possible Phoenix deployment experience. The goal is a CLI based launch command that takes a Phoenix app directory, sets the right configuration secrets on our service (SECRET_KEY_BASE and DATABASE_URL, so far) and then builds + deploys the app as quickly as possible.

For Ruby and Rails, we just use the default Heroku builder. It works very well.

The available Phoenix buildpacks are very slow and incredibly brittle. We can’t really use those, we need a better option.

How do you all package your apps for deployment today? Specifically:

  1. Do you use mix release?
  2. Do you have a Dockerfile?
  3. Do you run a CI system, and which one?

Thank you for the help!

Showing Posts 1 to 10

pmangalakader

pmangalakader

How do you all package your apps for deployment today? Specifically:

  1. Do you use mix release?

Yes, mix release is the inbuilt and easier way to distribute elixir applications. I have used distillery and edeliver also for deployments. There are multiple Elixir PAAS vendors for elixir deployments to try if you want to.

  1. Do you have a Dockerfile?

Yes, Dockerfile based containerization is easier to be embedded into development or deployment.

  1. Do you run a CI system, and which one?

I have used Pipelines, Github Actions, AWS or GCP based Pipelines and also Gitlab runner.

To answer briefly, it’s a mixture of all the three for most of the deployments, based on the Client’s convenience factors and productivity factors.

amnu3387

amnu3387

  1. Yes
  2. Depends - when I was using my own rolled out deployer it used docker to assemble the release locally and then would just deploy it to a target, change the symlink to the new one and restart the systemd service
  3. I’ve only recently started using Github actions but just for running tests before merge on a lib
lud

lud

I use this Gitlab CI

stages:
  - build
  - docker_build
  - deploy

variables:
  IMAGE_TAG: ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}
  CONTAINER_NAME: ${CI_PROJECT_NAME}_${CI_COMMIT_REF_SLUG}

mix_release:
  stage: build
  image: elixir:1.10.3-alpine
  variables:
    MIX_ENV: prod
    LANG: C.UTF-8
  script:
    - apk add --no-cache curl make openssl openssl-dev
    - mix local.hex --force && mix local.rebar --force
    - mix deps.get
    - mix deps.compile
    - mix phx.digest
    - mix release
  artifacts:
    paths:
      - _build/prod/rel/myapp

build_image:
  stage: docker_build
  image: docker:git
  dependencies:
    - mix_release
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker build -t ${IMAGE_TAG} .
    - docker push ${IMAGE_TAG}
  only:
    - /^release-.*$/
    - master


deploy_prod:
  stage: deploy
  image: kroniak/ssh-client:3.6
  script:
    - mkdir ~/.ssh
    - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$SSH_DEPLOY_ID_RSA")
    - ssh $SSH_DEPLOY_USER@$SSH_DEPLOY_HOST "sudo docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY"
    - ssh $SSH_DEPLOY_USER@$SSH_DEPLOY_HOST -t "cd ~/webapps/myapp ; sudo docker-compose pull phoenix"
    - ssh $SSH_DEPLOY_USER@$SSH_DEPLOY_HOST -t "cd ~/webapps/myapp ; sudo docker-compose rm --force --stop phoenix"
    - ssh $SSH_DEPLOY_USER@$SSH_DEPLOY_HOST -t "cd ~/webapps/myapp ; sudo docker-compose up --force-recreate --detach phoenix"
    - ssh $SSH_DEPLOY_USER@$SSH_DEPLOY_HOST -t "cd ~/webapps/myapp ; sudo docker image prune --force"

And this Dockerfile

# ---- Application Stage ----
FROM alpine:3.10 AS app

# Install openssl
RUN apk add --no-cache openssl zlib ncurses-libs ca-certificates

# Copy over the build artifact from the previous step and create a
# non-root user
RUN adduser -D app
WORKDIR /home/app
COPY _build/prod/rel/myapp .
RUN mkdir -p var/private-conf
RUN chown -R app: .
USER app

# Run the release
CMD ["./bin/myapp", "start"]

(Those are old versions I have on this computer).

I have a JavaScript build too but currently I just commit the build result. I should add a node docker image for that too.

I should also add a mix test run too.

crova

crova

1- Mix release
2- Nope
3- Only started using Sasa’s ci/cd library recently but nothing else.

mrkurt

mrkurt OP

When you use mix release but don’t package it with Docker, are you bundling everything up into a zip/tarball and deploying that? Or some other package format?

crova

crova

Not really, I just rsync everything.
But that only works because I don’t have to worry about the OS on the host.
I reckon the most common solution is indeed a docker container, maybe others will mention a different package format but I’m not aware of a spread solution other than docker.

mrkurt

mrkurt OP

We actually want to support something rsync-y too. I’m very interested in creating a hot code reload process. :slight_smile: Once we have the first deploy for a given app done, it should be pretty straightforward to just push the release files.

crova

crova

On the subject of hot code reload, there might be useful information for you on the erlang docs.

Any type of support for something rsync-y sounds like a good idea to me.

derek-zhou

derek-zhou

I run releases in production but git pull in the prod machine and mix release right there. my dev machine and prod machine are not exactly the same so I don’t want to mess with system libraries.

axelson

axelson

Scenic Core Team

I usually use GitHub - HashNuke/heroku-buildpack-elixir: Heroku Buildpack for Elixir with nitro boost · GitHub to deploy via Heroku

Not typically.

Nope, I try to avoid docker as much as possible.

I typically use CircleCI or GitHub Actions (although GitHub actions has only been on side projects)

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews