Skip to content

Commit

Permalink
Merge pull request #105 from CSCI-GA-2820-SP24-003/cd-pipeline-deploy
Browse files Browse the repository at this point in the history
CD Pipeline Deploy
  • Loading branch information
cisc0f authored Apr 30, 2024
2 parents 43b8642 + 1afaf56 commit 5d77833
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .tekton/events/event_listener.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
name: cd-listener
spec:
serviceAccountName: pipeline
triggers:
- triggerRef: cd-trigger
10 changes: 10 additions & 0 deletions .tekton/events/trigger.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .tekton/events/trigger_binding.yaml
Original file line number Diff line number Diff line change
@@ -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)
33 changes: 33 additions & 0 deletions .tekton/events/trigger_template.yaml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 17 additions & 3 deletions .tekton/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
10 changes: 5 additions & 5 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: shopcart
name: shopcarts
labels:
app: shopcart
app: shopcarts
spec:
replicas: 2
strategy:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions k8s/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: shopcart
name: shopcarts
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
Expand All @@ -13,6 +13,6 @@ spec:
pathType: Prefix
backend:
service:
name: shopcart
name: shopcarts
port:
number: 8080
4 changes: 2 additions & 2 deletions k8s/service.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: shopcart
name: shopcarts
spec:
selector:
app: shopcart
app: shopcarts
type: ClusterIP
internalTrafficPolicy: Local
ports:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5d77833

Please sign in to comment.