-
Notifications
You must be signed in to change notification settings - Fork 4
/
.gitlab-ci.yml
142 lines (132 loc) · 3.35 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
image: docker:latest
services:
- docker:dind
stages:
- test
- build
- package
- deploy
variables:
DOCKER_DRIVER: overlay2
###########################
# Tests
###########################
tests-unit:
stage: test
image: openjdk:12-jdk
variables:
POSTGRES_HOST: "postgres"
POSTGRES_DB: "db"
POSTGRES_USER: "user"
POSTGRES_PASSWORD: "password"
OPEN_API_URL: "open_api_url"
OPEN_CHAIN_URL: "open_chain_url"
EVENT_SUBSCRIPTION: "false"
services:
- name: postgres:10
alias: $POSTGRES_HOST
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
script:
- ./gradlew check
cache:
paths:
- .gradle/wrapper
- .gradle/caches
artifacts:
when: always
paths:
- build/reports
expire_in: 1 week
###########################
# Building
###########################
build-jar:
stage: build
image: openjdk:12-jdk
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
script:
- ./gradlew assemble
cache:
paths:
- .gradle/wrapper
- .gradle/caches
artifacts:
paths:
- build/libs/*.jar
expire_in: 1 week
only:
- sprint
- master
###########################
# Packaging
###########################
package-docker:
stage: package
before_script:
- export DOCKERIMAGE_TAG=$CI_COMMIT_REF_SLUG-$(date +%Y%m%d-%H%M%S)-${CI_COMMIT_SHA:0:8}
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- echo "export DOCKERIMAGE_TAG=$(echo $DOCKERIMAGE_TAG)" > variables
script:
- docker build
--tag $CI_REGISTRY_IMAGE:$DOCKERIMAGE_TAG
--file docker/Dockerfile .
- docker push $CI_REGISTRY_IMAGE:$DOCKERIMAGE_TAG
artifacts:
paths:
- variables
dependencies:
- build-jar
only:
- sprint
- master
###########################
# Deploy
###########################
.deploy-to-host-script: &deploy_to_host
- apk add --no-cache openssh-client
- apk add --no-cache py-pip py-paramiko
- pip install docker-compose==1.23.2
- eval $(ssh-agent -s)
- echo "$DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $SERVER >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- export DOCKER_HOST="ssh://gitlab@$SERVER"
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker-compose -f docker-compose-server.yml up -d
- docker image ls --filter reference=$CI_REGISTRY_IMAGE -q | tail -n +4 | xargs --no-run-if-empty docker image rm
deploy-sprint:
stage: deploy
before_script:
- source variables
- SERVER=$SPRINT_SERVER
- DEPLOY_KEY=$SPRINT_DEPLOY_KEY
- export OPEN_API_URL=http://api.open-platform.zensoft.io
- export OPEN_CHAIN_URL=$OPEN_CHAIN_URL
- export NETWORK_URL=$NETWORK_URL_DEV
- export EVENT_SUBSCRIPTION=true
- export POSTGRES_PASSWORD=$SPRINT_POSTGRES_PASSWORD
script: *deploy_to_host
dependencies:
- package-docker
only:
- sprint
deploy-master:
stage: deploy
before_script:
- source variables
- SERVER=$MASTER_SERVER
- DEPLOY_KEY=$MASTER_DEPLOY_KEY
- export OPEN_API_URL=https://api.openfuture.io
- export OPEN_CHAIN_URL=$OPEN_CHAIN_URL
- export NETWORK_URL=$NETWORK_URL_PROD
- export EVENT_SUBSCRIPTION=true
- export POSTGRES_PASSWORD=$MASTER_POSTGRES_PASSWORD
script: *deploy_to_host
dependencies:
- package-docker
only:
- master