Skip to content

Commit

Permalink
Creating a basic helm chart for this application, updating the build …
Browse files Browse the repository at this point in the history
…workflow to leverage semver
  • Loading branch information
BobJWalker committed Apr 11, 2024
1 parent d4d54fe commit 113ed07
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 : |
Expand All @@ -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 }}"
Expand Down
16 changes: 16 additions & 0 deletions k8s/charts/chart.yaml
Original file line number Diff line number Diff line change
@@ -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"
64 changes: 64 additions & 0 deletions k8s/charts/templates/randomquotes-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions k8s/charts/templates/randomquotes-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: random-quotes-secrets
type: Opaque
stringData:
homepageDisplay: {{ .Values.randomquotes.homepageDisplaySecret }}
4 changes: 4 additions & 0 deletions k8s/charts/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
randomquotes:
homepageDisplaySecret: "blah"
image:
tag: "0.1.88"

0 comments on commit 113ed07

Please sign in to comment.