-
Notifications
You must be signed in to change notification settings - Fork 7
/
.gitlab-ci.yml
150 lines (135 loc) · 4.86 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
143
144
145
146
147
148
149
150
variables:
REGISTRY: "docker-hub.2gis.ru"
stages:
- build:app
- build:image
- deploy
- end
before_script:
- export APPLICATION=`make -s print-APPLICATION`
- source ${CI_PROJECT_DIR}/ci-starter-kit/utils.sh
- export CI_TAG=`[[ -z ${CI_COMMIT_TAG} ]] && echo "branch-${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA:0:8}" || echo "${CI_COMMIT_TAG}"`
# ================= Test & Build =================
build:app:
image: $REGISTRY/microsoft/aspnetcore-build:1.1.4
stage: build:app
when: always
script:
- dotnet restore --runtime ubuntu.14.04-x64
- dotnet test tests/VStore.UnitTests/VStore.UnitTests.csproj --configuration Release
- dotnet publish src/VStore.Host --configuration Release --runtime ubuntu.14.04-x64 --output ../../publish/vstore
- dotnet publish src/VStore.Worker --configuration Release --runtime ubuntu.14.04-x64 --output ../../publish/vstore-worker
- dotnet publish src/CloningTool --configuration Release --runtime ubuntu.14.04-x64 --output ../../publish/cloning-tool
tags: [ 2gis, docker ]
artifacts:
name: "${CI_COMMIT_REF_NAME}"
expire_in: '1 week'
paths:
- publish/vstore/
- publish/vstore-worker/
- publish/cloning-tool/
build:vstore-image:
stage: build:image
when: manual
allow_failure: false
script:
- TAG=$CI_TAG DOCKER_FILE=publish/vstore/Dockerfile DOCKER_BUILD_CONTEXT=publish/vstore make docker-build
- TAG=$CI_TAG make docker-push
tags: [ docker-engine, io ]
dependencies:
- build:app
build:vstore-worker-image:
stage: build:image
when: manual
allow_failure: false
script:
- IMAGE=ams/vstore-worker TAG=$CI_TAG DOCKER_FILE=publish/vstore-worker/Dockerfile DOCKER_BUILD_CONTEXT=publish/vstore-worker make docker-build
- IMAGE=ams/vstore-worker TAG=$CI_TAG make docker-push
tags: [ docker-engine, io ]
dependencies:
- build:app
build:cloning-tool-image:
stage: build:image
when: manual
allow_failure: false
script:
- IMAGE=ams/cloning-tool TAG=$CI_TAG DOCKER_FILE=publish/cloning-tool/Dockerfile DOCKER_BUILD_CONTEXT=publish/cloning-tool make docker-build
- IMAGE=ams/cloning-tool TAG=$CI_TAG make docker-push
tags: [ docker-engine, io ]
dependencies:
- build:app
# ================ Deploy =================
deploy:standalone:
stage: deploy
when: manual
image: $REGISTRY/2gis-io/k8s-handle:latest
script:
- export VSTORE_ENVIRONMENT=Stage
- k8s-handle deploy --config config-standalone.yaml --section vstore --sync-mode True
only:
- tags
dependencies: []
tags: [ 2gis, docker ]
environment:
name: vstore-standalone
url: http://${CI_ENVIRONMENT_SLUG}.web-staging.2gis.ru/swagger
deploy:relizard:
stage: deploy
environment:
name: staging
url: http://vstore-stage.web-staging.2gis.ru/swagger
only:
- tags
script:
- "curl -X POST -F token=${AMS_DEPLOY_TRIGGER_TOKEN} -F ref=master https://gitlab.2gis.ru/api/v3/projects/2997/trigger/builds"
dependencies: []
tags: [ io, docker-engine ]
deploy:relizard:review:
stage: deploy
when: manual
environment:
name: review/${CI_COMMIT_REF_SLUG}
url: http://vstore-${CI_COMMIT_REF_SLUG}.web-staging.2gis.ru/swagger
on_stop: destroy:relizard:stop-review
only:
- branches
except:
- master
script:
- "curl -X POST -F token=${AMS_DEPLOY_TRIGGER_TOKEN} -F ref=master -F variables[VSTORE_TAG]=${CI_TAG} -F variables[HOST_POSTFIX]=${CI_COMMIT_REF_SLUG} -F variables[START_REVIEW]=true https://gitlab.2gis.ru/api/v3/projects/2997/trigger/builds"
dependencies: []
tags: [ io, docker-engine ]
# ================= End =================
destroy:relizard:stop-review:
stage: end
when: manual
variables:
GIT_STRATEGY: none
environment:
name: review/${CI_COMMIT_REF_SLUG}
action: stop
only:
- branches
script:
- "curl -X POST -F token=${AMS_DEPLOY_TRIGGER_TOKEN} -F ref=master -F variables[VSTORE_TAG]=${CI_TAG} -F variables[HOST_POSTFIX]=${CI_COMMIT_REF_SLUG} -F variables[STOP_REVIEW]=true https://gitlab.2gis.ru/api/v3/projects/2997/trigger/builds"
dependencies: []
tags: [ io, docker-engine ]
cleanup:registry:
stage: end
when: always
script:
- make docker-registry-images-cleanup TAG="branch-" TIME_LIFE_IMAGE=604800 # 7 days
- make docker-registry-images-cleanup IMAGE=ams/vstore-worker TAG="branch-" TIME_LIFE_IMAGE=604800 # 7 days
- make docker-registry-images-cleanup IMAGE=ams/cloning-tool TAG="branch-" TIME_LIFE_IMAGE=604800 # 7 days
dependencies: []
tags: [ docker-engine, io ]
cleanup:runner:
stage: end
when: always
script:
- make docker-containers-cleanup
- make docker-images-cleanup TAG="branch-" TIME_LIFE_IMAGE=86400 # 4 days
- make docker-images-cleanup IMAGE=ams/vstore-worker TAG="branch-" TIME_LIFE_IMAGE=86400 # 1 day
- make docker-images-cleanup IMAGE=ams/cloning-tool TAG="branch-" TIME_LIFE_IMAGE=86400 # 1 day
dependencies: []
tags: [ docker-engine, io ]