Hi everyone.
I have a pretty small Discourse instance running (for years actually, with pretty much zero issues): https://discuss.cubeisland.de/.
I’ve been using the standard lanucher-based deployment process on a dedicated VM (on my own hardware in a data center). The only thing I changed over the years was to migrate to an externally running shared postgresql database.
Recently I started migrating applications from dedicated VMs to a docker swarm as a preparation step to eventually migrate to a kubernetes cluster, mostly to save resources and make parts of the infrastructure more “elastic”.
Today was the day I looked into this small Discourse instance as one of the few remaining dedicated application VMs. “It’s already running on docker, how hard can it be to deploy that to a swarm” I thought. And from what I read it actually would be. I can just take the image from the currently running instance, push it to our internal registry and run it in the swarm and all would work just fine, which is great.
I looked at the launcher files, especially the templates and samples and figured it might probably be a good idea to have the redis separate in such a deployment and maybe I could setup a CI job to build new images when I add plugins or I want to update. So I checked out discourse_docker locally, copied my existing app.yml container definition to the clone and tried to run ./launcher bootstrap app
to build an image that I could then push to my registry, without immediately deploying it.
To my surprise, the script tried to connect the “production” postgresql server trying to migrate the database, which it luckily did not have access to from my local workstation.
I looked around here and apparently that is how this works, which make me wonder:
- How would build a container for a new instance, where I don’t have a database yet? Would I need to setup the production database before I can build the image?
- I assume this is the only time db:migrate is run, so if I have several similar instances (e.g. prod and test), I would need upgrade one of the instances to build the new image and then cannot use the same image for the second instance, even though the image would be identical.
- How would I go about building images for instances, where the database server is not accessible from the system building the image (which shouldn’t be that uncommon).
After reading a couple of posts (obviously including this one), I’m perfectly aware of the reasons for the build process as it is right now and I see the value of it for the mentioned 99% of people causally deploying Discourse on their standard full-fat VM. And I’m very used to “all in one” container models and I’m not opposed to that. After all, Docker’s key value comes from the fact, that the software vendor can pre-bake highly optimized configurations and bundle them into a reproducible runtime environment, removing the need for a lot of very application specific knowledge on the ops side of things. So I’m fully on board with using your provided tooling, why would I expect someone else to build better containers than the software vendor himself? Why would I want to split apart the nginx and the ruby application, when there is 0 benefit to be gained, just to make the deployment more “pure” (what ever that means…)?
However it is odd to see a container that is mutating runtime state while being nowhere near running. I already run quite a few applications in containers and I containerized quite a few myself, some of which were never intended to run in containers.
The prime example that comes to my mind, of an application that deals with similar requirements/issues in a similar way to Discourse, is Gitlab. While they do now provide a fancy Helm chart for a fully decomposed “how it should be” kubernetes deployment, I’m guessing (without looking at any numbers) that a similar 99% of its small-medium size deployments are using Gitlab’s omnibus docker image (or the OS package, which is practically the same). They have a similar bootstrapping process, but based on chef within the container, that’s all executed on every startup and does the usual things like db migrations and asset compilation.
Yes, Gitlab’s startup can take several minutes due to this, but never has that been an issue for the deployments I’ve seen (some in larger companies). Especially with modern orchestration systems like docker-swarm and kubernetes and whatever else, which can run rolling upgrades for you, where the old instance is turned off only if the new instance is running and successfully health- and ready-checked, a lengthy deployment process might not actually be an issue. But even without fancy rolling upgrades, which may or may not work, you can also get away with quite a bit of downtime in many situations.
So: Is it be possible to configure launcher to skip the database-dependent operations during image build and instead do these operations during container startup?
I’m definitely willing to invest some time here myself, but my time in the evening is limited, so any pointers would be very welcome.
I’m also open to completely different processes if you think this is stupid or not even possible or so.
Thanks for any feedback!