From 946aa2592ed5f41628a41dc1dd95c25f2ada40e6 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 28 Oct 2024 14:18:03 +0100 Subject: [PATCH 01/16] build(HMS-4895): add unit-test execution Add the unit tests execution for the tekton pipeline. https://issues.redhat.com/browse/HMS-4895 Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 51 +++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index 9cfe1d9a..709fec48 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -230,6 +230,55 @@ spec: workspace: git-auth - name: netrc workspace: netrc + - name: run-unit-tests + description: Execute the unit tests for idmsvc-backend + params: + - name: SOURCE_ARTIFACT + value: $(tasks.prefetch-dependencies.results.SOURCE_ARTIFACT) + runAfter: + - prefetch-dependencies + workspaces: + - name: git-basic-auth + workspace: git-auth + - name: source + workspace: workspace + taskSpec: + params: + - description: The Trusted Artifact URI pointing to the artifact with the application source code. + name: SOURCE_ARTIFACT + type: string + volumes: + # New volume to store a copy of the source code accessible only to this Task. + - name: workdir + emptyDir: {} + stepTemplates: + volumeMounts: + - name: workdir + mountPath: /var/workdir + readOnly: false + steps: + - name: use-trusted-artifact + image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:81c4864dae6bb11595f657be887e205262e70086a05ed16ada827fd6391926ac + args: + - use + - $(params.SOURCE_ARTIFACT)=/var/workdir + - name: unit-tests + image: registry.access.redhat.com/ubi9/go-toolset:1.21.11-9.1726696856@sha256:2fead14be2734020f98c731fef30cc54e99fe889a53cac97e80f6f043778b567 + workingDir: /var/workdir + computeResources: + requests: + memory: 7Gi + cpu: 1000m + limits: + memory: 14Gi + cpu: 2000m + # securityContext: + # runAsUser: 0 + scripts: | + #!/bin/bash + set -ex + + make test-unit - name: build-images matrix: params: @@ -263,7 +312,7 @@ spec: - name: IMAGE_APPEND_PLATFORM value: "true" runAfter: - - prefetch-dependencies + - run-unit-tests taskRef: params: - name: name From 7db038bdb12e58f9c0129a250dd172addc257e5c Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Thu, 12 Dec 2024 11:05:21 +0100 Subject: [PATCH 02/16] fixup fix: typo 'scripts' > 'script' Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index 709fec48..74bd539d 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -274,7 +274,7 @@ spec: cpu: 2000m # securityContext: # runAsUser: 0 - scripts: | + script: | #!/bin/bash set -ex From 47352e3f3576898450891eb24ad86b48de8f3d3f Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Thu, 12 Dec 2024 11:19:55 +0100 Subject: [PATCH 03/16] fixup check script block Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index 74bd539d..7d40cc99 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -278,6 +278,10 @@ spec: #!/bin/bash set -ex + ls -1 + + cp -vf configs/config.example.yml configs/config.yml + make test-unit - name: build-images matrix: From c758544ebcd76b0b286beb7c75aa4d0863617b80 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Thu, 12 Dec 2024 11:36:46 +0100 Subject: [PATCH 04/16] fixup check script block Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index 7d40cc99..b4760b96 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -278,9 +278,11 @@ spec: #!/bin/bash set -ex + pwd + ls -1 - cp -vf configs/config.example.yml configs/config.yml + cp -vf configs/config.example.yaml configs/config.yaml make test-unit - name: build-images From dc067d80b8d6df66b41ecdedca2dbd64c65f3b6a Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Thu, 12 Dec 2024 22:21:30 +0100 Subject: [PATCH 05/16] fixup check basic environment state Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index b4760b96..ae482637 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -278,9 +278,9 @@ spec: #!/bin/bash set -ex - pwd + pwd >&2 - ls -1 + ls -1 >&2 cp -vf configs/config.example.yaml configs/config.yaml From d0a0fc60d99b7dfa96c9453d012090146b3845ef Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Thu, 12 Dec 2024 22:28:05 +0100 Subject: [PATCH 06/16] fixup fix: comment workdir workspace Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index ae482637..d61e53f7 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -240,22 +240,22 @@ spec: workspaces: - name: git-basic-auth workspace: git-auth - - name: source - workspace: workspace + # - name: source + # workspace: workspace taskSpec: params: - description: The Trusted Artifact URI pointing to the artifact with the application source code. name: SOURCE_ARTIFACT type: string - volumes: - # New volume to store a copy of the source code accessible only to this Task. - - name: workdir - emptyDir: {} - stepTemplates: - volumeMounts: - - name: workdir - mountPath: /var/workdir - readOnly: false + # volumes: + # # New volume to store a copy of the source code accessible only to this Task. + # - name: workdir + # emptyDir: {} + # stepTemplates: + # volumeMounts: + # - name: workdir + # mountPath: /var/workdir + # readOnly: false steps: - name: use-trusted-artifact image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:81c4864dae6bb11595f657be887e205262e70086a05ed16ada827fd6391926ac From 7dc7f7adab4b6f6c398c1d3b35a817e11b712585 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 16 Dec 2024 14:56:01 +0100 Subject: [PATCH 07/16] fixup fix: make source available Following the steps below to make available the repository when running the unit tests. https://github.com/konflux-ci/docs/blob/main/docs/modules/ROOT/pages/advanced-how-tos/using-trusted-artifacts.adoc Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index d61e53f7..e72a7116 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -247,10 +247,10 @@ spec: - description: The Trusted Artifact URI pointing to the artifact with the application source code. name: SOURCE_ARTIFACT type: string - # volumes: - # # New volume to store a copy of the source code accessible only to this Task. - # - name: workdir - # emptyDir: {} + volumes: + # New volume to store a copy of the source code accessible only to this Task. + - name: workdir + emptyDir: {} # stepTemplates: # volumeMounts: # - name: workdir @@ -261,10 +261,10 @@ spec: image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:81c4864dae6bb11595f657be887e205262e70086a05ed16ada827fd6391926ac args: - use - - $(params.SOURCE_ARTIFACT)=/var/workdir + - $(params.SOURCE_ARTIFACT)=/var/workdir/source - name: unit-tests image: registry.access.redhat.com/ubi9/go-toolset:1.21.11-9.1726696856@sha256:2fead14be2734020f98c731fef30cc54e99fe889a53cac97e80f6f043778b567 - workingDir: /var/workdir + workingDir: /var/workdir/source computeResources: requests: memory: 7Gi From 4cf87ccff8164e649c2e3143d991d45c04df360c Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 16 Dec 2024 16:36:07 +0100 Subject: [PATCH 08/16] fixup fix: add missed stepTemplates section Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index e72a7116..24ac83c8 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -251,11 +251,11 @@ spec: # New volume to store a copy of the source code accessible only to this Task. - name: workdir emptyDir: {} - # stepTemplates: - # volumeMounts: - # - name: workdir - # mountPath: /var/workdir - # readOnly: false + stepTemplates: + volumeMounts: + - name: workdir + mountPath: /var/workdir + readOnly: false steps: - name: use-trusted-artifact image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:81c4864dae6bb11595f657be887e205262e70086a05ed16ada827fd6391926ac From c66ec0d07f6f825038440e234cacf2012628ffc0 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 16 Dec 2024 16:39:09 +0100 Subject: [PATCH 09/16] fixup fix: mount path Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index 24ac83c8..9eea992a 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -247,10 +247,6 @@ spec: - description: The Trusted Artifact URI pointing to the artifact with the application source code. name: SOURCE_ARTIFACT type: string - volumes: - # New volume to store a copy of the source code accessible only to this Task. - - name: workdir - emptyDir: {} stepTemplates: volumeMounts: - name: workdir @@ -261,10 +257,10 @@ spec: image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:81c4864dae6bb11595f657be887e205262e70086a05ed16ada827fd6391926ac args: - use - - $(params.SOURCE_ARTIFACT)=/var/workdir/source + - $(params.SOURCE_ARTIFACT)=/var/workdir - name: unit-tests image: registry.access.redhat.com/ubi9/go-toolset:1.21.11-9.1726696856@sha256:2fead14be2734020f98c731fef30cc54e99fe889a53cac97e80f6f043778b567 - workingDir: /var/workdir/source + workingDir: /var/workdir computeResources: requests: memory: 7Gi @@ -285,6 +281,10 @@ spec: cp -vf configs/config.example.yaml configs/config.yaml make test-unit + volumes: + # New volume to store a copy of the source code accessible only to this Task. + - name: workdir + emptyDir: {} - name: build-images matrix: params: From 36f977d243a03025cd4e3fe6dbefcfb3070e6416 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 16 Dec 2024 16:45:44 +0100 Subject: [PATCH 10/16] fixup fix: typo 'stepTemplates' > 'stepTemplate' Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index 9eea992a..ecada911 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -247,7 +247,7 @@ spec: - description: The Trusted Artifact URI pointing to the artifact with the application source code. name: SOURCE_ARTIFACT type: string - stepTemplates: + stepTemplate: volumeMounts: - name: workdir mountPath: /var/workdir From 05b0f097516f5ef1f49340095a31da71a8af6660 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 16 Dec 2024 16:48:47 +0100 Subject: [PATCH 11/16] fixup fix: restore paths as doc indicate Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index ecada911..c442165b 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -257,10 +257,10 @@ spec: image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:81c4864dae6bb11595f657be887e205262e70086a05ed16ada827fd6391926ac args: - use - - $(params.SOURCE_ARTIFACT)=/var/workdir + - $(params.SOURCE_ARTIFACT)=/var/workdir/source - name: unit-tests image: registry.access.redhat.com/ubi9/go-toolset:1.21.11-9.1726696856@sha256:2fead14be2734020f98c731fef30cc54e99fe889a53cac97e80f6f043778b567 - workingDir: /var/workdir + workingDir: /var/workdir/source computeResources: requests: memory: 7Gi From b3ad44e7bb730d931ea2f93994d99ff58a248128 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 16 Dec 2024 16:56:10 +0100 Subject: [PATCH 12/16] fixup fix: just run the test-unit rule Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index c442165b..ad3108ed 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -274,11 +274,11 @@ spec: #!/bin/bash set -ex - pwd >&2 + # pwd >&2 - ls -1 >&2 + # ls -1 >&2 - cp -vf configs/config.example.yaml configs/config.yaml + # cp -vf configs/config.example.yaml configs/config.yaml make test-unit volumes: From 410e9ee6f8a1a2fe349fdef723eda49ca666e859 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Mon, 16 Dec 2024 17:00:25 +0100 Subject: [PATCH 13/16] fixup fix: update go-toolset image Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index ad3108ed..d5c6ff6a 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -259,7 +259,7 @@ spec: - use - $(params.SOURCE_ARTIFACT)=/var/workdir/source - name: unit-tests - image: registry.access.redhat.com/ubi9/go-toolset:1.21.11-9.1726696856@sha256:2fead14be2734020f98c731fef30cc54e99fe889a53cac97e80f6f043778b567 + image: registry.access.redhat.com/ubi9/go-toolset:1.22.7-1733160835@sha256:c9c0129bff8e94b9e23e9e4a1ebb5b932cccc24e064940a792bdc002da512d2a workingDir: /var/workdir/source computeResources: requests: From eada77c6591bd5a018e1f2717b17186ba072b948 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Thu, 19 Dec 2024 12:11:58 +0100 Subject: [PATCH 14/16] fixup fix: add a volume for the configs Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index d5c6ff6a..15c98e4a 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -240,6 +240,8 @@ spec: workspaces: - name: git-basic-auth workspace: git-auth + - name: configs + workspace: configs # - name: source # workspace: workspace taskSpec: @@ -252,6 +254,9 @@ spec: - name: workdir mountPath: /var/workdir readOnly: false + - name: configs + mountPath: /tmp/configs + readOnly: false steps: - name: use-trusted-artifact image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:81c4864dae6bb11595f657be887e205262e70086a05ed16ada827fd6391926ac @@ -278,13 +283,15 @@ spec: # ls -1 >&2 - # cp -vf configs/config.example.yaml configs/config.yaml + cp -vf configs/config.example.yaml /tmp/configs/config.yaml make test-unit volumes: # New volume to store a copy of the source code accessible only to this Task. - name: workdir emptyDir: {} + - name: configs + emptyDir: {} - name: build-images matrix: params: From 36227abe6e143010a34a43fc94f0054a1d5a48c1 Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Thu, 19 Dec 2024 12:28:37 +0100 Subject: [PATCH 15/16] fixup add volumeClaimTemplate for configs Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index 15c98e4a..14ab8e34 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -588,6 +588,16 @@ spec: requests: storage: 1Gi status: {} + - name: configs + volumeClaimTemplate: + metadata: + creationTimestamp: null + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Mi - name: git-auth secret: secretName: '{{ git_auth_secret }}' From ded9025a2f74b0324635921543933d7ed77b2e8c Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Thu, 19 Dec 2024 16:33:28 +0100 Subject: [PATCH 16/16] fixup fix: uncomment securityContext and add CONFIG_PATH Signed-off-by: Alejandro Visiedo --- .tekton/idmsvc-backend-pull-request.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.tekton/idmsvc-backend-pull-request.yaml b/.tekton/idmsvc-backend-pull-request.yaml index 14ab8e34..72dfc7e9 100644 --- a/.tekton/idmsvc-backend-pull-request.yaml +++ b/.tekton/idmsvc-backend-pull-request.yaml @@ -273,16 +273,16 @@ spec: limits: memory: 14Gi cpu: 2000m - # securityContext: - # runAsUser: 0 + securityContext: + runAsUser: 0 script: | #!/bin/bash set -ex # pwd >&2 - # ls -1 >&2 + export CONFIG_PATH="/tmp/configs" cp -vf configs/config.example.yaml /tmp/configs/config.yaml make test-unit