1
+ #
2
+ # This task will build an appsody project specificed in the git-source using `appsody build`
3
+ # and push the generated application image to the specified image registry. The image can be optionally
4
+ # signed before it's pushed to the registry.
5
+ #
6
+ # If the gitops-map configmap is configured, it will also promote the service to the specified gitops repo.
7
+ # If gitops is enabled, a secret called gitops-token also needs to be configured with the token for the gitops repo.
8
+ #
9
+ # Insecure registy access or secure connection to the image registries can be setup by configuring the
10
+ # OpenShift cluster resource. For more information, refer to https://kabanero.io/guides/working-with-pipelines/#transport-layer-security-tls-verification-for-image-registry-access-in-pipelines
11
+ #
1
12
apiVersion : tekton.dev/v1beta1
2
13
kind : Task
3
14
metadata :
19
30
type : string
20
31
steps :
21
32
- name : enforce-stack-policy-pre-build
33
+ # This step enforces the pre build stack governance policy configured in the Kabanero CR.
34
+ # Refer to https://kabanero.io/docs/ref/general/reference/semver-governance.html for policy details.
22
35
securityContext :
23
36
privileged : true
24
37
image : kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
@@ -32,52 +45,71 @@ spec:
32
45
value : git-source
33
46
volumeMounts :
34
47
- mountPath : /var/lib/containers
35
- name : varlibcontainers
48
+ name : varlibcontainers
36
49
- name : build
50
+ # This steps builds the source project using appsody build.
37
51
securityContext :
38
52
privileged : true
39
53
image : kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
54
+ imagePullPolicy : Always
40
55
command : ["/bin/bash"]
41
56
args :
42
57
- -c
43
58
- |
44
- cd /workspace/$gitsource
45
-
46
- #executing the insecure_registry_setup.sh script if exists, to add internal registry to insecure registry list
47
- if [ -f "/scripts/insecure_registry_setup.sh" ]; then
48
- echo "Running the script /scripts/insecure_registry_setup.sh ...."
49
- /scripts/insecure_registry_setup.sh
50
- echo "printing the content /etc/containers/registries.conf"
51
- cat /etc/containers/registries.conf
59
+ # Configure image registry access in the container by adding it to the insecure registry list or enabling TLS verification
60
+ # by adding it to the trust store based on OpenShift cluster resource configuration.
61
+ echo "[INFO] Running the script /scripts/image_registry_access_setup.sh ...."
62
+ /scripts/image_registry_access_setup.sh
63
+ retVal=$?
64
+ if [ $retVal -ne 0 ]
65
+ then
66
+ echo "[ERROR] The script failed(/scripts/image_registry_access_setup.sh)" >&2
67
+ exit $retVal
52
68
fi
69
+ echo "[INFO] Completed setup for image registry access."
53
70
54
- #executing the ca_certs_setup.sh script if exists, to add additional trusted ca certs to /etc/docker/certs.d/<hosname>/ca.crt
55
- if [ -f "/scripts/ca_certs_setup.sh" ]; then
56
- echo "Running the script /scripts/ca_certs_setup.sh ...."
57
- /scripts/ca_certs_setup.sh
71
+ # If the image registry URL of the stack image is the external route of the internal registry, change the stack regisry URL to the
72
+ # internal route. This avoids having to configure additional secrets, certificates etc.
73
+ OUTPUTS_STACK_IMAGE_REGISTRY_URL=$( /scripts/stack_registry_url_setup.sh )
74
+ retVal=$?
75
+ if [ $retVal -ne 0 ]
76
+ then
77
+ echo "[ERROR] The script failed(/scripts/stack_registry_url_setup.sh) Reason: $OUTPUTS_STACK_IMAGE_REGISTRY_URL" >&2
78
+ exit $retVal
58
79
fi
59
80
81
+ echo "[INFO] Stack registry URL = $OUTPUTS_STACK_IMAGE_REGISTRY_URL"
82
+
83
+ # Docker does not support upper case characters in the image name. Github does not have this restriction.
84
+ # So lowercase the image name if it has any upper case characters.
60
85
OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE=$( /scripts/imageurl_imagename_lowercase.sh -u $(outputs.resources.docker-image.url) -n $(inputs.params.docker-imagename) -t $(inputs.params.docker-imagetag) )
61
86
retVal=$?
62
87
if [ $retVal -ne 0 ]
63
88
then
64
- echo "The script failed(/scripts/imageurl_imagename_lowercase.sh) Reason: $OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" >&2
89
+ echo "[ERROR] The script failed(/scripts/imageurl_imagename_lowercase.sh) Reason: $OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" >&2
65
90
exit $retVal
66
91
fi
67
92
68
- echo "OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE= $OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
93
+ echo "[INFO] Application image URL = $OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
69
94
95
+ # Kickoff appsody build
70
96
cd /workspace/$gitsource
71
- appsody build -t "$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" --buildah --buildah-options "--format=docker"
72
- #echo "Copying the generated app-deploy.yaml file from input to the output to pass the file to the next task when this task is used in deploy pipeline"
73
- #cp app-deploy.yaml $(outputs.resources.git-source.path)
97
+ echo "[INFO] Running appsody build..."
98
+ appsody build -t "$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" --buildah --buildah-options "--format=docker" --stack-registry "$OUTPUTS_STACK_IMAGE_REGISTRY_URL"
99
+ if [ $? != 0 ]; then
100
+ echo "[ERROR] Appsody build failed. Please review the appsody build logs above. Pipeline run aborted."
101
+ exit 1
102
+ fi
103
+ echo "[INFO] Completed appsody build."
74
104
env :
75
105
- name : gitsource
76
106
value : git-source
77
107
volumeMounts :
78
108
- mountPath : /var/lib/containers
79
109
name : varlibcontainers
80
110
- name : enforce-stack-policy-post-build
111
+ # This step enforces the post build stack governance policy configured in the Kabanero CR.
112
+ # Refer to https://kabanero.io/docs/ref/general/reference/semver-governance.html for policy details.
81
113
securityContext :
82
114
privileged : true
83
115
image : kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
@@ -86,66 +118,71 @@ spec:
86
118
- -c
87
119
- |
88
120
/scripts/enforce_stack_policy.sh post-build
121
+
89
122
env :
90
123
- name : gitsource
91
124
value : git-source
92
125
volumeMounts :
93
126
- mountPath : /var/lib/containers
94
- name : varlibcontainers
127
+ name : varlibcontainers
95
128
- name : push
129
+ # Push the image built in the build step to the specified image registry. Optionally sign the image.
96
130
securityContext :
97
131
privileged : true
98
132
image : kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
99
133
command : ["/bin/bash"]
100
134
args :
101
135
- -c
102
136
- |
103
-
137
+ # Docker does not support upper case characters in the image name. Github does not have this restriction.
138
+ # So lowercase the image name if it has any upper case characters.
104
139
OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE=$( /scripts/imageurl_imagename_lowercase.sh -u $(outputs.resources.docker-image.url) -n $(inputs.params.docker-imagename) -t $(inputs.params.docker-imagetag) )
105
140
retVal=$?
106
141
if [ $retVal -ne 0 ]
107
142
then
108
- echo "The script failed(/scripts/imageurl_imagename_lowercase.sh) Reason: $OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" >&2
143
+ echo "[ERROR] The script failed(/scripts/imageurl_imagename_lowercase.sh) Reason: $OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" >&2
109
144
exit $retVal
110
145
fi
111
- echo "OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE=$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
146
+
147
+ echo "[INFO] Application image URL = $OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
112
148
113
- #executing the insecure_registry_setup.sh script if exists, to add internal registry to insecure registry list
114
- if [ -f "/scripts/insecure_registry_setup.sh" ]; then
115
- echo "Running the script /scripts/insecure_registry_setup.sh ...."
116
- /scripts/insecure_registry_setup.sh
117
- fi
118
-
119
- #executing the ca_certs_setup.sh script if exists, to add additional trusted ca certs to /etc/docker/certs.d/<hosname>/ca.crt
120
- if [ -f "/scripts/ca_certs_setup.sh" ]; then
121
- echo "Running the script /scripts/ca_certs_setup.sh ...."
122
- /scripts/ca_certs_setup.sh
149
+ # Configure image registry access in the container by adding it to the insecure registry list or enabling TLS verification
150
+ # by adding it to the trust store based on OpenShift cluster resource configuration.
151
+ echo "[INFO] Running the script /scripts/image_registry_access_setup.sh ...."
152
+ /scripts/image_registry_access_setup.sh
153
+ retVal=$?
154
+ if [ $retVal -ne 0 ]
155
+ then
156
+ echo "[ERROR] The script failed(/scripts/image_registry_access_setup.sh)" >&2
157
+ exit $retVal
123
158
fi
124
159
125
- #if /image-signing-config/registry does not exist, a container image signature is not generated .
160
+ # Check if /image-signing-config/registry is setup to enable container image signature generation .
126
161
if [ -f "/image-signing-config/registry" ]; then
127
- REPO=`cat /image-signing-config/registry`
162
+ REPO=`cat /image-signing-config/registry`
128
163
fi
129
164
if [[ -z $REPO ]] || [[ $OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE != $REPO/* ]]; then
130
- echo "Signature will not be generated. The signed image repository is not set or does not match the target registry."
165
+ echo "[INFO] Signature will not be generated. The signed image repository is not set or does not match the target registry."
166
+ echo "[INFO] Pushing image to registry..."
131
167
buildah push "$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" "docker://$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
132
168
else
133
- echo "Signature will be generated."
169
+ echo "[INFO] Signature will be generated."
134
170
#importing RSA secret key, then extract an e-mail address from it.
135
171
gpg --import /image-signing-config/secret.asc
136
172
SIGNBY=`gpg --list-keys|sed -n -e "/.*<.*>.*/p"|sed -e "s/^.*<\(.*\)>.*$/\1/"`
173
+ echo "[INFO] Pushing image to registry..."
137
174
skopeo copy --remove-signatures --sign-by $SIGNBY "containers-storage:$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" "docker://$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
138
175
RESULT=$?
139
176
if [ $RESULT -ne 0 ]; then
140
- echo "sign-image failed. exit code : $RESULT"
177
+ echo "[ERROR] sign-image failed. exit code : $RESULT"
141
178
exit $RESULT
142
179
fi
143
180
if [[ -z `cat /image-signing-config/sigstore` ]]; then
144
- echo "Signature is stored in the image registry"
181
+ echo "[INFO] Signature is stored in the image registry"
145
182
else
146
183
#invoking scripts for processing a generated signature.
147
- echo "A signature is stored by scripts."
148
- for f in /sigstore-script/*; do [ -f "$f" ] || break; echo "Processing $f"; $f; done
184
+ echo "[INFO] A signature is stored by scripts."
185
+ for f in /sigstore-script/*; do [ -f "$f" ] || break; echo "[INFO] Processing $f"; $f; done
149
186
fi
150
187
fi
151
188
env :
@@ -159,23 +196,24 @@ spec:
159
196
- mountPath : /etc/containers/registries.d
160
197
name : registries-d
161
198
- mountPath : /sigstore-script
162
- name : sigstore-script
199
+ name : sigstore-script
163
200
- name : promote
201
+ # Promote the service to the configured gitops repository using the `services promote` CLI
164
202
securityContext :
165
203
privileged : true
166
- image : quay.io/redhat-developer/gitops-cli:latest
204
+ image : quay.io/redhat-developer/gitops-cli@sha256:f5f47bb0cf1dcd081c29e7017e4511441cab3379d06ef587ba6e539f005945dd
167
205
command : ["/bin/bash"]
168
206
args :
169
207
- -c
170
208
- |
171
209
echo " "
172
- echo "Gitops repo url = $GITOPS_REPOSITORY_URL"
173
- echo "Gitops repo type = $GITOPS_REPOSITORY_TYPE"
174
- echo "Gitops repo commit name = $GITOPS_COMMIT_USER_NAME"
175
- echo "Gitops repo commit email = $GITOPS_COMMIT_USER_EMAIL"
176
- echo " "
210
+ echo "[INFO] Gitops repo url = $GITOPS_REPOSITORY_URL"
177
211
178
212
if [[ ! -z "$GITOPS_REPOSITORY_URL" ]]; then
213
+ echo "[INFO] Gitops repo type = $GITOPS_REPOSITORY_TYPE"
214
+ echo "[INFO] Gitops repo commit name = $GITOPS_COMMIT_USER_NAME"
215
+ echo "[INFO] Gitops repo commit email = $GITOPS_COMMIT_USER_EMAIL"
216
+ echo " "
179
217
180
218
if [ -z "$GITHUB_TOKEN" ]; then
181
219
echo "[ERROR] Secret 'gitops-token' with the token to access gitops repo was not configured. Please configure secret and try again."
@@ -229,7 +267,7 @@ spec:
229
267
cat $HOME/.gitconfig
230
268
231
269
echo " "
232
- echo "service name = $(inputs.params.git-project)"
270
+ echo "[INFO] service name = $(inputs.params.git-project)"
233
271
if [[ -z "$(inputs.params.git-project)" ]]; then
234
272
echo "[ERROR] Unable to retrieve service name from input params. Unable to promote."
235
273
exit 1
@@ -242,7 +280,7 @@ spec:
242
280
fi
243
281
244
282
gitCommit=$(git rev-parse --short HEAD)
245
- services promote --from /workspace/$gitsource --to $(GITOPS_REPOSITORY_URL) --service $(inputs.params.git-project) --commit-message "Publish $(inputs.params.git-project) commit $gitCommit" --debug -- repository-type GITOPS_REPOSITORY_TYPE
283
+ services promote --from /workspace/$gitsource --to $(GITOPS_REPOSITORY_URL) --service $(inputs.params.git-project) --commit-message "Publish $(inputs.params.git-project) commit $gitCommit" --repository-type $( GITOPS_REPOSITORY_TYPE)
246
284
247
285
if [ $? != 0 ]; then
248
286
echo "[ERROR] Promote to gitops repo failed. Please review logs above."
0 commit comments