-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
327 lines (281 loc) · 12.9 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#Variables
variables:
# Configuration for General App Description
# More information can be found on https://store.plcnext.help/st/PLCnext_App_Integration_Guide/Apps_parts/Example_of_a_complete_app_info.htm
# PLCNext App specification
APP_VERSION: "0.1"
MINFIRMWARE_VERSION: "22.0"
APP_NAME: "Template for PLCNext Apps"
LICENSE_TYPE: "Free"
MANUFACTOR: "Phoenix Contact GmbH and Co. KG"
# ENV for LinuxDeamons
LINUXDAEMON_PATH: "/bin/placeholder"
# ENV for ARM Architecture
IDENTIFIER_ARM: "60002172000510"
TARGET_ARM: "AXC F 2152"
# ENV for x86 Architecture
IDENTIFIER_X86: "60002172000551"
TARGET_X86: "AXC F 3152,RFC 4072S,EPC 1502,EPC 1522,BPC 9102S"
# Compressed tarball that the image will be saved to
IMAGE_FILE_NAME: "nginx"
# A Docker build ENV
IMAGE_NAME: "nginx"
IMAGE_DESTINATION: "plcnext/nginx"
IMAGE_TAG: "1.24"
# Build specific Variables
# arm env
ENV_FILE_ARM: "arm\/.env"
# x86 env
ENV_FILE_X86: "x86\/.env"
# Build stages
stages:
- container_existing_image
- build_new_image
- container_new_image
# Build process for image that need to be build up
build_new_image:arm32v7:
stage: build_new_image
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
#Kaniko Executor to build image, its used here because of the easy and rootless integration
- /kaniko/executor
--context $CI_PROJECT_DIR/build_new_image/build
--dockerfile $CI_PROJECT_DIR/build_new_image/build/Dockerfile
--destination ${IMAGE_NAME}:${IMAGE_TAG}
--build-arg ARCH=arm32v7
--build-arg BUILD_DATE="$(date +"%Y-%m-%dT%H:%M:%SZ")"
--build-arg TAG_SUFFIX=default
--build-arg OS=alpine
--no-push
--customPlatform=linux/arm/v7
--tarPath ./${IMAGE_NAME}-${CI_COMMIT_SHA}.tar
- gzip ./${IMAGE_NAME}-${CI_COMMIT_SHA}.tar
allow_failure: false
when: always
tags:
- shared-runner-kubernetes
- multi-arc
artifacts:
name: "container_arm"
paths:
- ./${IMAGE_NAME}-${CI_COMMIT_SHA}.tar.gz
expire_in: 10 minutes
build_new_image:x86:
stage: build_new_image
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
#Replace NodeRed version from ENV
- /kaniko/executor
--context $CI_PROJECT_DIR/build_new_image/build
--dockerfile $CI_PROJECT_DIR/build_new_image/build/Dockerfile
--destination ${IMAGE_NAME}:${IMAGE_TAG}
--build-arg ARCH=amd64
--build-arg BUILD_DATE="$(date +"%Y-%m-%dT%H:%M:%SZ")"
--build-arg TAG_SUFFIX=default
--build-arg OS=alpine
--no-push
--customPlatform=linux/amd64
--tarPath ./${IMAGE_NAME}-${CI_COMMIT_SHA}.tar
- gzip ./${IMAGE_NAME}-${CI_COMMIT_SHA}.tar
allow_failure: false
when: always
tags:
- shared-runner-kubernetes
- multi-arc
artifacts:
name: "container_x86"
paths:
- ./${IMAGE_NAME}-${CI_COMMIT_SHA}.tar.gz
expire_in: 10 minutes
container_new_image:arm32v7:
stage: container_new_image
image:
name: ubuntu:22.04
needs: ["build_new_image:arm32v7"]
before_script:
# update repos and install dependecies
- apt-get update
- apt-get install -y squashfs-tools rpm curl jq
script:
# set Bash executable
- chmod +x scripts/replace_or_add_string.sh
# set ENV
- sed -i -e 's/NAME=.*/NAME='"${APP_NAME}"'/g' -e '$ a NAME='"${APP_NAME}" build_new_image/${ENV_FILE_ARM}
- scripts/replace_or_add_string.sh build_new_image/${ENV_FILE_ARM} 'IMAGE_NAME' "IMAGE_NAME=${IMAGE_NAME}"
- scripts/replace_or_add_string.sh build_new_image/${ENV_FILE_ARM} 'IMAGE_TAG' "IMAGE_TAG=${IMAGE_TAG}"
- scripts/replace_or_add_string.sh build_new_image/${ENV_FILE_ARM} 'IMAGE_FILE_NAME' "IMAGE_FILE_NAME=${IMAGE_FILE_NAME}"
# copy dependecies
- cp ./${IMAGE_NAME}-${CI_COMMIT_SHA}.tar.gz build_new_image/arm/images/${IMAGE_NAME}.tar.gz
# set information for app_info file
- sed -i 's/"name":.*/"name":\ "'"${APP_NAME}"'",/g' build_new_image/arm/app_info.json
- sed -i 's/"identifier":.*/"identifier":\ "'"${IDENTIFIER_ARM}"'",/g' build_new_image/arm/app_info.json
- sed -i 's/"version":.*/"version":\ "'"${APP_VERSION}"'",/g' build_new_image/arm/app_info.json
- sed -i 's/"target":.*/"target":\ "'"${TARGET_ARM}"'",/g' build_new_image/arm/app_info.json
- sed -i 's/"minfirmware_version":.*/"minfirmware_version":\ "'"${MINFIRMWARE_VERSION}"'",/g' build_new_image/arm/app_info.json
- sed -i 's/"manufacturer":.*/"manufacturer":\ "'"${MANUFACTOR}"'",/g' build_new_image/arm/app_info.json
- sed -i 's/"licensetype":.*/"licensetype":\ "'"${LICENSE_TYPE}"'"/g' build_new_image/arm/app_info.json
#Copy data and settings if you have something to copy
#- cp -r ./data/* dir
#Replace Windows style to Unix style for bash scripts
- sed -i -e 's/\r$//' build_new_image/arm/initscript.sh
- chmod +x build_new_image/arm/initscript.sh
- mksquashfs build_new_image/arm ${IMAGE_NAME}-${CI_COMMIT_SHORT_SHA}_ARMv7.app -force-uid 1001 -force-gid 1002
allow_failure: false
when: always
tags:
- shared-runner-kubernetes
- multi-arc
dependencies:
- build_new_image:arm32v7
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_SHORT_SHA}_armv7"
paths:
- ./*.app
when: on_success
expire_in: 1 Hour
container_new_image:x86:
stage: container_new_image
image:
name: ubuntu:22.04
needs: ["build_new_image:x86"]
before_script:
#Update repos and install dependecies
- apt-get update
- apt-get install -y squashfs-tools rpm curl jq
script:
# Set Bash executable
- chmod +x scripts/replace_or_add_string.sh
#Set ENV
- sed -i -e 's/NAME=.*/NAME='"${APP_NAME}"'/g' -e '$ a NAME='"${APP_NAME}" build_new_image/${ENV_FILE_X86}
- scripts/replace_or_add_string.sh build_new_image/${ENV_FILE_X86} 'IMAGE_NAME' "IMAGE_NAME=${IMAGE_NAME}"
- scripts/replace_or_add_string.sh build_new_image/${ENV_FILE_X86} 'IMAGE_TAG' "IMAGE_TAG=${IMAGE_TAG}"
- scripts/replace_or_add_string.sh build_new_image/${ENV_FILE_X86} 'IMAGE_FILE_NAME' "IMAGE_FILE_NAME=${IMAGE_FILE_NAME}"
# Copy dependecies
- cp ./${IMAGE_NAME}-${CI_COMMIT_SHA}.tar.gz build_new_image/x86/images/${IMAGE_NAME}.tar.gz
# set information for app_info file
- sed -i 's/"name":.*$/"name":\ "'"${APP_NAME}"'",/g' build_new_image/x86/app_info.json
- sed -i 's/"identifier":.*$/"identifier":\ "'"${IDENTIFIER_X86}"'",/g' build_new_image/x86/app_info.json
- sed -i 's/"version":.*$/"version":\ "'"${APP_VERSION}"'",/g' build_new_image/x86/app_info.json
- sed -i 's/"target":.*$/"target":\ "'"${TARGET_X86}"'",/g' build_new_image/x86/app_info.json
- sed -i 's/"minfirmware_version":.*$/"minfirmware_version":\ "'"${MINFIRMWARE_VERSION}"'",/g' build_new_image/x86/app_info.json
- sed -i 's/"manufacturer":.*$/"manufacturer":\ "'"${MANUFACTOR}"'",/g' build_new_image/x86/app_info.json
- sed -i 's/"licensetype":.*$/"licensetype":\ "'"${LICENSE_TYPE}"'"/g' build_new_image/x86/app_info.json
#Replace Windows style to Unix style for bash scripts
- sed -i -e 's/\r$//' build_new_image/x86/initscript.sh
- chmod +x build_new_image/x86/initscript.sh
- mksquashfs build_new_image/x86 ${IMAGE_NAME}-${CI_COMMIT_SHORT_SHA}_x86.app -force-uid 1001 -force-gid 1002
allow_failure: false
when: always
tags:
- shared-runner-kubernetes
- multi-arc
# cache:
# key: kaniko-cache
# paths:
# - ./cache
dependencies:
- build_new_image:x86
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_SHORT_SHA}_x86"
paths:
- ./*.app
when: on_success
expire_in: 1 Hour
# Build process for existing images
container_existing_image:amd64:
stage: container_existing_image
image:
name: ubuntu:latest
before_script:
#Update repos and install dependecies
- apt-get update && apt-get upgrade -y
- apt-get install -y squashfs-tools rpm curl jq
script:
# set Bash executable
- chmod +x scripts/replace_or_add_string.sh
# set ENV
- sed -i -e 's/NAME=.*/NAME='"${APP_NAME}"'/g' -e '$ a NAME='"${APP_NAME}" build_existing_image/${ENV_FILE_X86}
- scripts/replace_or_add_string.sh build_existing_image/${ENV_FILE_X86} 'IMAGE_NAME' "IMAGE_NAME=${IMAGE_NAME}"
- scripts/replace_or_add_string.sh build_existing_image/${ENV_FILE_X86} 'IMAGE_TAG' "IMAGE_TAG=${IMAGE_TAG}"
- scripts/replace_or_add_string.sh build_existing_image/${ENV_FILE_X86} 'IMAGE_FILE_NAME' "IMAGE_FILE_NAME=${IMAGE_FILE_NAME}"
- cat build_existing_image/${ENV_FILE_ARM}
# download Docker images to store for local installation and
- chmod +x ./scripts/download-frozen-image-v2.sh
# load Influxdb
- mkdir -p ./build_existing_image/x86/images/tmp/$IMAGE_NAME
- ./scripts/download-frozen-image-v2.sh build_existing_image/x86/images/tmp/$IMAGE_NAME amd64/$IMAGE_NAME:$IMAGE_TAG
- tar -czvC build_existing_image/x86/images/tmp/$IMAGE_NAME . -f build_existing_image/x86/images/$IMAGE_NAME.tar.gz
- rm -r build_existing_image/x86/images/tmp
# set information for app_info file
- sed -i 's/"name":.*/"name":\ "'"${APP_NAME}"'",/g' build_existing_image/x86/app_info.json
- sed -i 's/"identifier":.*/"identifier":\ "'"${IDENTIFIER_X86}"'",/g' build_existing_image/x86/app_info.json
- sed -i 's/"version":.*/"version":\ "'"${APP_VERSION}"'",/g' build_existing_image/x86/app_info.json
- sed -i 's/"target":.*/"target":\ "'"${TARGET_X86}"'",/g' build_existing_image/x86/app_info.json
- sed -i 's/"minfirmware_version":.*/"minfirmware_version":\ "'"${MINFIRMWARE_VERSION}"'",/g' build_existing_image/x86/app_info.json
- sed -i 's/"manufacturer":.*/"manufacturer":\ "'"${MANUFACTOR}"'",/g' build_existing_image/x86/app_info.json
- sed -i 's/"licensetype":.*/"licensetype":\ "'"${LICENSE_TYPE}"'"/g' build_existing_image/x86/app_info.json
#Replace Windows style to Unix style for bash scripts
- sed -i -e 's/\r$//' build_existing_image/x86/initscript.sh
- chmod +x build_existing_image/x86/initscript.sh
- mksquashfs build_existing_image/x86 $IMAGE_NAME-${CI_COMMIT_SHORT_SHA}_x86.app -force-uid 1001 -force-gid 1002
allow_failure: false
when: always
tags:
- shared-runner-kubernetes
- multi-arc
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_SHORT_SHA}_x86"
paths:
- ./*.app
when: on_success
expire_in: 1 week
container_existing_image:arm32v7:
stage: container_existing_image
image:
name: ubuntu:latest
before_script:
#Update repos and install dependecies
- apt-get update && apt-get upgrade -y
- apt-get install -y squashfs-tools rpm curl jq
script:
# set Bash executable
- chmod +x scripts/replace_or_add_string.sh
# set ENV
- sed -i -e 's/NAME=.*/NAME='"${APP_NAME}"'/g' -e '$ a NAME='"${APP_NAME}" build_existing_image/${ENV_FILE_ARM}
- scripts/replace_or_add_string.sh build_existing_image/${ENV_FILE_ARM} 'IMAGE_NAME' "IMAGE_NAME=${IMAGE_NAME}"
- scripts/replace_or_add_string.sh build_existing_image/${ENV_FILE_ARM} 'IMAGE_TAG' "IMAGE_TAG=${IMAGE_TAG}"
- scripts/replace_or_add_string.sh build_existing_image/${ENV_FILE_ARM} 'IMAGE_FILE_NAME' "IMAGE_FILE_NAME=${IMAGE_FILE_NAME}"
# download Docker images to store for local installation and
- chmod +x ./scripts/download-frozen-image-v2.sh
# load Influxdb
- mkdir -p ./build_existing_image/arm/images/tmp/$IMAGE_NAME
- ./scripts/download-frozen-image-v2.sh build_existing_image/arm/images/tmp/$IMAGE_NAME arm32v7/$IMAGE_NAME:$IMAGE_TAG
- tar -czvC build_existing_image/arm/images/tmp/$IMAGE_NAME . -f build_existing_image/arm/images/$IMAGE_NAME.tar.gz
- rm -r build_existing_image/arm/images/tmp
# set information for app_info file
- sed -i 's/"name":.*/"name":\ "'"${APP_NAME}"'",/g' build_existing_image/arm/app_info.json
- sed -i 's/"identifier":.*/"identifier":\ "'"${IDENTIFIER_ARM}"'",/g' build_existing_image/arm/app_info.json
- sed -i 's/"version":.*/"version":\ "'"${APP_VERSION}"'",/g' build_existing_image/arm/app_info.json
- sed -i 's/"target":.*/"target":\ "'"${TARGET_ARM}"'",/g' build_existing_image/arm/app_info.json
- sed -i 's/"minfirmware_version":.*/"minfirmware_version":\ "'"${MINFIRMWARE_VERSION}"'",/g' build_existing_image/arm/app_info.json
- sed -i 's/"manufacturer":.*/"manufacturer":\ "'"${MANUFACTOR}"'",/g' build_existing_image/arm/app_info.json
- sed -i 's/"licensetype":.*/"licensetype":\ "'"${LICENSE_TYPE}"'"/g' build_existing_image/arm/app_info.json
#Replace Windows style to Unix style for bash scripts
- sed -i -e 's/\r$//' build_existing_image/arm/initscript.sh
- chmod +x build_existing_image/arm/initscript.sh
- mksquashfs build_existing_image/arm $IMAGE_NAME-${CI_COMMIT_SHORT_SHA}_arm.app -force-uid 1001 -force-gid 1002
allow_failure: false
when: always
tags:
- shared-runner-kubernetes
- multi-arc
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_SHORT_SHA}_arm"
paths:
- ./*.app
when: on_success
expire_in: 1 week