From 48aebc92900ed023d34d054d9e4aef434a1b7265 Mon Sep 17 00:00:00 2001 From: cisc0f Date: Tue, 30 Apr 2024 16:28:55 -0400 Subject: [PATCH 1/3] CD Pipeline Deploy Completed --- .tekton/events/event_listener.yaml | 8 +++++++ .tekton/events/trigger.yaml | 10 +++++++++ .tekton/events/trigger_binding.yaml | 12 ++++++++++ .tekton/events/trigger_template.yaml | 33 ++++++++++++++++++++++++++++ .tekton/pipeline.yaml | 20 ++++++++++++++--- k8s/deployment.yaml | 10 ++++----- k8s/ingress.yaml | 4 ++-- k8s/service.yaml | 4 ++-- 8 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 .tekton/events/event_listener.yaml create mode 100644 .tekton/events/trigger.yaml create mode 100644 .tekton/events/trigger_binding.yaml create mode 100644 .tekton/events/trigger_template.yaml diff --git a/.tekton/events/event_listener.yaml b/.tekton/events/event_listener.yaml new file mode 100644 index 0000000..e26b31a --- /dev/null +++ b/.tekton/events/event_listener.yaml @@ -0,0 +1,8 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: EventListener +metadata: + name: cd-listener +spec: + serviceAccountName: pipeline + triggers: + - triggerRef: cd-trigger \ No newline at end of file diff --git a/.tekton/events/trigger.yaml b/.tekton/events/trigger.yaml new file mode 100644 index 0000000..6bb5239 --- /dev/null +++ b/.tekton/events/trigger.yaml @@ -0,0 +1,10 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: Trigger +metadata: + name: cd-trigger +spec: + serviceAccountName: pipeline + bindings: + - ref: cd-binding + template: + ref: cd-template \ No newline at end of file diff --git a/.tekton/events/trigger_binding.yaml b/.tekton/events/trigger_binding.yaml new file mode 100644 index 0000000..bc91f79 --- /dev/null +++ b/.tekton/events/trigger_binding.yaml @@ -0,0 +1,12 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerBinding +metadata: + name: cd-binding +spec: + params: + - name: git-repo-url + value: $(body.repository.url) + - name: git-repo-name + value: $(body.repository.name) + - name: git-revision + value: $(body.head_commit.id) \ No newline at end of file diff --git a/.tekton/events/trigger_template.yaml b/.tekton/events/trigger_template.yaml new file mode 100644 index 0000000..81fabb7 --- /dev/null +++ b/.tekton/events/trigger_template.yaml @@ -0,0 +1,33 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerTemplate +metadata: + name: cd-template +spec: + params: + - name: git-repo-url + description: The git repository url + - name: git-revision + description: The git revision + - name: git-repo-name + description: The name of the deployment to be created / patched + + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + generateName: cd-pipeline-$(tt.params.git-repo-name)- + spec: + serviceAccountName: pipeline + pipelineRef: + name: cd-pipeline + params: + - name: APP_NAME + value: $(tt.params.git-repo-name) + - name: GIT_REPO + value: $(tt.params.git-repo-url) + - name: IMAGE_NAME + value: image-registry.openshift-image-registry.svc:5000/$(context.pipelineRun.namespace)/$(tt.params.git-repo-name):$(tt.params.git-revision) + workspaces: + - name: pipeline-workspace + persistentVolumeClaim: + claimName: pipeline-pvc \ No newline at end of file diff --git a/.tekton/pipeline.yaml b/.tekton/pipeline.yaml index eae686b..5c980fd 100644 --- a/.tekton/pipeline.yaml +++ b/.tekton/pipeline.yaml @@ -5,7 +5,7 @@ metadata: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"tekton.dev/v1","kind":"Pipeline","metadata":{"annotations":{},"creationTimestamp":"2024-04-29T03:49:01Z","generation":1,"managedFields":[{"apiVersion":"tekton.dev/v1","fieldsType":"FieldsV1","fieldsV1":{"f:spec":{".":{},"f:finally":{},"f:params":{},"f:tasks":{},"f:workspaces":{}}},"manager":"Mozilla","operation":"Update","time":"2024-04-29T03:49:01Z"}],"name":"cd-pipeline","namespace":"fc2475-dev","resourceVersion":"2172270571","uid":"e709a048-1dae-4884-a299-2aa74065fe01"},"spec":{"params":[{"description":"The url of the github repo","name":"GIT_REPO","type":"string"},{"default":"master","description":"The reference (branch)","name":"GIT_REF","type":"string"}],"tasks":[{"name":"git-clone","params":[{"name":"url","value":"$(params.GIT_REPO)"},{"name":"revision","value":"$(params.GIT_REF)"},{"name":"refspec","value":""},{"name":"submodules","value":"true"},{"name":"depth","value":"1"},{"name":"sslVerify","value":"true"},{"name":"crtFileName","value":"ca-bundle.crt"},{"name":"subdirectory","value":""},{"name":"sparseCheckoutDirectories","value":""},{"name":"deleteExisting","value":"true"},{"name":"httpProxy","value":""},{"name":"httpsProxy","value":""},{"name":"noProxy","value":""},{"name":"verbose","value":"true"},{"name":"gitInitImage","value":"registry.redhat.io/openshift-pipelines/pipelines-git-init-rhel8@sha256:66f219b4d54a41b945cb5715ecd1fbb5d25431cf8dad4b06914a4cdc65b298cc"},{"name":"userHome","value":"/home/git"}],"taskRef":{"kind":"ClusterTask","name":"git-clone"},"workspaces":[{"name":"output","workspace":"pipeline-workspace"}]}],"workspaces":[{"name":"pipeline-workspace"}]}} creationTimestamp: '2024-04-30T13:59:46Z' - generation: 4 + generation: 5 managedFields: - apiVersion: tekton.dev/v1 fieldsType: FieldsV1 @@ -28,10 +28,10 @@ metadata: 'f:workspaces': {} manager: Mozilla operation: Update - time: '2024-04-30T14:55:14Z' + time: '2024-04-30T19:01:51Z' name: cd-pipeline namespace: fc2475-dev - resourceVersion: '2177835671' + resourceVersion: '2178509890' uid: cfaeba82-1736-4204-868e-171d093fa9d5 spec: params: @@ -156,5 +156,19 @@ spec: workspaces: - name: source workspace: pipeline-workspace + - name: deploy-image + params: + - name: image_name + value: $(params.IMAGE_NAME) + - name: manifest_dir + value: k8s + runAfter: + - buildah + taskRef: + kind: Task + name: deploy-image + workspaces: + - name: source + workspace: pipeline-workspace workspaces: - name: pipeline-workspace diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index b6fe348..69790f9 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -1,9 +1,9 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: shopcart + name: shopcarts labels: - app: shopcart + app: shopcarts spec: replicas: 2 strategy: @@ -13,17 +13,17 @@ spec: maxUnavailable: 50% selector: matchLabels: - app: shopcart + app: shopcarts template: metadata: labels: - app: shopcart + app: shopcarts spec: imagePullSecrets: - name: all-icr-io restartPolicy: Always containers: - - name: shopcart + - name: shopcarts image: cluster-registry:32000/shopcarts:latest #image: shopcart imagePullPolicy: IfNotPresent diff --git a/k8s/ingress.yaml b/k8s/ingress.yaml index ad409cf..a069e98 100644 --- a/k8s/ingress.yaml +++ b/k8s/ingress.yaml @@ -2,7 +2,7 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: shopcart + name: shopcarts annotations: nginx.ingress.kubernetes.io/rewrite-target: / spec: @@ -13,6 +13,6 @@ spec: pathType: Prefix backend: service: - name: shopcart + name: shopcarts port: number: 8080 diff --git a/k8s/service.yaml b/k8s/service.yaml index 56d7576..6960599 100644 --- a/k8s/service.yaml +++ b/k8s/service.yaml @@ -1,10 +1,10 @@ apiVersion: v1 kind: Service metadata: - name: shopcart + name: shopcarts spec: selector: - app: shopcart + app: shopcarts type: ClusterIP internalTrafficPolicy: Local ports: From 5054d8472e761f8d9b09ca746071ac021b4c13ca Mon Sep 17 00:00:00 2001 From: cisc0f Date: Tue, 30 Apr 2024 16:33:40 -0400 Subject: [PATCH 2/3] Update test bug --- tests/test_routes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_routes.py b/tests/test_routes.py index dc547ec..37278ca 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -181,8 +181,8 @@ def test_update_shopcart(self): "user_id" ], # Assuming user_id can be updated or is needed for identification "name": "Updated Name", - "total_price": new_shopcart["total_price"] - + 100, # Example of updating the price + "total_price": float(new_shopcart["total_price"]) + + float(100), # Example of updating the price # Include updates to other fields here "status": new_shopcart["status"], } From 1afaf56a1b46bc3ee3e6876a14b54571ef78bdac Mon Sep 17 00:00:00 2001 From: cisc0f Date: Tue, 30 Apr 2024 16:37:10 -0400 Subject: [PATCH 3/3] Fix bug --- tests/test_routes.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_routes.py b/tests/test_routes.py index 37278ca..f9b1504 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -181,8 +181,8 @@ def test_update_shopcart(self): "user_id" ], # Assuming user_id can be updated or is needed for identification "name": "Updated Name", - "total_price": float(new_shopcart["total_price"]) - + float(100), # Example of updating the price + "total_price": new_shopcart["total_price"] + + 100, # Example of updating the price # Include updates to other fields here "status": new_shopcart["status"], } @@ -197,7 +197,8 @@ def test_update_shopcart(self): # Verify that all fields have been updated correctly self.assertEqual(updated_shopcart["name"], update_payload["name"]) self.assertEqual( - updated_shopcart["total_price"], float(update_payload["total_price"]) + round(updated_shopcart["total_price"], 2), + round(float(update_payload["total_price"]), 2), ) def test_update_shop_cart_with_invalid_fields(self):