Select Git revision

Fanna Lautenbach authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
README.md 2.29 KiB
Template: docker build and deploy
This a gitlab CI/CD template for building a docker image and deploying a docker stack to a certain machine via environment variables within gitlab.
Getting started
Within your project
In your own project make sure the following files are present in the root of your project
- Dockerfile
- Docker file that has all the necessary information to run your code
-
Example Dockerfile for a standard python project with a
main.py
and some libraries in arequirements.txt
added as a template here
- docker-compose.yaml
- docker-compose file with at least your own service, a network for internal docker container communication and the location of the environment file
- Example docker-compose for a single service added as a template here
- gitlab-ci.yml
- the gitlab-ci.yml template that is in this project
-
change the name within this template to your own service name and remove template from the name (template.gitlab-ci.yml -> .gitlab-ci.yml))
On gitlab
To make sure variables and the build+deploy job are not dependent, add the following variables to gitlab
- Create a new gitlab environment here: https://git.astron.nl/grafana/docker-deploy/-/environments/new
- Go to the CI/CD variables section (for example: https://git.astron.nl/templates/docker-deploy/-/settings/ci_cd -> variables)
- Expand the section and add the following variables as a variable and don't forget to set your environment!:
-
DEPLOY_HOST
- Where the docker service(s) should run.
-
SERVICE_DIR
- Where the static files are stored like the docker-compose.yaml.
-
DEPLOY_USER: The user that has read, write, and execute permissions for your
SERVICE_DIR
- The private key
SSH_PRIVATE_KEY
for an ssh connection to yourDEPLOY_HOST
. - The known hosts file
KNOWN_HOSTS
which ensures it deploys to the correct machines.
Note: it's best to inherit the private key and known hosts file from the group settings or change this setup with deploy tokens
- The private key
-
- Add the environment variables that are used by your docker service as a file called
DOT_ENV
and don't forget to set your environment!: