forked from dockcross/dockcross
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
221 lines (178 loc) · 7.53 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
variables:
IMAGE_REF: ${CI_COMMIT_SHORT_SHA}-${CI_PIPELINE_ID}
REF_TAG_amd64: ${IMAGE_REF}-amd64
REF_TAG_arm64: ${IMAGE_REF}-arm64
DOCKER_REPO: artifactory-pub.bit9.local:5000
DOCKCROSS_ROOT_NAME: ${DOCKER_REPO}/cbdev/dockcross
BASE_IMAGE_NAME: ${DOCKCROSS_ROOT_NAME}/base
image: ${DOCKER_REPO}/cbdev/ubuntu2004-docker:kk_arm_support
stages:
- build
before_script:
- |
# Pre Script
if [ "$GIT_STRATEGY" != "none" ]; then
git config --global url.https://gitlab.bit9.local/.insteadOf [email protected]:
git config --global credential.helper '!function f { echo "username=$GIT_USER"; echo "password=$GIT_TOKEN"; }; f'
# If we have a clone for this job make sure we have the latest, and checkout the branch
# We do not want to remain detached for the audit code
git branch -D $CI_COMMIT_REF_NAME &> /dev/null || true
git fetch --prune &> /dev/null || true
git checkout -B "$CI_BUILD_REF_NAME" "$CI_BUILD_REF"
fi
- docker login -u $SVC_GITLAB_USER_NAME -p $SVC_GITLAB_PASSWORD $DOCKER_REPO
.build_script: &build_script |
# Build Script
echo "### Building ${TARGET}:${REF_TAG}"
TARGET_PATH=.
# If this is not the base we need to do some prep work
if [[ "${TARGET}" != "base" ]]; then
# Just in case this job is on a differnt pull the base image for this build
docker pull ${BASE_IMAGE_NAME}:${REF_TAG}
# This logic comes from dockcross/Makefile
TARGET_PATH=${TARGET}
mkdir -p ${TARGET_PATH}/imagefiles && cp -r imagefiles ${TARGET_PATH}/
fi
# I am only using the make to generate the Dockerfle
make ORG=${DOCKCROSS_ROOT_NAME} ${TARGET_PATH}/Dockerfile
IMAGE=${DOCKCROSS_ROOT_NAME}/${TARGET}
# Do the actual build. This gives us better control of how it is built.
# TODO: I would like to have this use `docker buildx` instead. Right now the method I am using
# to create the multi-arch docker manifest is the the approved approach. Unfortunatly I
# am blocked by
docker build \
-t ${IMAGE}:${REF_TAG} \
--build-arg ORG=${DOCKCROSS_ROOT_NAME} \
--build-arg IMAGE=${IMAGE} \
--build-arg VERSION=${REF_TAG} \
--build-arg VCS_REF=${CI_COMMIT_SHORT_SHA} \
--build-arg VCS_URL="[email protected]:vmware-labs/dockcross.git" \
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
${TARGET_PATH}
rm -rf ${TARGET_PATH}/imagefiles
# We need to push the image so it is available to later jobs.
# Note: We are only pushing the REF_TAG image. The branch and latest images
# will be pushed later.
docker push ${IMAGE}:${REF_TAG}
# BEGIN: Rules to build the base image
.build_template:
stage: build
when: on_success
retry: 2
script:
- *build_script
build:base:amd64:
extends: .build_template
when: always
variables:
TARGET: base
REF_TAG: ${REF_TAG_amd64}
build:base:arm64:
extends: .build_template
when: always
tags:
- aarch64
variables:
TARGET: base
REF_TAG: ${REF_TAG_arm64}
# END: Rules to build the base image
# BEGIN: Template rules to build the toolchain images
# Template to build amd64 tools
.build_amd64_template:
extends: .build_template
needs:
- job: build:base:amd64
# Template to build arm64 tools
.build_arm64_template:
extends: .build_template
needs:
- job: build:base:arm64
tags:
- aarch64
# END: Template rules to build the toolchain images
# BEGIN: Rules to build the toolchain images
build:linux-x86_64-gcc11_2:amd64:
extends: .build_amd64_template
variables:
TARGET: linux-x86_64-gcc11_2
REF_TAG: ${REF_TAG_amd64}
build:linux-arm64-gcc8_2:amd64:
extends: .build_amd64_template
variables:
TARGET: linux-arm64-gcc8_2
REF_TAG: ${REF_TAG_amd64}
build:linux-x86_64-gcc11_2:arm64:
extends: .build_arm64_template
variables:
TARGET: linux-x86_64-gcc11_2
REF_TAG: ${REF_TAG_arm64}
build:linux-arm64-gcc8_2:arm64:
extends: .build_arm64_template
variables:
TARGET: linux-arm64-gcc8_2
REF_TAG: ${REF_TAG_arm64}
# END: Rules to build the toolchain images
# BEGIN: Manifest generation
build:manifest:
stage: build
when: on_success
needs:
- job: build:linux-x86_64-gcc11_2:amd64
- job: build:linux-arm64-gcc8_2:amd64
- job: build:linux-x86_64-gcc11_2:arm64
- job: build:linux-arm64-gcc8_2:arm64
variables:
REF_TAG: ${IMAGE_REF}
script: |
# This logic uses the experimental docker commands.
# See: https://docs.docker.com/engine/reference/commandline/manifest/
set -x
## BEGIN: base image manifest creation
# REF_TAG
docker manifest create ${DOCKCROSS_ROOT_NAME}/base:${REF_TAG} \
--amend ${DOCKCROSS_ROOT_NAME}/base:${REF_TAG_amd64} \
--amend ${DOCKCROSS_ROOT_NAME}/base:${REF_TAG_arm64}
docker manifest push --purge ${DOCKCROSS_ROOT_NAME}/base:${REF_TAG}
# BRANCH_TAG
docker manifest create ${DOCKCROSS_ROOT_NAME}/base:${CI_COMMIT_REF_NAME} \
--amend ${DOCKCROSS_ROOT_NAME}/base:${REF_TAG_amd64} \
--amend ${DOCKCROSS_ROOT_NAME}/base:${REF_TAG_amd64}
docker manifest push --purge ${DOCKCROSS_ROOT_NAME}/base:${CI_COMMIT_REF_NAME}
# latest
docker manifest create ${DOCKCROSS_ROOT_NAME}/base:latest \
--amend ${DOCKCROSS_ROOT_NAME}/base:${REF_TAG_amd64} \
--amend ${DOCKCROSS_ROOT_NAME}/base:${REF_TAG_arm64}
docker manifest push --purge ${DOCKCROSS_ROOT_NAME}/base:latest
## BEGIN: linux-x86_64-gcc11_2 image manifest creation
# REF_TAG
docker manifest create ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${REF_TAG} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${REF_TAG_amd64} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${REF_TAG_arm64}
docker manifest push --purge ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${REF_TAG}
# BRANCH_TAG
docker manifest create ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${CI_COMMIT_REF_NAME} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${REF_TAG_amd64} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${REF_TAG_amd64}
docker manifest push --purge ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${CI_COMMIT_REF_NAME}
# latest
docker manifest create ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:latest \
--amend ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${REF_TAG_amd64} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:${REF_TAG_arm64}
docker manifest push --purge ${DOCKCROSS_ROOT_NAME}/linux-x86_64-gcc11_2:latest
## BEGIN: linux-arm64-gcc8_2 image manifest creation
# REF_TAG
docker manifest create ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${REF_TAG} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${REF_TAG_amd64} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${REF_TAG_arm64}
docker manifest push --purge ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${REF_TAG}
# BRANCH_TAG
docker manifest create ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${CI_COMMIT_REF_NAME} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${REF_TAG_amd64} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${REF_TAG_amd64}
docker manifest push --purge ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${CI_COMMIT_REF_NAME}
# latest
docker manifest create ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:latest \
--amend ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${REF_TAG_amd64} \
--amend ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:${REF_TAG_arm64}
docker manifest push --purge ${DOCKCROSS_ROOT_NAME}/linux-arm64-gcc8_2:latest
# END: Manifest generation