-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
185 lines (166 loc) · 4.56 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
185 lines (166 loc) · 4.56 KB
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
image: docker
variables:
CARGO_HOME: "$CI_PROJECT_DIR/.cargo"
DOCKER_TLS_CERT_DIR: ""
RELEASE_BRANCH: "main"
DEV_BRANCH: "develop"
MAIN_BRANCH: "main"
IMAGE_TAG: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
stages:
- build
- test
- push
- deploy
- doctor
- pages
include:
- project: "security/container-scanning"
file: ".ESnet-container-scan.yml"
- component: $CI_SERVER_FQDN/ht/cicd-common/aap-run@v0.3.0
inputs:
aap_token: $AAP_TOKEN
.wharf_logout: &wharf_logout |-
docker logout "$WHARF_SITE"
.wharf_login: &wharf_login |-
echo "$WHARF_TOKEN" | docker login -u "$WHARF_USER" "$WHARF_SITE" --password-stdin
.docker_login: &docker_login |-
echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin
.build_environment:
image: rust:latest
before_script:
- apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install
--no-install-recommends --assume-yes protobuf-compiler libprotobuf-dev
sqlite3 libssl-dev musl-tools
- rustup target add x86_64-unknown-linux-musl
- cargo install sqlx-cli cargo-audit
- export "DATABASE_URL=sqlite:///tmp/udplbd.db"
- echo "Setting up database"
- $CARGO_HOME/bin/sqlx database setup
build_udplbd:
stage: build
extends: .build_environment
script:
- cargo build --release --target x86_64-unknown-linux-musl
artifacts:
paths:
- target/x86_64-unknown-linux-musl/release/udplbd
expire_in: 3 month
pages:
stage: pages
extends: .build_environment
script:
- cargo install mdbook
- .cargo/bin/mdbook build docs
- cargo doc --no-deps
- mv docs/book public
- mv target/doc public/api
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $MAIN_BRANCH
build_container:
stage: build
script:
- *docker_login
- docker build --pull -t $IMAGE_TAG .
- docker push $IMAGE_TAG
test:unit:
extends: .build_environment
stage: test
script:
- cargo test --release --lib
test:mock_integration:
extends: .build_environment
stage: test
script:
- cargo test --release --bin udplbd -- --nocapture
test:audit:
extends: .build_environment
stage: test
script:
- cargo audit
allow_failure: true
.push:
stage: push
before_script:
- *docker_login
- *wharf_login
after_script:
- *wharf_logout
script:
- |
docker pull $IMAGE_TAG
for tag in $TAGS; do
if echo $tag | grep -q "BRANCH_TAG"; then
tag=$(echo $tag | sed "s/BRANCH_TAG/$(echo $CI_COMMIT_BRANCH | sed 's/\//-/g')/g")
fi
docker tag $IMAGE_TAG $tag
docker push $tag
done;
publish_container:
extends: .push
variables:
TAGS: |
$WHARF_SITE/$WHARF_PROJECT/$CI_PROJECT_NAME:$CI_PIPELINE_ID
$WHARF_SITE/$WHARF_PROJECT/$CI_PROJECT_NAME:BRANCH_TAG
publish_release_container:
extends: .push
rules:
- if: "$CI_COMMIT_BRANCH == $MAIN_BRANCH"
- if: $CI_COMMIT_TAG
variables:
TAGS: |
$WHARF_SITE/$WHARF_PROJECT/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
$WHARF_SITE/$WHARF_PROJECT/$CI_PROJECT_NAME:latest
deploy_alpha:
extends: .aap_run
stage: deploy
variables:
AAP_JOB_TEMPLATE: 747
AAP_LIMIT: node2.fpga.es.net
rules:
- if: $CI_COMMIT_BRANCH == "develop"
deploy_node4_cicd9:
extends: .aap_run
stage: deploy
variables:
AAP_JOB_TEMPLATE: 882
AAP_LIMIT: node4.fpga.es.net
rules:
- if: $CI_COMMIT_BRANCH == "develop"
doctor_node4_cicd9:
extends: .aap_run
stage: doctor
variables:
AAP_JOB_TEMPLATE: 883
AAP_LIMIT: node4.fpga.es.net
rules:
- if: $CI_COMMIT_BRANCH == "develop"
after_script:
- |
# Extract the JSON string value of "doctor.stdout" and unescape it into doctor.xml.
# The line looks like: "doctor.stdout": "<?xml ...\\"...\\n..."
# Ansible double-escapes the JSON: quotes become \\" and newlines become \\n.
# awk strips the outer quotes then replaces \\" with " and \\n with newline.
awk '
/"doctor\.stdout"/ {
# Find the opening quote of the value
sub(/^[^"]*"doctor\.stdout":[[:space:]]*"/, "")
# Strip the trailing closing quote
sub(/"[[:space:]]*$/, "")
# Unescape \\" -> " and \\n -> newline
gsub(/\\\\"/, "\"")
gsub(/\\\\n/, "\n")
print
found = 1
}
END { if (!found) { print "ERROR: doctor.stdout not found in stdout.txt" > "/dev/stderr"; exit 1 } }
' stdout.txt > doctor.xml
artifacts:
paths:
- doctor.xml
- stdout.txt
when: always
reports:
junit: doctor.xml