CD
Overview CD System
Because we are small team, we should find away to automate the process of deploying the code to the server. We use the following tools to deploy the code to the server.
- Github Actions(GHA)
- We use Github Actions to run the CI/CD pipeline.
- Push our images to Gitlab Private Registry
- Portainer
- We use Portainer to manage the docker container on the server
- Dockerfile + docker-compose
- We use Dockerfile to build the image and docker-compose to run the container on the server
Workflow
Currently
- You need to have an account on Gitlab and Portainer.
- You need to have the permission to push the code to the repository, and ensure that the repository is the same with image tag. Example: your images tag is: "registry.gitlab.com/organization_name/product_name:0.0.0-rc.0". This require you must create a repository in Gitlab, like https://gitlab.com/organization_name/product_name
- You need to upgrade version of the image in the
docker-compose.local.yml
anddocker-compose.development.yml
file. The upgrade version bump following the Semantic Versioning. - You need to up the
docker-compose.local.yml
file to build the nessarry container for the project.
- After build complete and double-check that will work on the local machine, you can push the images to the Gitlab Private Registry with command:
- Push the image to the Gitlab Private Registry
-
Wait for the Portainer server auto trigger fetch the repo(develop branch) around 5 min, and re-deploy the container with the new image. If you want to trigger the re-deploy manually, you can go to the Portainer server -> click on the
Stacks
menu -> Chose the stack you want to re-deplot -> click on thePull and redeploy
button. -
In case you want to add/update the runtime environment variables, go to page like step 6, and click on the
Load variables from .env
orAdd an environment variable
button.
(Next Future)
- After we push the new code to our specific branch(usally is main/develop). GHA will run the CD pipeline.
- GHA will build the image and push the image to the Gitlab Private Registry.
- The portainer server will pull the image from the Gitlab Private Registry, and trigger re-deploy the container on the server, based on GitOps mechanism configured on Portainer Stack.