What's the best way to deploy a Phoenix app in production?

We have a company guide to deploying Phoenix on Ubuntu Server - it assumes some knowledge of Ubuntu Servers, Elixir, and postgresql - but it should be good enough to guide an apprentice to deploy their first Phoenix app.

If there is anything very wrong, or a problem when following this guide, let me know.

2 Likes

hey @Ninigi that’s actually what I did. I followed two tutorials and combined them when one fell short to deploy my first Phoenix app to production on an Ubuntu server on Vultr (Prefer them instead of Digital Ocean).

1 Like

If you are looking for an end to end deploy solution, Gigalixir (similar to Heroku) and Edeliver (Similar to Capistrano) are the best options. However, distillery and mix release can be considered ways to deploy a phoenix/elixir application to production. You can read about it on their documentation.

The point is distillery and mix release requires additional works to make your application alive, that is the main difference from Giga/Edeliver

For the last, I’ve suggested Docker as a solution because nowadays is very common to use docker (k8 or docker swarm) in production infrastructure. So, I’ve only suggested a ready-to-use elixir docker image to run in your infra

In my opinion is very important an elixir programmer know all the possibilities to find out what fits more according to their resources (time, $$)

2 Likes

Very insightful @pierreabreup. Thanks!

1 Like

Your original post was a little weird, I did not assume you don’t know about all that.

Nothing else to say, you are saying what I assumed you said.

On a personal note: I don’t like docker, I have used it, and am working with legacy apps using docker. The legacy apps are the worst (doen’t have anything to do with Elixir) It’s all a blackbox, and the last time I tried to update, it broke and I had restore the server from a snapshot.
I don’t know how yaml configuration makes things easier than learning basic Linux bash commands, it seems to be so much harder to debug (on the infrastructure level) and… I guess I am the old guy yelling at clouds here, I think it’s a fad.
Don’t mind me, I also think React is a fad, I think it breaks how the web was supposed to work, and I think virtual DOMs are a fad - because browsers and computers are getting faster still.
I use Firefox, not Chrome - and for at least 6 months now, I actually think it is the better browser.

Everyone, you go use docker. It’s probably great! I haven’t seen what it offers over a vanilla server yet, but maybe I will have to come around. Seriously. I know it sounds condescending, I just want to state my opinion.

I guess I will have to wait for people to actually trying it out, but I have set up servers mostly following the tutorial I posted (as of October 2019).

I feel like there are always tutorials, but maybe not the one you actually need, then you start to combine and in the end, you end up learning about so many things, and with a thing you at least can google. Docker images seem to be so very specific, and if you do anything a little different, then you have to figure out the options - and how does that make it better than learning Linux/Unix or whatever your server is, commands?

I’m no expert in container stuff, but I think the main pain point that it solves is duplication and so less prone to errors configuring multiple servers. I think it’s kinda cool to have the same environment on local and in production. Tho that requires a bit more work. Still (anyway I said I’m no expert in containers) I prefer to configure the server myself, especially when it’s a small project that doesn’t need distributed systems or any other fancy feature.

I feel like the main advantage of a docker image is that you can set up the same environment really fast ( what you said), but when does a developer ever really need that? You have to maintain the docker images, just as you have to with a server, pretty much everything has a .lock file nowadays, so what is the point?

I seriously don’t get it, but I am no expert either, so maybe someone can explain to me why you would want docker, over everything vanilla (without a 5 foot 8 inches long yaml config file)?

bing able to provision any number of similar servers without having to configure them one after the other or just run some script manually, seems to be worth it for me.

1 Like

Have you tried the Dokku on Digital Ocean? https://marketplace.digitalocean.com/apps/dokku
I’ve used it successfully with the Phoenix. Used the same buildpacks you would’ve used with Heroku. Give it a try!

2 Likes

I’m gonna have a look at that. Thanks

US West for the most part, but the CDN is global.

Heroku works fine for me.

2 Likes

hey @Ninigi I’m trying to follow your guide to use Distillery and edeliver and arriving at the mix edeliver build release production it errors out with ```
** (Mix) Could not invoke task “release”: 1 error found!
–verbosity : Unknown option

A remote command failed on:

deploy@8.6.193.40

Output of the command is shown above and the command executed
on that host is printed below for debugging purposes:

FAILED with exit status 1:

[ -f ~/.profile ] && source ~/.profile
set -e
cd /tmp/edeliver/edeliver/builds
if [ "mix" = "rebar" ]; then
  echo "using rebar to generate release"
  ./rebar   -f generate
elif [ "mix" = "relx" ]; then
  echo "using relx to generate release"
  ./relx release
elif [ "mix" = "mix" ]; then
  echo "using mix to generate release"
  MIX_ENV="prod" LINK_SYS_CONFIG="" LINK_VM_ARGS="" APP="edeliver" AUTO_VERSION="revision" BRANCH="master" SKIP_RELUP_MODIFICATIONS="" RELUP_MODIFICATION_MODULE="" USING_DISTILLERY="" mix do release.version ,  release --verbosity=verbose
fi

I googled it but couldn't find what the problem was. Upgraded and downgraded versions of both. But no luck. This method seems cool tho.

thanks for trying it out.

It looks like it doesn’t say you have to run mix distillery.init, that should create some files in rel/. Sorry for that :wink:

1 Like

hey @Ninigi it worked. But there are other issues. The deployment was successfully but the app never started. I googled it and found some more stuff I needed to add to config/prod.exs like server: true, code_reloader: false and now it saying that /home/deploy/apps/edeliver/bin/edeliver_rc_exec.sh: line 45: /home/deploy/apps/edeliver/releases/0.1.0+2f38fb5/edeliver.sh: No such file or directory. Is anything that I did wrong?

In the begin, docker-compose.yml can be scareful , but, when you sit down in your desk and spend a little while reading docker compose documentation and some Mediums articles, everything becomes more simple.

The main concept of yaml configuration is to avoid to concern yourself about how to create and configure a machine, you have to only focus in what dependences your service needs to up. You don’t need to care about install a apache/nginx, varnish, imagemagick, passenger, haproxy, and others tools, you only have chosen what you need to you application up and voilà :smiley: Moreover, you can run your application in a small machine (docker image about 30mb or less), which make you environment faster to scale up and down.

In Docker ecosystem, there is not more the classical problem: why this problem only happens in staging/production? Here at my company, my productions docker images are the same images in my local environment.

However, not everything is flowers :sweat_smile: Docker in docker swarm is very painful, mainly to kill and up services in new nodes (aws coreOs). Now we are migration to K8 and it is have been the haven in the land.

With docker, you can have got the same environment in local/staging/production. You only need to create a docker image (or find out a ready docker image in https://hub.docker.com/) and set up it in a docker-compose.yml which you will mount the working dir to inside the containers.

In staging/production, you can use your image in a docker swarm (docker stack deploy) ou k8. it is more easy and simple that you imagine :smiley:

However, if you don’t want a production/staging cluster, you can run a simple docker run if you project is monothilic

Magically. Been using in production for almost 2 years.

Looks similar to Render, but it’s maybe a bit cheaper based on quick look at pricing?

Recently acquired by Digital Ocean.

Seems like they are in Beta since the acquisition (if you’re not an existing customer), but worth signing up for.

1 Like

You most likely did not do anything wrong, it’s entirely on us :wink: There are certain parts that I personally just do (and I guess others too), so it is probably missing in the tutorial.

Thanks again for trying and finding those issues :+1:

1 Like