-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
49 lines (47 loc) · 1.64 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
variables:
DOCKER_DRIVER: overlay
mof-nginx-build:
image: gitlab/dind:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
script:
- >
if git diff HEAD~ --name-only|grep mof-nginx-prod; then
echo "$FULLCHAIN_CERTIFICATE" > ./mof-nginx-prod/fullchain.pem
echo "$KEY_CERTIFICATE" > ./mof-nginx-prod/key.pem
docker build -t "$CI_NGINX_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" ./mof-nginx-prod
docker push "$CI_NGINX_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
fi;
only:
refs:
- master
changes:
- mof-nginx-prod/*
tags:
- main
deploy:
stage: deploy
image: alpine:latest
variables:
PROJECT_DIR: "mof-prod"
EXTRA_ENV_VARIABLES: "\nALLOWED_HOST=${DEPLOYMENT_SERVER_IP}"
before_script:
- apk update
- apk add openssh-client
script:
- echo "$EXTRA_ENV_VARIABLES" >> web.env
- mkdir "$PROJECT_DIR"
- cp db.env web.env secret.env service.env docker-compose.yml turnserver.conf ./"$PROJECT_DIR"/
- echo "$DEPLOY_SERVER_PRIVATE_KEY" > dkey
- chmod 700 dkey
- scp -o StrictHostKeyChecking=no -i ./dkey -r "$PROJECT_DIR"/ root@$DEPLOYMENT_SERVER_IP:~/
- ssh -o StrictHostKeyChecking=no -i dkey root@$DEPLOYMENT_SERVER_IP "cd ${PROJECT_DIR}; docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}; docker-compose -f docker-compose.yml stop; docker-compose -f docker-compose.yml rm; docker system prune -d; docker-compose -f docker-compose.yml pull; docker-compose -f docker-compose.yml up -d"
only:
- "master"
dependencies:
- mof-nginx-build
tags:
- main