Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Commit 7ed373f

Browse files
authored
Merge pull request #381 from kabanero-io/rc5
Cleanup
2 parents 5462b6d + a29eda4 commit 7ed373f

14 files changed

+187
-156
lines changed

pipelines/experimental/gitops/build-push-promote-task.yaml

Lines changed: 87 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
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+
#
112
apiVersion: tekton.dev/v1beta1
213
kind: Task
314
metadata:
@@ -19,6 +30,8 @@ spec:
1930
type: string
2031
steps:
2132
- 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.
2235
securityContext:
2336
privileged: true
2437
image: kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
@@ -32,52 +45,71 @@ spec:
3245
value: git-source
3346
volumeMounts:
3447
- mountPath: /var/lib/containers
35-
name: varlibcontainers
48+
name: varlibcontainers
3649
- name: build
50+
# This steps builds the source project using appsody build.
3751
securityContext:
3852
privileged: true
3953
image: kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
54+
imagePullPolicy: Always
4055
command: ["/bin/bash"]
4156
args:
4257
- -c
4358
- |
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
5268
fi
69+
echo "[INFO] Completed setup for image registry access."
5370
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
5879
fi
5980
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.
6085
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) )
6186
retVal=$?
6287
if [ $retVal -ne 0 ]
6388
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
6590
exit $retVal
6691
fi
6792
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"
6994
95+
# Kickoff appsody build
7096
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."
74104
env:
75105
- name: gitsource
76106
value: git-source
77107
volumeMounts:
78108
- mountPath: /var/lib/containers
79109
name: varlibcontainers
80110
- 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.
81113
securityContext:
82114
privileged: true
83115
image: kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
@@ -86,66 +118,71 @@ spec:
86118
- -c
87119
- |
88120
/scripts/enforce_stack_policy.sh post-build
121+
89122
env:
90123
- name: gitsource
91124
value: git-source
92125
volumeMounts:
93126
- mountPath: /var/lib/containers
94-
name: varlibcontainers
127+
name: varlibcontainers
95128
- name: push
129+
# Push the image built in the build step to the specified image registry. Optionally sign the image.
96130
securityContext:
97131
privileged: true
98132
image: kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
99133
command: ["/bin/bash"]
100134
args:
101135
- -c
102136
- |
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.
104139
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) )
105140
retVal=$?
106141
if [ $retVal -ne 0 ]
107142
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
109144
exit $retVal
110145
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"
112148
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
123158
fi
124159
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.
126161
if [ -f "/image-signing-config/registry" ]; then
127-
REPO=`cat /image-signing-config/registry`
162+
REPO=`cat /image-signing-config/registry`
128163
fi
129164
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..."
131167
buildah push "$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" "docker://$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
132168
else
133-
echo "Signature will be generated."
169+
echo "[INFO] Signature will be generated."
134170
#importing RSA secret key, then extract an e-mail address from it.
135171
gpg --import /image-signing-config/secret.asc
136172
SIGNBY=`gpg --list-keys|sed -n -e "/.*<.*>.*/p"|sed -e "s/^.*<\(.*\)>.*$/\1/"`
173+
echo "[INFO] Pushing image to registry..."
137174
skopeo copy --remove-signatures --sign-by $SIGNBY "containers-storage:$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE" "docker://$OUTPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
138175
RESULT=$?
139176
if [ $RESULT -ne 0 ]; then
140-
echo "sign-image failed. exit code : $RESULT"
177+
echo "[ERROR] sign-image failed. exit code : $RESULT"
141178
exit $RESULT
142179
fi
143180
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"
145182
else
146183
#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
149186
fi
150187
fi
151188
env:
@@ -159,23 +196,24 @@ spec:
159196
- mountPath: /etc/containers/registries.d
160197
name: registries-d
161198
- mountPath: /sigstore-script
162-
name: sigstore-script
199+
name: sigstore-script
163200
- name: promote
201+
# Promote the service to the configured gitops repository using the `services promote` CLI
164202
securityContext:
165203
privileged: true
166-
image: quay.io/redhat-developer/gitops-cli:latest
204+
image: quay.io/redhat-developer/gitops-cli@sha256:f5f47bb0cf1dcd081c29e7017e4511441cab3379d06ef587ba6e539f005945dd
167205
command: ["/bin/bash"]
168206
args:
169207
- -c
170208
- |
171209
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"
177211
178212
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 " "
179217
180218
if [ -z "$GITHUB_TOKEN" ]; then
181219
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:
229267
cat $HOME/.gitconfig
230268
231269
echo " "
232-
echo "service name = $(inputs.params.git-project)"
270+
echo "[INFO] service name = $(inputs.params.git-project)"
233271
if [[ -z "$(inputs.params.git-project)" ]]; then
234272
echo "[ERROR] Unable to retrieve service name from input params. Unable to promote."
235273
exit 1
@@ -242,7 +280,7 @@ spec:
242280
fi
243281
244282
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)
246284
247285
if [ $? != 0 ]; then
248286
echo "[ERROR] Promote to gitops repo failed. Please review logs above."

pipelines/experimental/gitops/deploy-kustomize-pl.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This pipeline will call a task to deploy a service using the kustomization.yaml in the gitops repo.
12
apiVersion: tekton.dev/v1beta1
23
kind: Pipeline
34
metadata:
@@ -13,4 +14,4 @@ spec:
1314
resources:
1415
inputs:
1516
- name: git-source
16-
resource: git-source
17+
resource: git-source

