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

fix tiny mistakes, add gitlab environment to settings, add deploy user...

fix tiny mistakes, add gitlab environment to settings, add deploy user settings + reference to deploy tokens
parent f0803dc8
No related branches found
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,18 @@ 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`.
_Note: it's best to inherit the private key 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)
......@@ -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

60.9 KiB | W: | H:

gitlab.vars.png

114 KiB | W: | H:

gitlab.vars.png
gitlab.vars.png
gitlab.vars.png
gitlab.vars.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -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,24 @@ deploy-job:
- |
cat > ~/.ssh/config << EOF
Host *
User gitlab-deploy
User $DEPLOY_USER
StrictHostKeyChecking no
EOF
script:
- rsync -avz docker-compose.yaml $DEPLOY_HOST:$PATH_TO_SERVICE
- rsync -avz $DOT_ENV $DEPLOY_HOST:$SERVICE_DIR/.env
- rsync -avz docker-compose.yml $DEPLOY_HOST:$SERVICE_DIR
- rsync -avz grafana-resources $DEPLOY_HOST:$SERVICE_DIR
- |
ssh $DEPLOY_HOST -C \
"cd $SERVICE_DIR &&\
chmod 600 $SERVICE_DIR/.env &&\
docker pull $CI_REGISTRY_IMAGE${DOCKER_IMAGE_TAG} &&\
docker-compose up -d"
- 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