Skip to content
Snippets Groups Projects
Commit cfc6b183 authored by Fanna Lautenbach's avatar Fanna Lautenbach
Browse files

Merge branch 'update-template' into 'main'

Fix & update deploy template

See merge request templates/docker-deploy!1
parents f0803dc8 56b0a14b
Branches main
No related tags found
1 merge request!1Fix & update deploy template
......@@ -10,7 +10,7 @@ In your own project make sure the following files are present in the root of you
1. Docker file that has all the necessary information to run your code
2. **Example Dockerfile** for a standard python project with a ```main.py``` and some libraries in a ```requirements.txt``` added as a template here
2. docker-compose.yaml
1. docker-compose file with at least your own service and a network and the location of the environment file
1. docker-compose file with at least your own service, a network for internal docker container communication and the location of the environment file
2. **Example docker-compose** for a single service added as a template here
3. gitlab-ci.yml
1. the gitlab-ci.yml template that is in this project
......@@ -18,14 +18,19 @@ In your own project make sure the following files are present in the root of you
### On gitlab
To make sure variables and the build+deploy job are not dependent, add the following variables to gitlab
1. Go to the CI/CD variables section (for example: https://git.astron.nl/templates/docker-deploy/-/settings/ci_cd -> variables)
2. Expand the section and add the following variables **as a variable**:
1. Create a new gitlab environment here: https://git.astron.nl/grafana/docker-deploy/-/environments/new
2. Go to the CI/CD variables section (for example: https://git.astron.nl/templates/docker-deploy/-/settings/ci_cd -> variables)
3. Expand the section and add the following variables **as a variable** and don't forget to set your environment!:
1. DEPLOY_HOST
1. Where the docker service(s) should run.
2. SERVICE_DIR
1. Where the static files are stored like the docker-compose.yaml.
3. Expand the section and add the variables that are used by your docker service **as a file** called DOT_ENV
3. DEPLOY_USER: The user that has read, write, and execute permissions for your `SERVICE_DIR`
1. The private key `SSH_PRIVATE_KEY` for an ssh connection to your `DEPLOY_HOST`.
2. 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](https://git.astron.nl/help/user/project/deploy_tokens/index.md)_
4. 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!:
![](gitlab.vars.png)
![](gitlab-vars.png)
......@@ -9,8 +9,6 @@ services:
container_name: my_service
image: git.astron.nl:5000/location/my_service:latest
networks:
- adex_network
volumes:
- $HOME/shared:/shared
- my_network_name
env_file:
- /docker_compose/my_service/.env
\ No newline at end of file
gitlab-vars.png

90.8 KiB

gitlab.vars.png

60.9 KiB

......@@ -24,7 +24,7 @@ docker-build:
- docker build --pull -t $CI_REGISTRY_IMAGE$DOCKER_IMAGE_TAG .
- docker push $CI_REGISTRY_IMAGE$DOCKER_IMAGE_TAG
deploy-job:
.base-deploy-job:
image: ubuntu:latest
stage: deploy
before_script:
......@@ -37,17 +37,27 @@ deploy-job:
- |
cat > ~/.ssh/config << EOF
Host *
User gitlab-deploy
User $DEPLOY_USER
StrictHostKeyChecking no
EOF
- cp $KNOWN_HOSTS ~/.ssh/known_hosts
script:
- rsync -avz docker-compose.yaml $DEPLOY_HOST:$PATH_TO_SERVICE
- rsync -avz docker-compose.yml $DEPLOY_HOST:$SERVICE_DIR
- rsync -avz $DOT_ENV $DEPLOY_HOST:$SERVICE_DIR/.env
- |
ssh $DEPLOY_HOST -C \
"cd $SERVICE_DIR &&\
chmod 600 $SERVICE_DIR/.env &&\
docker pull $CI_REGISTRY_IMAGE${DOCKER_IMAGE_TAG} &&\
docker-compose up -d"
docker-compose up -d --force-recreate"
- echo "Application successfully deployed."
when: manual
deploy-to-your-host:
extends: .base-deploy-job
environment: your-host
variables:
DEPLOY_USER: $DEPLOY_USER
DEPLOY_HOST: $DEPLOY_HOST
SERVICE_DIR: $SERVICE_DIR
DOT_ENV: $DOT_ENV
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment