-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclusterbuildstrategy.yml
294 lines (280 loc) · 10.7 KB
/
clusterbuildstrategy.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
---
apiVersion: shipwright.io/v1alpha1
kind: ClusterBuildStrategy
metadata:
name: buildpacks
spec:
volumes:
- name: layers-dir
emptyDir: {}
- name: empty-dir
emptyDir: {}
- name: kaniko-dir
emptyDir: {}
- name: cache-dir
persistentVolumeClaim:
claimName: ws-pvc
parameters:
- name: CNB_PLATFORM_API
description: Platform API Version supported
default: "0.13"
- name: CNB_BUILDER_IMAGE
description: Builder image containing the buildpacks
default: "paketocommunity/builder-ubi-base:0.0.54"
- name: CNB_BUILD_IMAGE
description: Reference to the current build image in an OCI registry (if used <kaniko-dir> must be provided)
default: "paketobuildpacks/build-jammy-tiny:latest"
- name: CNB_LIFECYCLE_IMAGE
description: The image to use when executing Lifecycle phases.
default: "buildpacksio/lifecycle:0.19.3"
- name: CNB_LOG_LEVEL
description: Logging level
default: "info"
- name: CNB_EXPERIMENTAL_MODE
description: Parameter to enable the experimental mode
default: "warn"
- name: APP_IMAGE
description: The name of where to store the app image.
- name: RUN_IMAGE
description: Reference to a run image to use.
default: ""
- name: CACHE_IMAGE
description: The name of the persistent app cache image (if no cache workspace is provided).
default: ""
- name: CACHE_DIR_NAME
description: Directory to cache files
default: cache
- name: PROCESS_TYPE
description: The default process type to set on the image.
default: ""
- name: SOURCE_SUBPATH
description: A subpath within the `source` input where the source to build is located.
default: ""
- name: ENV_VARS
type: array
description: Environment variables to set during _build-time_.
defaults: []
- name: PLATFORM_DIR
description: The name of the platform directory.
default: empty-dir
- # Update the user id to use new paketo builder image till we can use: https://github.com/shipwright-io/community/blob/main/ships/0036-runAs-for-supporting-steps.md
name: CNB_USER_ID
description: The user ID of the builder image user.
default: "1002"
- name: CNB_GROUP_ID
description: The group ID of the builder image user.
default: "1000"
- name: USER_HOME
description: Absolute path to the user's home directory.
default: /tekton/home
buildSteps:
- name: prepare
image: docker.io/library/bash:5.1.4
args:
- -c
- |
set -e
# TODO: To be reviewed
echo "> Creating the cache directory if it is not empty"
if [ ! -d "$DIRECTORY" ]; then
echo "> Creating cache: /layers/$(params.CACHE_DIR_NAME)"
mkdir -p /layers/$(params.CACHE_DIR_NAME)
chown -R "$(params.CNB_USER_ID):$(params.CNB_GROUP_ID)" /layers/$(params.CACHE_DIR_NAME)
fi
# TODO: To be reviewed as shipwright don't support like Tekton workspaces
#if [[ "$(workspaces.cache.bound)" == "true" ]]; then
# echo "> Setting permissions on '$(workspaces.cache.path)'..."
# chown -R "$(params.CNB_USER_ID):$(params.CNB_GROUP_ID)" "$(workspaces.cache.path)"
#fi
for path in "/tekton/home" "/layers" "$(workspaces.source.path)"; do
echo "> Setting permissions on '$path'..."
chown -R "$(params.CNB_USER_ID):$(params.CNB_GROUP_ID)" "$path"
done
echo "> Parsing additional configuration..."
parsing_flag=""
envs=()
for arg in "$@"; do
if [[ "$arg" == "--env-vars" ]]; then
echo "-> Parsing env variables..."
parsing_flag="env-vars"
elif [[ "$parsing_flag" == "env-vars" ]]; then
envs+=("$arg")
fi
done
echo "> Processing any environment variables..."
ENV_DIR="/platform/env"
echo "--> Creating 'env' directory: $ENV_DIR"
mkdir -p "$ENV_DIR"
for env in "${envs[@]}"; do
IFS='=' read -r key value string <<< "$env"
if [[ "$key" != "" && "$value" != "" ]]; then
path="${ENV_DIR}/${key}"
echo "--> Writing ${path}..."
echo -n "$value" > "$path"
fi
done
# That's the separator between the shell script and its args
- --
- --env-vars
- $(params.ENV_VARS[*])
volumeMounts:
- name: layers-dir
mountPath: /layers
- name: empty-dir #name: --> DON'T WORK : $(params.PLATFORM_DIR)
mountPath: /platform
- name: cache-dir #name: --> DON'T WORK : $(params.CACHE_DIR_NAME)
mountPath: /tmp/cache
- name: analyze
image: $(params.CNB_BUILDER_IMAGE)
securityContext:
runAsUser: 1002 # Won't work : $(params.CNB_USER_ID) -> https://github.com/shipwright-io/build/issues/1354
runAsGroup: 1000 # Won't work : $(params.CNB_GROUP_ID) -> https://github.com/shipwright-io/build/issues/1354
command: ["/cnb/lifecycle/analyzer"]
args:
- "-layers=/layers"
- "-run-image=$(params.RUN_IMAGE)"
- "-cache-image=$(params.CACHE_IMAGE)"
- "-uid=$(params.CNB_USER_ID)"
- "-gid=$(params.CNB_GROUP_ID)"
- "$(params.APP_IMAGE)"
env:
- name: CNB_PLATFORM_API
value: $(params.CNB_PLATFORM_API)
volumeMounts:
- name: layers-dir
mountPath: /layers
- name: detect
image: $(params.CNB_BUILDER_IMAGE)
imagePullPolicy: Always
securityContext:
runAsUser: 1002 # Won't work : $(params.CNB_USER_ID) -> https://github.com/shipwright-io/build/issues/1354
runAsGroup: 1000 # Won't work : $(params.CNB_GROUP_ID) -> https://github.com/shipwright-io/build/issues/1354
command: [ "/cnb/lifecycle/detector" ]
args:
- "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)"
- "-group=/layers/group.toml"
- "-plan=/layers/plan.toml"
env:
- name: CNB_PLATFORM_API
value: $(params.CNB_PLATFORM_API)
volumeMounts:
- name: layers-dir
mountPath: /layers
- name: empty-dir # Hard coded the name as substitution do not work: $(params.PLATFORM_DIR)
mountPath: /platform
- name: empty-dir
mountPath: /tekton/home
- name: restore
image: $(params.CNB_BUILDER_IMAGE)
imagePullPolicy: Always
securityContext:
runAsUser: 1002 # Won't work : $(params.CNB_USER_ID) -> https://github.com/shipwright-io/build/issues/1354
runAsGroup: 1000 # Won't work : $(params.CNB_GROUP_ID) -> https://github.com/shipwright-io/build/issues/1354
command: ["/cnb/lifecycle/restorer"]
args:
- "-log-level=$(params.CNB_LOG_LEVEL)"
- "-group=/layers/group.toml"
- "-layers=/layers"
- "-build-image=$(params.CNB_BUILD_IMAGE)"
- "-cache-dir=/layers/$(params.CACHE_DIR_NAME)"
- "-cache-image=$(params.CACHE_IMAGE)"
- "-uid=$(params.CNB_USER_ID)"
- "-gid=$(params.CNB_GROUP_ID)"
env:
- name: CNB_PLATFORM_API
value: $(params.CNB_PLATFORM_API)
volumeMounts:
- name: layers-dir
mountPath: /layers
- name: kaniko-dir
mountPath: /kaniko
- name: cache-dir
mountPath: /tmp/cache #name: --> DON'T WORK : $(params.CACHE_DIR_NAME)
- name: extender
image: $(params.CNB_BUILDER_IMAGE)
imagePullPolicy: Always
command: ["/cnb/lifecycle/extender"]
args:
- "-log-level=$(params.CNB_LOG_LEVEL)"
- "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)"
- "-generated=/layers/generated"
- "-uid=$(params.CNB_USER_ID)"
- "-gid=$(params.CNB_GROUP_ID)"
env:
- name: CNB_PLATFORM_API
value: $(params.CNB_PLATFORM_API)
securityContext:
runAsUser: 0
runAsGroup: 0
capabilities:
add:
- "SYS_ADMIN"
- "SETFCAP"
volumeMounts:
- name: layers-dir
mountPath: /layers
- name: empty-dir # Hard coded the name as substitution do not work: $(params.PLATFORM_DIR)
mountPath: /platform
- name: empty-dir
mountPath: /tekton/home
- name: kaniko-dir
mountPath: /kaniko
- name: cache-dir
mountPath: /tmp/cache #name: --> DON'T WORK : $(params.CACHE_DIR_NAME)
#- name: build-and-push
# image: $(params.CNB_BUILDER_IMAGE)
# imagePullPolicy: Always
# securityContext:
# runAsUser: 1002 # Won't work : $(params.CNB_USER_ID) -> https://github.com/shipwright-io/build/issues/1354
# runAsGroup: 1000 # Won't work : $(params.CNB_GROUP_ID) -> https://github.com/shipwright-io/build/issues/1354
# command: ["/cnb/lifecycle/builder"]
# args:
# - "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)"
# - "-layers=/layers"
# - "-group=/layers/group.toml"
# - "-plan=/layers/plan.toml"
# env:
# - name: CNB_PLATFORM_API
# value: $(params.CNB_PLATFORM_API)
# volumeMounts:
# - name: layers-dir
# mountPath: /layers
# - name: empty-dir # Hard coded the name as substitution do not work: $(params.PLATFORM_DIR)
# mountPath: /platform
# - name: empty-dir
# mountPath: /tekton/home
# - name: cache-dir
# mountPath: /tmp/cache #name: --> DON'T WORK : $(params.CACHE_DIR_NAME)
- name: export
image: $(params.CNB_BUILDER_IMAGE)
imagePullPolicy: Always
command: ["/cnb/lifecycle/exporter"]
args:
- "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)"
- "-layers=/layers"
- "-group=/layers/group.toml"
- "-cache-dir=/layers/$(params.CACHE_DIR_NAME)"
- "-cache-image=$(params.CACHE_IMAGE)"
- "-report=/layers/report.toml"
- "-process-type=$(params.PROCESS_TYPE)"
- "-uid=$(params.CNB_USER_ID)"
- "-gid=$(params.CNB_GROUP_ID)"
- "$(params.APP_IMAGE)"
env:
- name: CNB_PLATFORM_API
value: $(params.CNB_PLATFORM_API)
volumeMounts:
- name: layers-dir
mountPath: /layers
- name: cache-dir
mountPath: /tmp/cache #name: --> DON'T WORK : $(params.CACHE_DIR_NAME)
- name: results
image: docker.io/library/bash:5.1.4
args:
- -c
- |
set -e
cat /layers/report.toml | grep "digest" | cut -d'"' -f2 | cut -d'"' -f2 | tr -d '\n' > $(results.shp-image-digest.path)
volumeMounts:
- name: layers-dir
mountPath: /layers