commit 70ceb5bdb15e3e9567e5c735fc64c5b80e664646 Author: Jack Jackson Date: Tue Oct 25 15:45:00 2022 -0700 First commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..0757aff --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +This repo, in conjunction with the [App Code repo](https://gitea.scubbo.org/scubbo/auto-update-test-app-code), demonstrates how to use the Auto-Update Drone Plugin to trigger App deployments in a CI/CD pipeline which uses GitOps to define the App Versions in Git. + +## Demonstration + +While in the App Code repo, at commit `65866e` ([link](https://gitea.scubbo.org/scubbo/auto-update-test-app-code/commit/65866ea3b60906d60c4c7aa22b51333cb906c839)), and having already carried out a "first-pass" sync in my CD application (ArgoCD) to get components deployed: + +``` +# Make the deployed pod "call itself" - saves us from the hassle of setting up a Service +$ kubectl exec -it -n auto-update $(kubectl -n auto-update get pods -o=jsonpath='{.items[*].metadata.name}') -- curl localhost:8000 +Hello world!% +# OK, good - as expected, the Application initially responds with "Hello world!". Now let's make a change and demonstrate that it's deployed. +$ git reset --hard cffc43 +HEAD is now at cffc437 Expand project scope +$ git status +On branch main +Your branch is ahead of 'origin/main' by 1 commit. + +nothing to commit, working tree clean +$ git push +[...] +To https://gitea.scubbo.org/scubbo/auto-update-test-app-code.git + 65866ea..cffc437 main -> main +# +# Now observe: +# * the Drone pipeline results in a commit to the infra package... +# * ...which is visible in Gitea +# * Once the Argo application is synced, new Kubernetes resources are created to match the new Infrastructure definition +# +$ kubectl exec -it -n auto-update $(kubectl -n auto-update get pods -o=jsonpath='{.items[*].metadata.name}') -- curl localhost:8000 +Hello universe! +``` + + + +## Points to note +* `helm/templates/_helpers.tpl` contains the `fullImageName` definition, which in turn depends on `imageTag`, which uses [Files access](https://helm.sh/docs/chart_template_guide/accessing_files) to read the contents of `helm/deployed-images/` +* The value `targetEnv` must be set in the setup for the specific CD application which will "watch" this repo for updates. \ No newline at end of file diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 0000000..1bf9f6f --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,7 @@ +apiVersion: v2 +name: auto-update-test-infra +description: A Helm chart for Kubernetes, demonstrating auto-update functionality + +type: application +version: 0.1.0 +appVersion: "1.1.0" \ No newline at end of file diff --git a/helm/deployed-images/prod b/helm/deployed-images/prod new file mode 100644 index 0000000..f8ac620 --- /dev/null +++ b/helm/deployed-images/prod @@ -0,0 +1 @@ +9b6b005ca3 \ No newline at end of file diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl new file mode 100644 index 0000000..7a07b66 --- /dev/null +++ b/helm/templates/_helpers.tpl @@ -0,0 +1,13 @@ +{{- define "imageTag" }} +{{- $val := "" }} +{{- if and (hasKey .Values.image "tag") (.Values.image.tag) }} +{{- $val = .Values.image.tag }} +{{- else }} +{{- $val = (.Files.Get (printf "%s/%s" "deployed-images" (required "You must set targetEnv if image.tag is absent!" .Values.targetEnv))) }} +{{- end }} +{{- trim $val }} +{{- end }} + +{{- define "fullImageName" -}} +{{- printf "%s:%s" .Values.image.repository (include "imageTag" .) }} +{{- end }} \ No newline at end of file diff --git a/helm/templates/infra.yaml b/helm/templates/infra.yaml new file mode 100644 index 0000000..e2f8129 --- /dev/null +++ b/helm/templates/infra.yaml @@ -0,0 +1,16 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: auto-update-test-infra +spec: + selector: + matchLabels: + app: auto-update-test-infra + template: + metadata: + labels: + app: auto-update-test-infra + spec: + containers: + - name: auto-update-test-infra + image: {{ include "fullImageName" . }} \ No newline at end of file diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 0000000..874cb25 --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,2 @@ +image: + repository: gitea.scubbo.org/scubbo/auto-update-test-app-code \ No newline at end of file