Skip to content

Commit

Permalink
update readme and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
schlapzz committed May 13, 2023
1 parent 5357840 commit 17f362c
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -19,7 +19,7 @@
"mode": "auto",
"program": "main.go",
"args": ["kustomize", "build", "./testdata/kustomize/source", "--output-dir=out/"]
},
},
{
"name": "Kustomize diff",
"type": "go",
Expand Down
11 changes: 11 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ 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)
2. Run your pipeline, Goff renders the Base and the Overlays and 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-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

Expand Down
19 changes: 15 additions & 4 deletions ci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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)
}
48 changes: 48 additions & 0 deletions doc/github/argocd.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion doc/github/helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion doc/github/kustomize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Binary file added doc/img/github-argo-diff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/goff-argo-diff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions doc/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions testdata/argocd/helm_app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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

0 comments on commit 17f362c

Please sign in to comment.