-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
44 lines (39 loc) · 1.15 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
image: docker:20.10.16
services:
- docker:20.10.16-dind
stages:
- build
- deploy
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- 'which ssh-agent || ( sudo apt install -qq openssh-client )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- ssh-keyscan $PROD_SSH_HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
build:
stage: build
script:
- docker build -t $CI_REGISTRY_IMAGE .
- docker push $CI_REGISTRY_IMAGE
only:
- master
deploy:
stage: deploy
script:
- echo "HOST SERVER - $PROD_SSH_HOST"
- echo "CI REGISTRY IMAGE - $CI_REGISTRY_IMAGE"
- |
ssh $PROD_SSH_USER@$PROD_SSH_HOST "
set -x -e
cd $PROD_SSH_DIR_DOCKER
docker compose pull api
docker compose kill api
docker compose rm api -f
docker compose up -d --build api
docker image ls $CI_REGISTRY_IMAGE -f dangling=true -q | xargs --no-run-if-empty docker rmi
exit
"
only:
- master