Boaz Poolman
Published on 3 August 2024
The best way to deploy your Strapi applications is through an automated deployment pipeline, otherwise called "Continuous Integration" (CI). I'll teach you how to build your Strapi app as a docker image using a Dockerfile, and how to deploy that image on a Dokku host. Once everything is setup all it takes to release a new version of your Strapi application is creating a new "Release" on Github and the Github Actions runner will take care of the rest!
To see how to configure a Dokku server to run Strapi please read my previous article about the topic:
[article-2]
The first step is to create a user named `ci` on your Dokku host. You can do that by running the following command:
This command will prompt you to set a password for the user. Make sure to set a secure password and store it in a safe place.
Once you've created the user and saved the password you have to make sure it can fire sudo commands without a password. You can do that by adding the user to the `/etc/sudoers` file on your server. Edit the sudoers file and add the following line:
During our deployment workflow we'll transfer a docker image do the Dokku host. To make sure it'll arrive properly we'll have to configure it's destination.
On the Dokku host create a folder in the following location:
Once the folder is created, make sure to set the newly created `ci` user as it's owner. You can do that by running the following command
To build a docker image from our Strapi application we need a Dockerfile. The easiest way to create a Dockerfile for your Strapi application is by using the strapi-tool-dockerize from strapi-community: https://github.com/strapi-community/strapi-tool-dockerize
To create the Dockerfile run:
The Dockerfile can then be committed and pushed to your Github repository.
Below you'll find a Github Actions workflow YML which you can copy into your Github repository on the following location:
The deployment workflow will do the following things for you:
The workflow file makes use of Github Action Secrets. You'll have to configure these in the settings section of your repository on Github. The following secrets need to be set:
And that's it! Make sure your Dockerfile and deploy.yml workflow file are both pushed to the repository on Github. Once that's done you can create a new release on Github by going to the following URL:
Once you publish the release it will trigger the deployment pipeline automatically. Make sure it successfully finishes to guarantee a successfull deployment!
Boaz Poolman
Published on 3 August 2024