From 113ed07797d26262d96ebe21b671fa0474d65dea Mon Sep 17 00:00:00 2001 From: bobjwalker Date: Thu, 11 Apr 2024 11:16:54 -0500 Subject: [PATCH] Creating a basic helm chart for this application, updating the build workflow to leverage semver --- .github/workflows/build.yml | 8 +-- k8s/charts/chart.yaml | 16 +++++ .../templates/randomquotes-deployment.yaml | 64 +++++++++++++++++++ .../templates/randomquotes-secrets.yaml | 7 ++ k8s/charts/values.yaml | 4 ++ 5 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 k8s/charts/chart.yaml create mode 100644 k8s/charts/templates/randomquotes-deployment.yaml create mode 100644 k8s/charts/templates/randomquotes-secrets.yaml create mode 100644 k8s/charts/values.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 898aaa2..79c57a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,7 +36,7 @@ jobs: - name: update tag uses: richardsimko/update-tag@v1 with: - tag_name: ${{ env.GitVersion_MajorMinorPatch }}.${{ env.GitVersion_PreReleaseNumber || env.GitVersion_PreReleaseTag || github.run_number }}${{ env.GitVersion_PreReleaseLabelWithDash }} + tag_name: ${{ env.GitVersion_SemVer }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} if: github.ref == 'refs/heads/main' @@ -54,11 +54,11 @@ jobs: - name: build and push website container working-directory: src run: | - docker buildx build --push --platform linux/amd64,linux/arm64 -f "./RandomQuotes.Web/Dockerfile" --build-arg APP_VERSION=${{ env.GitVersion_MajorMinorPatch }}.${{ env.GitVersion_PreReleaseNumber || env.GitVersion_PreReleaseTag || github.run_number }} --tag bobjwalker99/randomquotes-k8s:${{ env.GitVersion_MajorMinorPatch }}.${{ env.GitVersion_PreReleaseNumber || env.GitVersion_PreReleaseTag || github.run_number }} --tag bobjwalker99/randomquotes-k8s:latest . + docker buildx build --push --platform linux/amd64,linux/arm64 -f "./RandomQuotes.Web/Dockerfile" --build-arg APP_VERSION=${{ env.GitVersion_SemVer }} --tag bobjwalker99/randomquotes-k8s:${{ env.GitVersion_SemVer }} --tag bobjwalker99/randomquotes-k8s:latest . - name: update kustomize overlay uses: mikefarah/yq@master with: - cmd: yq -i '.images.[0].newTag = "${{ env.GitVersion_MajorMinorPatch }}.${{ env.GitVersion_PreReleaseNumber || env.GitVersion_PreReleaseTag || github.run_number }}"' 'k8s/overlays/${{ github.ref == 'refs/heads/main' && 'test' || 'dev' }}/kustomization.yaml' + cmd: yq -i '.images.[0].newTag = "${{ env.GitVersion_SemVer }}"' 'k8s/overlays/${{ github.ref == 'refs/heads/main' && 'test' || 'dev' }}/kustomization.yaml' - id: commit_kustomize_change name: commit kustomize change run : | @@ -67,7 +67,7 @@ jobs: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY git checkout "${GITHUB_REF:11}" git stage 'k8s/overlays/${{ github.ref == 'refs/heads/main' && 'test' || 'dev' }}/kustomization.yaml' - git commit -am "[promotion:demo] Updating ${{ github.ref == 'refs/heads/main' && 'test' || 'dev' }} to ${{ env.GitVersion_MajorMinorPatch }}.${{ env.GitVersion_PreReleaseNumber || env.GitVersion_PreReleaseTag || github.run_number }}" + git commit -am "[promotion:demo] Updating ${{ github.ref == 'refs/heads/main' && 'test' || 'dev' }} to ${{ env.GitVersion_SemVer }}" git push --set-upstream origin ${GITHUB_REF:11} echo "The current branch is ${{ github.ref }}" diff --git a/k8s/charts/chart.yaml b/k8s/charts/chart.yaml new file mode 100644 index 0000000..23143b4 --- /dev/null +++ b/k8s/charts/chart.yaml @@ -0,0 +1,16 @@ +apiVersion: v2 +name: bobjwalker-randomquotesk8s # The chart name is also used as the repository name when publishing +description: A simple .NET application used to learn Kubernetes deployments + +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.88 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "0.1.88" \ No newline at end of file diff --git a/k8s/charts/templates/randomquotes-deployment.yaml b/k8s/charts/templates/randomquotes-deployment.yaml new file mode 100644 index 0000000..426228c --- /dev/null +++ b/k8s/charts/templates/randomquotes-deployment.yaml @@ -0,0 +1,64 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: randomquotes-deployment +spec: + replicas: 1 + selector: + matchLabels: + component: randomquotes-web + template: + metadata: + labels: + component: randomquotes-web + spec: + containers: + - name: randomquotes-web + image: octopussamples/randomquotes-k8s:{{ default .Chart.AppVersion .Values.randomquotes.image.tag }} + resources: + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "128Mi" + cpu: "500m" + imagePullPolicy: "Always" + ports: + - containerPort: 5000 + name: http-port + env: + - name: RANDOM_SECRET_PHRASE + valueFrom: + secretKeyRef: + name: random-quotes-secrets + key: homepageDisplay +--- +apiVersion: v1 +kind: Service +metadata: + name: randomquotes-app-cluster-ip-service +spec: + type: ClusterIP + selector: + component: randomquotes-web + ports: + - port: 6801 + targetPort: 8080 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: randomquotes-ingress-nginx +spec: + ingressClassName: nginx + rules: + - host: randomquotes.local + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: randomquotes-app-cluster-ip-service + port: + number: 6801 \ No newline at end of file diff --git a/k8s/charts/templates/randomquotes-secrets.yaml b/k8s/charts/templates/randomquotes-secrets.yaml new file mode 100644 index 0000000..af7c323 --- /dev/null +++ b/k8s/charts/templates/randomquotes-secrets.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: Secret +metadata: + name: random-quotes-secrets +type: Opaque +stringData: + homepageDisplay: {{ .Values.randomquotes.homepageDisplaySecret }} \ No newline at end of file diff --git a/k8s/charts/values.yaml b/k8s/charts/values.yaml new file mode 100644 index 0000000..46971d8 --- /dev/null +++ b/k8s/charts/values.yaml @@ -0,0 +1,4 @@ +randomquotes: + homepageDisplaySecret: "blah" + image: + tag: "0.1.88" \ No newline at end of file