-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathpublish-index-image.yaml
More file actions
236 lines (221 loc) · 8.35 KB
/
Copy pathpublish-index-image.yaml
File metadata and controls
236 lines (221 loc) · 8.35 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
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
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: publish-index-image
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
spec:
description: |-
Publish a built FBC index image using skopeo
params:
- name: dataPath
description: Path to the JSON string of the merged data to use in the data workspace
type: string
- name: internalRequestResultsFile
type: string
description: File containing the results of the build
- name: retries
type: string
default: "0"
description: Number of skopeo retries
- name: requestTimeout
type: string
default: "360"
description: Max seconds waiting for the status update
- name: buildTimestamp
type: string
description: Build timestamp for the publishing image
- name: pipelineRunUid
type: string
description: The uid of the current pipelineRun. Used as a label value when creating internal requests
- name: ociStorage
description: The OCI repository where the Trusted Artifacts are stored
type: string
default: "empty"
- name: ociArtifactExpiresAfter
description: Expiration date for the trusted artifacts created in the
OCI repository. An empty string means the artifacts do not expire
type: string
default: "1d"
- name: trustedArtifactsDebug
description: Flag to enable debug logging in trusted artifacts. Set to a non-empty string to enable
type: string
default: ""
- name: orasOptions
description: oras options to pass to Trusted Artifacts calls
type: string
default: ""
- name: sourceDataArtifact
type: string
description: Location of trusted artifacts to be used to populate data directory
default: ""
- name: dataDir
description: The location where data will be stored
type: string
default: /var/workdir/release
- name: taskGitUrl
type: string
description: The url to the git repo where the release-service-catalog tasks and stepactions to be used are stored
- name: taskGitRevision
type: string
description: The revision in the taskGitUrl repo to be used
- name: caTrustConfigMapName
type: string
description: The name of the ConfigMap to read CA bundle data from
default: trusted-ca
- name: caTrustConfigMapKey
type: string
description: The name of the key in the ConfigMap that contains the CA bundle data
default: ca-bundle.crt
results:
- name: requestMessage
type: string
- name: sourceDataArtifact
type: string
description: Produced trusted data artifact
volumes:
- name: workdir
emptyDir: {}
- name: trusted-ca
configMap:
name: $(params.caTrustConfigMapName)
items:
- key: $(params.caTrustConfigMapKey)
path: ca-bundle.crt
optional: true
stepTemplate:
volumeMounts:
- mountPath: /var/workdir
name: workdir
- name: trusted-ca
mountPath: /mnt/trusted-ca
readOnly: true
securityContext:
runAsUser: 1001
env:
- name: IMAGE_EXPIRES_AFTER
value: $(params.ociArtifactExpiresAfter)
- name: "ORAS_OPTIONS"
value: "$(params.orasOptions)"
- name: "DEBUG"
value: "$(params.trustedArtifactsDebug)"
steps:
- name: use-trusted-artifact
computeResources:
limits:
memory: 64Mi
requests:
memory: 64Mi
cpu: 30m
ref:
resolver: "git"
params:
- name: url
value: $(params.taskGitUrl)
- name: revision
value: $(params.taskGitRevision)
- name: pathInRepo
value: stepactions/use-trusted-artifact/use-trusted-artifact.yaml
params:
- name: workDir
value: $(params.dataDir)
- name: sourceDataArtifact
value: $(params.sourceDataArtifact)
- name: publish-index-image
image: >-
quay.io/konflux-ci/release-service-utils@sha256:5546fa78d3c88d7b6a2e8cff8902f7757f00541d0bbaf113b9f293133894afa3
computeResources:
limits:
memory: 512Mi
requests:
memory: 512Mi
cpu: 200m
script: |
#!/usr/bin/env bash
set -e
DATA_FILE="$(params.dataDir)/$(params.dataPath)"
if [ ! -f "${DATA_FILE}" ] ; then
echo "No valid data file was provided."
exit 1
fi
request="publish-index-image-pipeline"
credentials=$(jq -r '.fbc.publishingCredentials' "$DATA_FILE")
pipelinerun_label="internal-services.appstudio.openshift.io/pipelinerun-uid"
LENGTH="$(jq -r '.components | length' "$(params.dataDir)/$(params.internalRequestResultsFile)")"
for((i=0; i<LENGTH; i++)); do
targetIndex=$(jq -r --argjson i "$i" \
'.components[$i].target_index' "$(params.dataDir)/$(params.internalRequestResultsFile)")
sourceIndex="$(jq -r --argjson i "$i" \
'.components[$i].index_image' "$(params.dataDir)/$(params.internalRequestResultsFile)")"
targetOcpVersion=$(jq -r --argjson i "$i" \
'.components[$i].ocp_version' "$(params.dataDir)/$(params.internalRequestResultsFile)")
buildTimestamp=$(jq -r --argjson i "$i" '.components[$i].completion_time' \
"$(params.dataDir)/$(params.internalRequestResultsFile)")
publishingImages=("$targetIndex")
# only publish the extra timestamp-based tag if the targetIndex does not have it already
if [[ ! "$targetIndex" =~ .*"$buildTimestamp"$ ]]; then
publishingImages+=("${targetIndex}-${buildTimestamp}")
fi
requestTimeout=$(params.requestTimeout)
pipelineTimeoutSeconds=$((requestTimeout+300))
pipelineTimeout=$(date -u -d @"${pipelineTimeoutSeconds}" +"%Hh%Mm%Ss")
taskTimeout=$(date -u -d @"${requestTimeout}" +"%Hh%Mm%Ss")
IR_RESULT_FILE=$(mktemp)
for((x=0; x<${#publishingImages[@]}; x++ )); do
echo "=== Creating internal request to publish image:"
echo ""
echo "- from: ${sourceIndex}"
echo "- to: ${publishingImages[$x]}"
internal-request --pipeline "${request}" \
-p sourceIndex="${sourceIndex}" \
-p targetIndex="${publishingImages[$x]}" \
-p targetOcpVersion="${targetOcpVersion}" \
-p publishingCredentials="${credentials}" \
-p retries="$(params.retries)" \
-p taskGitUrl="$(params.taskGitUrl)" \
-p taskGitRevision="$(params.taskGitRevision)" \
-t "$(params.requestTimeout)" \
--pipeline-timeout "${pipelineTimeout}" \
--task-timeout "$taskTimeout" \
-l ${pipelinerun_label}="$(params.pipelineRunUid)" \
| tee "$IR_RESULT_FILE" || \
(grep "^\[" "$IR_RESULT_FILE" | jq . && exit 1)
internalRequest=$(awk -F"'" '/created/ { print $2 }' "$IR_RESULT_FILE")
echo "done (${internalRequest})"
results=$(kubectl get internalrequest "${internalRequest}" -o=jsonpath='{.status.results}')
requestMessage=$(echo "${results}" | jq -r '.requestMessage // ""')
if echo "${requestMessage}" | grep -qi "error"; then
echo "ERROR: Publish to ${publishingImages[$x]} failed"
echo "requestMessage: ${requestMessage}"
exit 1
fi
echo "=== published successfully (${publishingImages[$x]})"
echo ""
echo ""
done
done
- name: create-trusted-artifact
computeResources:
limits:
memory: 128Mi
requests:
memory: 128Mi
cpu: 250m
ref:
resolver: "git"
params:
- name: url
value: $(params.taskGitUrl)
- name: revision
value: $(params.taskGitRevision)
- name: pathInRepo
value: stepactions/create-trusted-artifact/create-trusted-artifact.yaml
params:
- name: ociStorage
value: $(params.ociStorage)
- name: workDir
value: $(params.dataDir)
- name: sourceDataArtifact
value: $(results.sourceDataArtifact.path)