diff --git a/.vscode/launch.json b/.vscode/launch.json index 9717ad7..93d70a9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "mode": "auto", "program": "main.go", - "args": ["argocd", "./testdata/argocd/", "--output-dir=out/"] + "args": ["argocd", "./testdata/argocd/", "--repoServer=localhost:8081", "--output-dir=out/"] }, { "name": "Kustomize build", @@ -19,7 +19,7 @@ "mode": "auto", "program": "main.go", "args": ["kustomize", "build", "./testdata/kustomize/source", "--output-dir=out/"] - }, + }, { "name": "Kustomize diff", "type": "go", diff --git a/Readme.md b/Readme.md index 9b84ac5..a1d6d2e 100644 --- a/Readme.md +++ b/Readme.md @@ -5,6 +5,8 @@ Inspired from Kostis Kapelonis (Codefresh.io) talk at the KubeCon about [How to ## How it works +[Checkout the examples](doc/) +### Kustomize example 1. Create a new branch and commit your changes in your Kustomize deployment ![GitHub Diff](doc/img/github-diff.png) @@ -12,6 +14,15 @@ Inspired from Kostis Kapelonis (Codefresh.io) talk at the KubeCon about [How to 3. Check the auto generated comment in your Pull request and review the changes ![GitHub Diff](doc/img/goff-diff.png) +### ArgoCD Application + +1. Create a new branch and commit your changes in your ArgoCd Application + ![GitHub Diff](doc/img/github-argo-diff.png) +2. Run your pipeline, Goff renders the Appication into manifests calculate the diff between the source and target branch. +3. Check the auto generated comment in your Pull request and review the changes + ![GitHub Diff](doc/img/goff-argo-diff.png) + + ## Usage diff --git a/ci/main.go b/ci/main.go index b27f92e..7ba3e07 100644 --- a/ci/main.go +++ b/ci/main.go @@ -42,7 +42,7 @@ func main() { goffBin := golang.File("/app/goff") glabBin := golang.File("/go/bin/glab") - goofContainer := daggerClient.Container().From("registry.puzzle.ch/cicd/alpine-base"). + goffContainer := daggerClient.Container().From("registry.puzzle.ch/cicd/alpine-base"). WithFile("/bin/goff", goffBin). WithFile("/bin/glab", glabBin). WithEntrypoint([]string{"/bin/goff"}) @@ -54,11 +54,22 @@ func main() { panic(fmt.Errorf("Env var REGISTRY_USER not set")) } - addr, err := goofContainer.WithRegistryAuth("registry.puzzle.ch", regUser, secret).Publish(ctx, "registry.puzzle.ch/cicd/goff") + _, err = goffContainer.WithRegistryAuth("registry.puzzle.ch", regUser, secret).Publish(ctx, "registry.puzzle.ch/cicd/goff") + if err != nil { + panic(err) + } + + //Build repo server for GitHub actions becuase they don't yet support overriding the entrypoint + repoServerContainer := daggerClient.Container().From("quay.io/argoproj/argocd:latest"). + WithUser("root"). + WithExec([]string{"apt", "update"}). + WithExec([]string{"apt", "install", "netcat", "-y"}). + WithUser("argocd"). + WithEntrypoint([]string{"argocd-repo-server"}) + + _, err = repoServerContainer.WithRegistryAuth("registry.puzzle.ch", regUser, secret).Publish(ctx, "registry.puzzle.ch/cicd/argocd-repo-server") if err != nil { panic(err) } - // print ref - fmt.Println("Published at:", addr) } diff --git a/doc/github/argocd.yml b/doc/github/argocd.yml new file mode 100644 index 0000000..4e0ea1b --- /dev/null +++ b/doc/github/argocd.yml @@ -0,0 +1,48 @@ +on: + pull_request: + types: [opened, synchronize] + paths: + - "argocd/**" + +permissions: + contents: read + pull-requests: write + +name: Diff GitOps Environments + +jobs: + diff-env-argo: + # The type of runner that the job will run on + runs-on: ubuntu-latest + services: + reposerver: + image: registry.puzzle.ch/cicd/argocd-repo-server:latest + ports: + - "8081:8081" + options: >- + --health-cmd "nc -z localhost 8081" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + container: + image: registry.puzzle.ch/cicd/goff:latest + steps: + - name: Checkout PR + uses: actions/checkout@v3 + with: + path: source + - name: Checkout Target of PR + uses: actions/checkout@v3 + with: + path: target + ref: ${{ github.event.pull_request.base.ref }} + - run: | + goff argocd "./source/argocd" --repoServer="reposerver:8081" --output-dir=/tmp/source/ + goff argocd "./target/argocd" --repoServer="reposerver:8081" --output-dir=/tmp/target/ + goff diff "/tmp/source" "/tmp/target" --output-dir . + - name: comment PR + uses: machine-learning-apps/pr-comment@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + path: diff.md \ No newline at end of file diff --git a/doc/github/helm.yml b/doc/github/helm.yml index b6dd94c..5c9a29b 100644 --- a/doc/github/helm.yml +++ b/doc/github/helm.yml @@ -11,7 +11,7 @@ permissions: name: Diff GitOps Environments jobs: - diff-env: + diff-env-helm: # The type of runner that the job will run on runs-on: ubuntu-latest container: diff --git a/doc/github/kustomize.yml b/doc/github/kustomize.yml index 2433dd6..3aca114 100644 --- a/doc/github/kustomize.yml +++ b/doc/github/kustomize.yml @@ -11,7 +11,7 @@ permissions: name: Diff GitOps Environments jobs: - diff-env: + diff-env-kustomize: # The type of runner that the job will run on runs-on: ubuntu-latest container: diff --git a/doc/img/github-argo-diff.png b/doc/img/github-argo-diff.png new file mode 100644 index 0000000..e0b8412 Binary files /dev/null and b/doc/img/github-argo-diff.png differ diff --git a/doc/img/goff-argo-diff.png b/doc/img/goff-argo-diff.png new file mode 100644 index 0000000..e1dbe8a Binary files /dev/null and b/doc/img/goff-argo-diff.png differ diff --git a/doc/integrations.md b/doc/integrations.md index 55b7dad..ad54b90 100644 --- a/doc/integrations.md +++ b/doc/integrations.md @@ -7,6 +7,12 @@ We provide and support following CI Tools //TODO +## ArgoCD Applications Considerations + +Due the limitation of Github we can not override the entrypoint of a service image. +Therefore we recommend to use our argo-cd-repo server image which just overrides the entrypoint and install netcat +for the health probe. + # Gitlab //TODO diff --git a/testdata/argocd/helm_app.yaml b/testdata/argocd/helm_app.yaml index 8a0bac9..d9bfce0 100644 --- a/testdata/argocd/helm_app.yaml +++ b/testdata/argocd/helm_app.yaml @@ -4,17 +4,17 @@ metadata: name: goff-test namespace: openshift-gitops spec: - project: default destination: - server: https://kubernetes.default.svc namespace: pitc-cschlatter + server: 'https://kubernetes.default.svc' + project: default sources: - - repoURL: 'https://charts.bitnami.com/bitnami' - chart: redis - targetRevision: 17.10.1 - helm: - valueFiles: - - $values/argocd/helm/redis.yaml - - repoURL: 'https://github.com/schlapzz/goff-examples.git' - targetRevision: main - ref: values \ No newline at end of file + - chart: redis + helm: + valueFiles: + - $values/argocd/redis.yaml + repoURL: 'https://charts.bitnami.com/bitnami' + targetRevision: 16.11.2 + - ref: values + repoURL: 'https://github.com/schlapzz/goff-github.git' + targetRevision: v1.2.7 \ No newline at end of file