-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
250 lines (225 loc) · 7.11 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
stages:
- check
- build
- test
- push
- trigger
- docs
workflow:
rules:
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS == null
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_TAG
# Not making these global variables because they would get overridden in multi-project pipelines
.variables: &variables
# The base of this repo's docker registry
REPO_DOCKER_REGISTRY: ${CI_REGISTRY_IMAGE}
# The image name of java-haskell-base
BLAZE_HASKELL_JAVA_BASE_IMAGE: ${CI_REGISTRY}/${CI_PROJECT_NAMESPACE}/devops/haskell-java-base
# Enable buildkit for more efficient layer caching
DOCKER_BUILDKIT: "1"
# Potential build dependencies for the dind host
.script-bootstrap-dind: &script-bootstrap-dind
- echo -e "section_start:`date +%s`:bootstrap[collapsed=true]\r\e[0KBootstrap build dependencies"
- |
if [ -f /etc/alpine-release ]; then
apk add git coreutils python3
apk add -X http://dl-cdn.alpinelinux.org/alpine/edge/testing time
fi
- echo -e "section_end:`date +%s`:bootstrap\r\e[0K"
.script-setup-dependencies: &script-setup-dependencies
- echo -e "section_start:`date +%s`:setup[collapsed=true]\r\e[0KProject Setup"
- echo -e "machine ${CI_SERVER_HOST}\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
- |
for project in binary-analysis; do
rm -rf "../${project}"
git clone --depth=1 "${CI_REPOSITORY_URL%/*}/${project}.git" "../${project}"
done
- echo -e "section_end:`date +%s`:setup\r\e[0K"
- echo -e "section_start:`date +%s`:setup-dockerignore[collapsed=true]\r\e[0KSet up .dockerignore"
# Write a .dockerignore to the build context (../). This ignores everything there except for
# our source dependencies, since gitlab runner will have cloned our other repos to ../
- |
cat <<EOF >../.dockerignore
*
!ghidra-haskell
!binary-analysis
**/.git
**/.gitlab-ci.yml
**/.stack
**/.stack-work*
**/*.cabal
**/dist-newstyle
**/dist
ghidra-haskell/docs
EOF
- |
{ echo -e '\n\n# From binary-analysis/.gitignore:';
cat ../binary-analysis/.gitignore \
| sed -E 's|^/|/binary-analysis/|;s|^([^/])|/binary-analysis/**/\1|';
echo -e '\n\n# From ghidra-haskell/.gitignore:';
cat ../ghidra-haskell/.gitignore \
| sed -E 's|^/|/ghidra-haskell/|;s|^([^/])|/ghidra-haskell/**/\1|';
} >>../.dockerignore
- echo -e "section_end:`date +%s`:setup-dockerignore\r\e[0K"
.job:
timeout: 1h
variables:
<<: *variables
before_script: &job-before-script
- echo -e "section_start:`date +%s`:pre-env[collapsed=true]\r\e[0KEnvironment info (before_script)"
- uname -a
- env
- ls -al
- find . -maxdepth 1 \( ! -name . \) -print0 | sort -z | xargs -0 -x du -bhsc
- echo -e "section_end:`date +%s`:pre-env\r\e[0K"
.docker-job:
extends: .job
image: docker:dind
before_script:
- *script-bootstrap-dind
- *job-before-script
- docker login -u "${CI_REGISTRY_USER}" -p "$CI_JOB_TOKEN" "$CI_REGISTRY"
.haskell-job:
extends: .job
image: ${REPO_DOCKER_REGISTRY}/ghidra-haskell:pipeline-${CI_PIPELINE_IID}
# stage: check
include:
project: 'kevino/filter-check'
file: '/filtercheck.gitlab-ci.yml'
lint:
stage: check
extends: .job
image: ${BLAZE_HASKELL_JAVA_BASE_IMAGE}
needs: []
script:
- hlint --color=always src test app
allow_failure: true
build:
stage: build
extends: .docker-job
needs: []
script:
- *script-setup-dependencies
- image=${REPO_DOCKER_REGISTRY}/ghidra-haskell
- docker pull "${image}:latest" || true
- if [ "${CI_COMMIT_BRANCH}" = "${CI_DEFAULT_BRANCH}" ]; then
build_type=release;
else
build_type=dev;
fi
- docker build --pull .. -f Dockerfile
--build-arg "CI_REGISTRY=${CI_REGISTRY}"
--build-arg "CI_PROJECT_NAMESPACE=${CI_PROJECT_NAMESPACE}"
--build-arg "BUILD_TYPE=${build_type}"
--build-arg STACK_BUILD_OPTIONS=--ghc-options=-fdiagnostics-color=always
-t "${image}:pipeline-${CI_PIPELINE_IID}"
- docker push "${image}:pipeline-${CI_PIPELINE_IID}"
test:
stage: test
extends: .haskell-job
needs:
- build
variables:
<<: *variables
GIT_STRATEGY: none
GIT_CLEAN_FLAGS: none
script:
- cd /blaze/build/ghidra-haskell
- .ci/scripts/run_test.py ~/.local/bin/ghidra-test
push:latest:
stage: push
extends: .docker-job
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
needs:
- test
variables:
<<: *variables
GIT_STRATEGY: none
GIT_CLEAN_FLAGS: none
script:
- image=${REPO_DOCKER_REGISTRY}/ghidra-haskell
- docker pull "${image}:pipeline-${CI_PIPELINE_IID}"
- docker tag "${image}:pipeline-${CI_PIPELINE_IID}" "${image}:latest"
- docker push "${image}:latest"
push:tag:
stage: push
extends: .docker-job
rules:
- if: $CI_COMMIT_TAG
needs:
- test
variables:
<<: *variables
GIT_STRATEGY: none
GIT_CLEAN_FLAGS: none
script:
- image=${REPO_DOCKER_REGISTRY}/ghidra-haskell
- docker pull "${image}:pipeline-${CI_PIPELINE_IID}"
- docker tag "${image}:pipeline-${CI_PIPELINE_IID}" "${image}:tag-${CI_COMMIT_TAG}"
- docker push "${image}:tag-${CI_COMMIT_TAG}"
pages:
extends: .docker-job
stage: docs
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_MERGE_REQUEST_ID == null
when: on_success
- if: $CI_MERGE_REQUEST_ID == null
when: manual
needs:
- test
variables:
<<: *variables
script:
- *script-setup-dependencies
- image=${REPO_DOCKER_REGISTRY}/ghidra-haskell
- docker build --pull .. -f Dockerfile
--build-arg "CI_REGISTRY=${CI_REGISTRY}"
--build-arg "CI_PROJECT_NAMESPACE=${CI_PROJECT_NAMESPACE}"
--target docs
-t "${image}/docs:pipeline-${CI_PIPELINE_IID}"
- mkdir public
- docker run --rm "${image}/docs:pipeline-${CI_PIPELINE_IID}" tar -cvC docs . | tar -xvC public --no-same-owner
allow_failure: true
artifacts:
paths:
- public
expire_in: 12 hours
trigger-blaze:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
stage: trigger
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/alpine
script:
- apk add curl jq
- curl --fail-with-body
-X POST
-F token="${CI_JOB_TOKEN}"
-F ref=master
"${CI_API_V4_URL}"/projects/"$(jq -rn --arg x "${CI_PROJECT_NAMESPACE}/blaze" '$x|@uri')"/trigger/pipeline
cleanup:
stage: .post
when: always
extends: .docker-job
variables:
GIT_STRATEGY: none
script:
- apk add --no-cache --update bash
- images=${REPO_DOCKER_REGISTRY}/ghidra-haskell
- "# Untag all images created by this pipeline so we don't waste space on CI runner"
- |
bash -c '
images=${REPO_DOCKER_REGISTRY}/ghidra-haskell
tags=()
for image in "${images[@]}"; do
tags+=(
"${image}:pipeline-${CI_PIPELINE_IID}"
"${image}/docs:pipeline-${CI_PIPELINE_IID}"
"${CI_COMMIT_TAG:+${image}:tag-${CI_COMMIT_TAG}}"
)
done
for i in "${!tags[@]}"; do if [ -z "${tags[$i]}" ]; then unset tags[$i]; fi; done
echo "${tags[@]}"
docker image rm "${tags[@]}" || true
'