I spent most of a day trying to deploy a new Phoenix app (and an umbrella application) via dokku to my test server.
All the deployments fail on the node assets fetching stage. It seems that the heroku phoenix static buildfile that’s the de facto build for Phoenix requires a version of node that is incompatible with a number of packages Phoenix 1.5 wants to build. (Many, many of them are looking for a minimum of 8 or 10, and the build file wants to provide Node 5.something.)
Setting the version of node higher in a build config file fails for other reasons. I’ve checked the git issues for the static build file, and a related error is there, but no fix has been offered.
My question is, has anyone had any luck deploying Phoenix 1.5 to Heroku/Dokku? If so, how did you manage it?
If not, what’s your preferred deployment solution because I’m really digging on 1.5, but my deployment pipeline for simple one-off projects seems to have just collapsed.
have you added the phoenix_static_buildpack? and made sure they are in correct order… then https://hexdocs.pm/phoenix/heroku.html#adding-the-phoenix-server-and-assets-buildpack for setting node version…
I used to use Heroku but it got too expensive for running a few personal apps. I also tried Dokku but it was more complicated than I expected and I couldn’t get it setup right.
I ended up going with a very simple solution; using some SSH scripts to deploy my apps. It’s not the prettiest, but it works quite well. I have it working on a few apps. My solution is here if you are interested: https://github.com/jswny/deploy. Basically, you have the CI build the Docker image, push it to Docker hub, and then just SSH into the remote server copying over your Docker Compose file, which pulls down the new image and runs
docker-compose up. That repository has a few extra environment variable handling niceties which I use to configure the apps based on their release channel, so it also copies over a
.env populated with the right environment variables for your apps.
Since docker containers are immutable, how do you deal with agents and whatnot getting shutdown and restarted? Like if you had an session tracker that wasn’t connected to a database backup?
Thanks for the suggestion, outlog. I double-checked, and yes, I’m loading in the correct order and I do have the node version set correctly in the phoenix_static_buildpack.config.
It’s possible I misconfigured something else. I’m probably going to just rebuild the VM from the ground up and try again from scratch to see what, if anything, I missed.
From my experience Docker Compose is smart enough to only restart containers that have images which actually changed. So, my database container never changes, so it doesn’t restart when I change my code since it’s image is not any different.
However, the image for my app obviously changes, so docker will restart that.
So, if you don’t keep any state in the application container then it will be fine.
can you post the error log - and what node version you have config’ed?
I started over. Wiped out my dokku installation, re-initialized my phoenix 1.5 application. Somewhere while tweaking the configuration for the umbrella app, I must have done something incorrectly, because it seems to work now. Going to try the same for a plain vanilla phoenix application.
I’ll reply to myself in case someone else also finds themselves in this position.
If the dokku push fails in any compilation step, make sure the phoenix_static_buildpack.config contains this line:
A failure could easily cache bad data, and you’ll need to wipe all that out and try again. set it to false after success or you’re just increasing your deployment time needlessly.
I think that if you set the engine version in your package.json file, it will load this version of Node. For example:
Thanks for the tip. I’ll see if that’s an alternate solution.