Search code examples
automated-testsgithub-actionsargocd

How to run application E2E test after argocd deployment?


I would like to know how can we run application E2E(UI or API) test after successful deployment of any micro services using ArgoCD.

Current Setup: I have CI pipeline setup with github-actions. Upon completion on CI build for any microservices, it updates the docker image version in helm values which resides in one of the github repo. This repo is than polled by ArgoCD for any change, and deploys in Kubernestes cluster if there is change exists.

Intent: I want to run the application E2E( UI & API ) test once argocd synced any micro-services deployment object defined in the Helm charts. But I am unsure what should be the trigger point in github actions for that. How E2E test github actions workflow will know argocd has deployed the microservices without any issue and service is ready to be consumed by the automated test.


Solution

  • Here is the full solution to the problem statement.

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: api-test-trigger
      annotations:
        argocd.argoproj.io/hook: PostSync
        argocd.argoproj.io/hook-delete-policy: HookSucceeded
    spec:
      template:
        metadata:
          labels:
            name: api-test
        spec:
          containers:
          - name: api-test
            args:
                - /bin/sh
                - -ec
                - "curl -X POST -H \"Accept: application/vnd.github.v3+json\" -H \"Authorization: token ${GITHUB_TOKEN}\" ${GITHUB_URL} -d '{\"ref\":\"main\"}'"
            env:
              - name: GITHUB_URL
                value: "https://api.github.com/repos/<your org>/<your repo>/actions/workflows/<workflow id>/dispatches"
              - name: GITHUB_TOKEN
                value: <your PAT>
            image: curlimages/curl
    

    You can create the PAT from github settings and provide the PAT as a secret.