-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gitlab-ci.yml
93 lines (84 loc) · 2.22 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
image: docker:latest
services:
- docker:dind
stages:
- build
- package
- deploy
variables:
DOCKER_DRIVER: overlay2
IMAGE_NAME: zensoftio/kicker
###########################
# Building
###########################
build-jar:
stage: build
image: openjdk:8-jdk
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
script:
- ./gradlew build
cache:
paths:
- .gradle/wrapper
- .gradle/caches
artifacts:
paths:
- backend/build/libs/*.jar
expire_in: 1 day
###########################
# Packaging
###########################
package-docker:
stage: package
dependencies:
- build-jar
script:
- if [[ ${CI_COMMIT_REF_NAME} == master ]]; then export IMAGE_TAG=latest; else export IMAGE_TAG=${CI_COMMIT_REF_NAME}; fi;
- docker login -u ${DOCKER_LOGIN} -p ${DOCKER_PASS}
- docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
- docker push ${IMAGE_NAME}:${IMAGE_TAG}
only:
- master
- tags
###########################
# Deployment
###########################
.prepare-key-script: &prepare_key
- apk add --no-cache openssh-client
- eval $(ssh-agent -s)
- echo "$SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
deploy:
stage: deploy
dependencies: []
variables:
CONTAINER_NAME: kicker
CONTAINER_PORT: 8585
DOMAINS: zensoft.io,zensoft.by,zensoft.kg
before_script: *prepare_key
script:
- ssh $SSH_USER@$SSH_HOST "docker rm -f $CONTAINER_NAME || true"
- ssh $SSH_USER@$SSH_HOST "docker rmi $IMAGE_NAME || true"
- ssh $SSH_USER@$SSH_HOST "docker login -u ${DOCKER_LOGIN} -p ${DOCKER_PASS}"
- ssh $SSH_USER@$SSH_HOST "docker pull $IMAGE_NAME"
- |
ssh $SSH_USER@$SSH_HOST "
docker run -d --name $CONTAINER_NAME --restart always \
--network kicker-net \
-p $CONTAINER_PORT:8080 \
-v $DATA_DIR:/data/ \
-e POSTGRES_HOST=$POSTGRES_HOST \
-e POSTGRES_DB=$POSTGRES_DB \
-e POSTGRES_USER=$POSTGRES_USER \
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-e DOMAINS=$DOMAINS \
$IMAGE_NAME
"
tags:
- minsk
only:
- master