-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
184 lines (163 loc) · 4.21 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
include:
- project: 'buildsrv/ci'
file:
- '/templates/build/multiarch-image/v1.gitlab-ci.yml'
- '/templates/build/gitlab-release/v1.gitlab-ci.yml'
- '/templates/build/registry-image-copy/v1.gitlab-ci.yml'
- '/templates/test/multiarch-image/v1.gitlab-ci.yml'
.go-cache:
variables:
GOPATH: $CI_PROJECT_DIR/.go
before_script:
- mkdir -p .go
cache:
key: $CI_PROJECT_ID
# read-only cache as default
policy: pull
paths:
- .go/pkg/mod/
.rule-build-docker: &rule-build-docker
# don't run on tags
if: '$CI_COMMIT_TAG == null'
.rule-build-go: &rule-build-go
# don't run on tags
if: '$CI_COMMIT_TAG == null'
.rule-run-on-tags: &rule-run-on-tags
if: $CI_COMMIT_TAG
when: on_success
default:
image: registry.gitlab.com/buildsrv/images:build-base-golang-1.22
variables:
APP_VERSION_INTERNAL: "dev.$CI_PIPELINE_IID"
stages:
- prepare
- test
- build
- integration
- release
cache_deps:
extends: .go-cache
stage: prepare
rules:
- *rule-build-go
script:
- task dep
cache:
# make cache writeable for this job
policy: pull-push
unit_tests:
extends: .go-cache
stage: test
rules:
- *rule-build-go
script:
- task test
race_detector:
extends: .go-cache
stage: test
rules:
- *rule-build-go
script:
- task race
.memory_sanitizer:
extends: .go-cache
stage: test
rules:
- *rule-build-go
script:
- task msan
lint_code:
extends: .go-cache
stage: test
rules:
- *rule-build-go
script:
- task lint
build:
extends: .go-cache
stage: build
rules:
- *rule-build-go
script:
- task build
build-docker:
# per includes
extends: .build:multiarch-image
stage: build
rules:
- *rule-build-docker
- *rule-run-on-tags
variables:
TAGS: "$APP_VERSION_INTERNAL"
retry: 2
# integration below --------------------
test-image:
# per includes
extends: .test:multiarch-image
stage: integration
rules:
- *rule-build-docker
needs:
- build-docker
variables:
TEST_IMAGE_TAG: $APP_VERSION_INTERNAL
script:
- |
docker run --name "$TEST_CONTAINER_NAME" --rm --platform "$PLATFORM" "$TEST_IMAGE" serve &
sleep 3
- |
# call metrics endpoint
docker run --link "$TEST_CONTAINER_NAME:testme" --rm curlimages/curl -v --show-error --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 1 "http://testme:9952/metrics" >./response.txt
- cat ./response.txt
- |
# check if "chia_price_eur_cent 1234.0" is in response
RESPONSE_PATTERN="^chia_price_eur_cent[[:blank:]][[:digit:]]+\.?[[:digit:]]+$"
if grep -q -E $RESPONSE_PATTERN ./response.txt; then
parsedResult=$(grep -E $RESPONSE_PATTERN ./response.txt)
else
echo "Could not find 'chia_price_eur_cent' in response"
docker logs "$TEST_CONTAINER_NAME"
exit 1
fi
# check if the price has a valid value (> 0)
actualPriceEurCent=$(echo $parsedResult | cut -d" " -f2)
echo "actual chia price [eur cent] is '$actualPriceEurCent'"
([ ! -z "$actualPriceEurCent" ] && [ "$(echo "$actualPriceEurCent > 0"|bc)" -eq 1 ] && echo "Test successful!") || (echo "Test failed: expected chia price [eur cent] '$actualPriceEurCent' is not > 0" && exit 1)
parallel:
matrix:
- PLATFORM:
- linux/amd64
- linux/arm64
# release below ------------------------
gitlab-release:
# per includes
extends: .build:gitlab-release
stage: release
rules:
- *rule-run-on-tags
tag-release:
# per includes
extends: .build:registry-image-copy
stage: release
rules:
- *rule-run-on-tags
needs:
- job: build-docker
variables:
IN_DOCKER_IMAGE_TAG: "$APP_VERSION_INTERNAL"
OUT_DOCKER_IMAGE_TAGS: "$CI_COMMIT_TAG latest"
publish-docker-hub:
# per includes
stage: release
extends: .build:registry-image-copy
rules:
- *rule-run-on-tags
needs:
- tag-release
variables:
OUT_DOCKER_REGISTRY: 'docker.io'
OUT_DOCKER_REGISTRY_IMAGE_PATH: 'cryptastic/chia-price-exporter'
OUT_DOCKER_REGISTRY_LOGIN_TOKEN: $DOCKER_HUB_TOKEN
OUT_DOCKER_REGISTRY_LOGIN_USER: $DOCKER_HUB_USER
IN_DOCKER_IMAGE_TAG: "$CI_COMMIT_TAG"
OUT_DOCKER_IMAGE_TAGS: "$CI_COMMIT_TAG latest"