Skip to content

Commit

Permalink
feat: Implement the on branch workflow (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaLanziani authored Jul 5, 2023
1 parent 20a057d commit 2238866
Show file tree
Hide file tree
Showing 30 changed files with 675 additions and 372 deletions.
36 changes: 0 additions & 36 deletions .github/actions/build_push/action.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/app_build.yaml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/onbranch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build on branch

on:
push:
branches-ignore:
- "main"

jobs:
cli:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ inputs.GO_VERSION }}

- name: build and deploy on pr
run: go run main.go onbranch --stop-on-push
env:
KKA_APP_NAME: k8s-kurated-addons-cli
KKA_REGISTRY_USER: ${{ github.actor }}
KKA_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
24 changes: 24 additions & 0 deletions .github/workflows/onmain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deploy on main

on:
push:
branches:
- main

jobs:
cli:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ inputs.GO_VERSION }}

- name: build and deploy on main
run: go run main.go onmain --stop-on-push
env:
KKA_APP_NAME: k8s-kurated-addons-cli
KKA_REGISTRY_USER: ${{ github.actor }}
KKA_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.env
Dockerfile.kka
*.init_test*
kka_on_main.yaml
kka_onmain.yaml
kka_onbranch.yaml
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,16 @@ You will be able to run the executable from
```bash
./bin/kka-cli
```

### Setup local environment

These are the environment variables that you have to set in order to use the onmain, onbranch commands from your local environment

```
export KKA_REGISTRY_PASSWORD="<lucalprojects_pat>"
export KKA_REGISTRY_USER="lucalprojects"
export KKA_REPO_NAME="ghcr.io/llprojects/registry"
export KKA_CLUSTER_ENDPOINT=$(kubectl config view -o jsonpath='{.clusters[?(@.name == "kind-k8s-kurated-addons")].cluster.server}')
export KKA_CLUSTER_TOKEN=$(kubectl get secrets ci-bot-token -o jsonpath="{.data.token}" | base64 -d)
export KKA_CLUSTER_CA_CERT=$(kubectl get secrets ci-bot-token -o jsonpath="{.data.ca\.crt}" | base64 -d)
```
42 changes: 42 additions & 0 deletions assets/github/onbranch.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is generate by https://github.com/nearform/k8s-kurated-addons-cli
name: Deploy on PR

on:
pull_request:
types: [opened, synchronize, reopened, closed]

jobs:
on_pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: delete application
if: github.event.type == "closed"
uses: docker://ghcr.io/nearform/k8s-kurated-addons-cli:latest
with:
args: onbranch --clean
env:
KKA_APP_NAME: {{ .AppName }}
KKA_PROJECT_DIRECTORY: {{ .ProjectDirectory }}
KKA_REPO_NAME: {{ .Repository }}
KKA_REGISTRY_USER: {{ `${{ github.actor }}` }}
KKA_REGISTRY_PASSWORD: {{ `${{ secrets.GITHUB_TOKEN }}` }}
KKA_CLUSTER_ENDPOINT: {{ `${{ secrets.CLUSTER_ENDPOINT }}` }}
KKA_CLUSTER_TOKEN: {{ `${{ secrets.CLUSTER_TOKEN }}` }}
KKA_CLUSTER_CA_CERT: {{ `${{ secrets.CLUSTER_CA_CERT }}` }}

- name: build and deploy application
if: github.event.type != "closed"
uses: docker://ghcr.io/nearform/k8s-kurated-addons-cli:latest
with:
args: onbranch
env:
KKA_APP_NAME: {{ .AppName }}
KKA_PROJECT_DIRECTORY: {{ .ProjectDirectory }}
KKA_REPO_NAME: {{ .Repository }}
KKA_REGISTRY_USER: {{ `${{ github.actor }}` }}
KKA_REGISTRY_PASSWORD: {{ `${{ secrets.GITHUB_TOKEN }}` }}
KKA_CLUSTER_ENDPOINT: {{ `${{ secrets.CLUSTER_ENDPOINT }}` }}
KKA_CLUSTER_TOKEN: {{ `${{ secrets.CLUSTER_TOKEN }}` }}
KKA_CLUSTER_CA_CERT: {{ `${{ secrets.CLUSTER_CA_CERT }}` }}
17 changes: 7 additions & 10 deletions assets/github/pipeline.tmpl → assets/github/onmain.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is generate by https://github.com/nearform/k8s-kurated-addons-cli
name: Build and Push
name: Deploy on {{ .DefaultBranch }}

on:
push:
Expand All @@ -12,19 +12,16 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: build docker image application
- name: build and deploy on {{ .DefaultBranch }}
uses: docker://ghcr.io/nearform/k8s-kurated-addons-cli:latest
with:
args: build
env:
KKA_APP_NAME: {{ .AppName }}

- name: push docker image application
uses: docker://ghcr.io/nearform/k8s-kurated-addons-cli:latest
with:
args: push
args: onmain
env:
KKA_APP_NAME: {{ .AppName }}
KKA_PROJECT_DIRECTORY: {{ .ProjectDirectory }}
KKA_REPO_NAME: {{ .Repository }}
KKA_REGISTRY_USER: {{ `${{ github.actor }}` }}
KKA_REGISTRY_PASSWORD: {{ `${{ secrets.GITHUB_TOKEN }}` }}
KKA_CLUSTER_ENDPOINT: {{ `${{ secrets.CLUSTER_ENDPOINT }}` }}
KKA_CLUSTER_TOKEN: {{ `${{ secrets.CLUSTER_TOKEN }}` }}
KKA_CLUSTER_CA_CERT: {{ `${{ secrets.CLUSTER_CA_CERT }}` }}
25 changes: 21 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/charmbracelet/log v0.2.2
github.com/docker/docker v23.0.1+incompatible
github.com/go-git/go-git/v5 v5.7.0
github.com/moby/term v0.0.0-20221205130635-1aeaba878587
github.com/urfave/cli/v2 v2.25.0
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -18,31 +19,41 @@ require (
require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containerd/containerd v1.7.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-containerregistry v0.13.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -59,26 +70,32 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/opencontainers/runc v1.1.4 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.7.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.4.0 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
Expand Down
Loading

0 comments on commit 2238866

Please sign in to comment.