pipelines/experimental/gitops/deploy-kustomize-task.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This task will deploy the service using the kustomization.yaml in the gitops repo.
12
apiVersion: tekton.dev/v1beta1
23
kind: Task
34
metadata:
@@ -14,21 +15,27 @@ spec:
1415
#!/usr/bin/env sh
1516
1617
# First check if a dryrun is successful
17-
kubectl apply -k /workspace/git-source/env --dry-run=server
18+
echo "[INFO] Starting dry run..."
19+
kubectl apply -k /workspace/git-source/environments --dry-run=server
1820
1921
if [ $? != 0 ]; then
2022
echo "[ERROR] Dry run of deployment was unsuccessful. Please review errors above for more details. Service will not be deployed."
2123
exit 1
2224
fi
2325
2426
# If it's good then run
27+
echo "[INFO] Starting deployment..."
2528
kubectl apply -k /workspace/git-source/environments
29+
if [ $? != 0 ]; then
30+
echo "[ERROR] Deployment was unsuccessful. Please review errors above for more details. Service was not deployed."
31+
exit 1
32+
fi
2633
27-
# TODO: The pipeline declares success if apply is successful. It takes a minute or so after we apply for the app pod to come up.
28-
# Maybe we should wait and try to check for status of app?.
34+
# TODO: To support newer kustomize we should be doing
35+
# kustomize build /workspace/git-source/environments | kubectl apply -k -
2936
30-
# TODO: To support newer kustomize
31-
# kustomize build /workspace/git-source/env | kubectl apply -k -
37+
# TODO: The pipeline declares success if apply is successful. It takes a minute or so after we apply for the app pod to come up.
38+
# Maybe we should wait and try to check for status of app?
3239
env:
3340
- name: gitsource
3441
value: git-source

pipelines/experimental/gitops/image-scan-task.yaml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ spec:
3737
- name: mount-image
3838
securityContext:
3939
privileged: true
40-
image: kabanero/kabanero-utils:0.9.0
40+
image: kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
4141
# Temporarily make copy of mounted image since the mounted image will be unmounted when the container for this task ends.
4242
# TODO: Determine another way to persist the mounted container image across containers
4343
command: ['/bin/bash']
4444
args:
4545
- -c
4646
- |
47+
# Docker does not support upper case characters in the image name. Github does not have this restriction.
48+
# So lowercase the image name if it has any upper case characters.
4749
INPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE=$( /scripts/imageurl_imagename_lowercase.sh -u $(inputs.resources.docker-image.url) -n $(inputs.params.docker-imagename) -t $(inputs.params.docker-imagetag) )
4850
retVal=$?
4951
if [ $retVal -ne 0 ]
@@ -53,16 +55,15 @@ spec:
5355
fi
5456
echo "INPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE=$INPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
5557
56-
#executing the insecure_registry_setup.sh script if exists, to add internal registry to insecure registry list
57-
if [ -f "/scripts/insecure_registry_setup.sh" ]; then
58-
echo "Running the script /scripts/insecure_registry_setup.sh ...."
59-
/scripts/insecure_registry_setup.sh
60-
fi
61-
62-
#executing the ca_certs_setup.sh script if exists, to add additional trusted ca certs to /etc/docker/certs.d/<hosname>/ca.crt
63-
if [ -f "/scripts/ca_certs_setup.sh" ]; then
64-
echo "Running the script /scripts/ca_certs_setup.sh ...."
65-
/scripts/ca_certs_setup.sh
58+
# Configure image registry access in the container by adding it to the insecure registry list or enabling TLS verification
59+
# by adding it to the trust store based on OpenShift cluster resource configuration.
60+
echo "[INFO] Running the script /scripts/image_registry_access_setup.sh ...."
61+
/scripts/image_registry_access_setup.sh
62+
retVal=$?
63+
if [ $retVal -ne 0 ]
64+
then
65+
echo "[ERROR] The script failed(/scripts/image_registry_access_setup.sh), and the image registry access setup was not complete, aborting the pipelinerun" >&2
66+
exit $retVal
6667
fi
6768

6869
echo "Pulling image docker://$INPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE"
@@ -90,7 +91,7 @@ spec:
9091
- name: scan-image
9192
securityContext:
9293
privileged: true
93-
image: kabanero/scanner:1.3.1
94+
image: kabanero/scanner@sha256:82b979de485fc5990d41b8b4acc2aeee2211bd26b0f03374f5657773ae4148f9
9495
command: ['/bin/bash']
9596
args:
9697
- -c
@@ -189,4 +190,4 @@ spec:
189190
hostPath:
190191
path: /var/lib
191192
- name: varlibcontainers
192-
emptyDir: {}
193+
emptyDir: {}

pipelines/experimental/sample-helper-files/gitops/gitops-map.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: v1
33
metadata:
44
name: gitops-map
55
data:
6-
gitops-repo-url: <gitops_repo_url>
6+
gitops-repository-url: <gitops_repo_url>
7+
gitops-repository-type: <gitops_repo_type: ghe, github, gitlab>
78
gitops-commit-user-name: <user_name_to_commit_using>
89
gitops-commit-user-email: <user_email_to_commit_using>

pipelines/incubator/build-deploy-task.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ spec:
146146
- mountPath: /var/lib/containers
147147
name: varlibcontainers
148148
- name: deploy-image
149-
image: kabanero/kabanero-utils:0.3.0
149+
image: kabanero/kabanero-utils@sha256:8020573657ed1b80e2b872a37719d6398ee78219296fe6180733f54425f7bd6a
150150
command: ['/bin/sh']
151-
args: ['-c', 'find /workspace/$gitsource -name ${YAMLFILE} -type f|xargs kubectl apply -f']
151+
args:
152+
- -c
153+
- |
154+
kubectl apply -f /workspace/$gitsource/${YAMLFILE}
152155
env:
153156
- name: gitsource
154157
value: git-source

0 commit comments

Comments
 (0)