From e297121e937050c96136f39bf842609d3f27fb58 Mon Sep 17 00:00:00 2001 From: Marcin-Ramotowski Date: Sat, 2 Aug 2025 14:52:42 +0200 Subject: [PATCH] Added second webhook to separate deploy repo --- argo-workflows/deploy-sensor.yaml | 109 ++++++++++++++++++++++++++++ argo-workflows/sensor.yaml | 2 +- argo-workflows/source.yaml | 12 ++- argo-workflows/webhook-ingress.yaml | 9 ++- 4 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 argo-workflows/deploy-sensor.yaml diff --git a/argo-workflows/deploy-sensor.yaml b/argo-workflows/deploy-sensor.yaml new file mode 100644 index 0000000..23b09fc --- /dev/null +++ b/argo-workflows/deploy-sensor.yaml @@ -0,0 +1,109 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Sensor +metadata: + name: webhook-deploy + namespace: argo-events +spec: + template: + serviceAccountName: operate-workflow-sa + dependencies: + - name: gitea-push + eventSourceName: webhook + eventName: user-microservice-deploy + triggers: + - template: + name: deploy-user-microservice + k8s: + operation: create + source: + resource: + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: deploy-user-microservice- + spec: + entrypoint: main + serviceAccountName: operate-workflow-sa + volumeClaimTemplates: + - metadata: + name: workspace + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 128Mi + templates: + - name: main + steps: + - - name: checkout + template: checkout + - - name: deploy + template: deploy + + - name: checkout + container: + image: alpine/git + command: [sh, -c] + workingDir: /workspace + env: + - name: REPO_URL + value: https://gitea.marcin00.pl/pikram/user-microservice-deploy.git + - name: REPO_BRANCH + value: argo-deploy + args: + - | + git clone --depth 1 --branch "${REPO_BRANCH}" --single-branch "${REPO_URL}" repo + volumeMounts: + - name: workspace + mountPath: /workspace + + - name: deploy + container: + image: marcin00.azurecr.io/azure-cli-kubectl:latest + command: [sh, -c] + workingDir: /workspace/repo + env: + - name: CLIENT_ID + value: "c302726f-fafb-4143-94c1-67a70975574a" + - name: CLUSTER_NAME + value: "build" + - name: RESOURCE_GROUP + value: "tst-aks-rg" + - name: DEPLOY_FILES + value: "namespace.yaml secret-store.yaml deploy.yaml ingress.yaml" + - name: DEPLOYMENT + value: "api" + - name: NAMESPACE + value: "user-microservice" + - name: HEALTHCHECK_URL + value: "https://user-microservice.marcin00.pl/health" + args: + - | + echo "===> Logging in to Azure" + az login --identity --client-id $CLIENT_ID + az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --overwrite-existing + kubelogin convert-kubeconfig -l azurecli + + echo "===> Applying Kubernetes manifests" + for file in $DEPLOY_FILES; do + kubectl apply -f "$file" + done + + echo "===> Waiting for deployment to complete" + kubectl rollout status deployment/$DEPLOYMENT -n $NAMESPACE --timeout=60s + + echo "===> Running health check" + for i in $(seq 1 120); do + if curl -sf $HEALTHCHECK_URL; then + echo "Health check OK" + exit 0 + else + echo "Health check failed. Retry $i..." + sleep 5 + fi + done + echo "Health check failed" + exit 1 + volumeMounts: + - name: workspace + mountPath: /workspace diff --git a/argo-workflows/sensor.yaml b/argo-workflows/sensor.yaml index 1e28505..a911e8c 100644 --- a/argo-workflows/sensor.yaml +++ b/argo-workflows/sensor.yaml @@ -9,7 +9,7 @@ spec: dependencies: - name: gitea-push eventSourceName: webhook - eventName: test-hook + eventName: user-microservice triggers: - template: name: trigger-build-workflow diff --git a/argo-workflows/source.yaml b/argo-workflows/source.yaml index e6f0dbd..30f7c18 100644 --- a/argo-workflows/source.yaml +++ b/argo-workflows/source.yaml @@ -1,7 +1,7 @@ apiVersion: argoproj.io/v1alpha1 kind: EventSource metadata: - name: webhook + name: webhook-build namespace: argo-events spec: service: @@ -9,7 +9,11 @@ spec: - port: 12000 targetPort: 12000 webhook: - test-hook: - endpoint: /gitea-hook + user-microservice: + endpoint: /user-microservice method: POST - port: "12000" \ No newline at end of file + port: "12000" + user-microservice-deploy: + endpoint: /user-microservice-deploy + method: POST + port: "12000" \ No newline at end of file diff --git a/argo-workflows/webhook-ingress.yaml b/argo-workflows/webhook-ingress.yaml index 64950bc..1f8052a 100644 --- a/argo-workflows/webhook-ingress.yaml +++ b/argo-workflows/webhook-ingress.yaml @@ -11,7 +11,14 @@ spec: - host: argo-hook.marcin00.pl http: paths: - - path: /gitea-hook + - path: /user-microservice + pathType: Prefix + backend: + service: + name: webhook-eventsource-svc + port: + number: 12000 + - path: /user-microservice-deploy pathType: Prefix backend: service: