Coolify for hosting - part 2

Are flexible preview deployments possible with Coolify?

Coolify for hosting - part 2
Photo by Aditya Wardhana / Unsplash

This is the second part of my Coolify evalutation. The first part can be found here.

As written in the previous post about Coolify, it is possible to establish a common "staging" like deployment when f.e. merging a PR to the main branch for testing and evaluating the changes of an app. The aim of this post is to check how flexible preview deployments are. The evaluated version at the time of this writing is v4.0.0-beta.297.

Preview deployments - a primer

Preview deployments are a nice idea but pretty hard to do right. Depending on the app stack it might also involve a lot of other services that need to be up and running or even in a specific state. For the sake of brevity this post only handles a fairly common case where there is an app and a database.

Besides the setup another important part of a preview deployment is cleanup. When the PR is merged the stack should be torn down and cleaned up.

Coolify's approach

Coolify does support preview deployments out of the box. Sort of at least. The given "Resource" is a GitHub app where the Dockerfile is used to build the image that is deployed.

Coolify has a switch to enable preview deployments that can be found in the Advanced section. There is also a section allowing to setup how preview deployments work under Preview Deployments. The third part containing preview deployment related things can be found in the section Environment Variables. So there are some cogs to tweak and handle preview deployments.

The limitations start to show when you have f.e. a database in your project. How do you link a clean one to the preview deployment? You can use the standard one or define a preview DB via the environment variables that is then shared with all deployments. To have one isolated DB per preview deployment is not possible.

This limitation could maybe worked around when you'd given the possibility to have a before and after script where you could create and destroy the databases or a Docker Compose field where you can define additional services. But none of these things exist.

Attempted workaround 1

A bundled all in one based preview deployment does not offer sufficient flexibility as the app would need to handle creating a custom DB etc. which would be a rabbit hole let alone that the permissions would need to be very broad.

But Coolify offers multiple ways to create Git based resources. There are:

  • Nixpacks
  • Static
  • Dockerfile
  • Docker Compose

Nixpacks does not work and has other limitations especially for Elixir based apps. Static is not applicable as well. Dockerfile is what I have setup and described above.

The last and also promising sounding one is the Docker Compose approach. The idea is to create a docker-compose-preview.yml and setup the complete stack (app and database service).

Unfortunately as of this writing this approach is bugged. The "normal" application (non preview deployment) does not run without manual mitigation. Coolify has pre-defined variables like COOLIFY_FQDN and COOLIFY_URL. This is handy when you have to set the domain inside your app like in Elixir Phoenix' case the PHX_HOST for websocket related things (and URLs generate in emails). But those are unfortunately empty for the normal deployment when using the Docker Compose approach (bug report) so you'd need to hard code the domain yourself (which is not a bigger issue for the normal deployment as the domain does not change here). If those are empty as well for preview deployments cannot be said as you can't even deploy. You are greeted with a Array to string conversion error message. Also you cannot remove the preview deployment as it also results in the same error message being spit out. There was a bug report that since has been closed but not fixed fully. I added a new one here.

Summary

Unfortunately as of the writing it is not possible to have a sufficiently flexible preview deployment setup. The main reason are beta related bugs I'm sure the maintainer will fix as this project is very, very active. I will re-evaluate this part of Coolify and monitor any progress in this regard as it looks really promising.