Skip to content

Commit a1d5289

Browse files
authored
Merge pull request #6 from DevOpsFortress/ci/helm-chart-and-tags
ci(helm): Catalogue chart and latest tags
2 parents 72adc46 + 785aca7 commit a1d5289

18 files changed

Lines changed: 740 additions & 5 deletions

File tree

.DS_Store

2 KB
Binary file not shown.

.github/workflows/build-images.yml

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,78 @@ env:
1414
IMAGE_PREFIX: ${{ github.repository }}
1515

1616
jobs:
17+
detect-changes:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
catalogue: ${{ steps.filter.outputs.catalogue }}
21+
voting: ${{ steps.filter.outputs.voting }}
22+
recommendation: ${{ steps.filter.outputs.recommendation }}
23+
frontend: ${{ steps.filter.outputs.frontend }}
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: dorny/paths-filter@v3
27+
id: filter
28+
with:
29+
filters: |
30+
catalogue:
31+
- 'catalogue/**'
32+
voting:
33+
- 'voting/**'
34+
recommendation:
35+
- 'recommendation/**'
36+
frontend:
37+
- 'frontend/**'
38+
1739
build-images:
40+
needs: detect-changes
1841
runs-on: ubuntu-latest
1942
strategy:
2043
matrix:
21-
images-name: ["catalogue", "voting", "recommendation", "frontend"]
44+
include:
45+
- name: catalogue
46+
changed: ${{ needs.detect-changes.outputs.catalogue }}
47+
- name: voting
48+
changed: ${{ needs.detect-changes.outputs.voting }}
49+
- name: recommendation
50+
changed: ${{ needs.detect-changes.outputs.recommendation }}
51+
- name: frontend
52+
changed: ${{ needs.detect-changes.outputs.frontend }}
2253
permissions:
2354
contents: read
2455
packages: write
2556
steps:
2657
- name: Checkout
58+
if: ${{ matrix.changed == 'true' }}
2759
uses: actions/checkout@v4
2860

2961
- name: Set up Docker Buildx
62+
if: ${{ matrix.changed == 'true' }}
3063
uses: docker/setup-buildx-action@v3
3164

3265
- name: Login to GitHub Container Registry
66+
if: ${{ matrix.changed == 'true' }}
3367
uses: docker/login-action@v3
3468
with:
3569
registry: ${{ env.REGISTRY }}
3670
username: ${{ github.actor }}
3771
password: ${{ secrets.GITHUB_TOKEN }}
3872

3973
- name: Extract metadata
74+
if: ${{ matrix.changed == 'true' }}
4075
id: meta
4176
uses: docker/metadata-action@v5
4277
with:
43-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.images-name }}
78+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.name}}
4479
tags: |
4580
type=ref,event=pr
81+
type=raw,value=latest,enable={{is_default_branch}}
4682
type=sha,prefix=pr-${{ github.event.pull_request.number }}-
4783
4884
- name: Build and push
85+
if: ${{ matrix.changed == 'true' }}
4986
uses: docker/build-push-action@v5
5087
with:
51-
context: ./${{ matrix.images-name }}
88+
context: ./${{ matrix.name}}
5289
push: true
5390
tags: ${{ steps.meta.outputs.tags }}
5491
labels: ${{ steps.meta.outputs.labels }}

catalogue/.DS_Store

6 KB
Binary file not shown.

charts/general-chart/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

charts/general-chart/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: general-chart
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.16.0"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.httpRoute.enabled }}
3+
{{- if .Values.httpRoute.hostnames }}
4+
export APP_HOSTNAME={{ .Values.httpRoute.hostnames | first }}
5+
{{- else }}
6+
export APP_HOSTNAME=$(kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o jsonpath="{.spec.listeners[0].hostname}")
7+
{{- end }}
8+
{{- if and .Values.httpRoute.rules (first .Values.httpRoute.rules).matches (first (first .Values.httpRoute.rules).matches).path.value }}
9+
echo "Visit http://$APP_HOSTNAME{{ (first (first .Values.httpRoute.rules).matches).path.value }} to use your application"
10+
11+
NOTE: Your HTTPRoute depends on the listener configuration of your gateway and your HTTPRoute rules.
12+
The rules can be set for path, method, header and query parameters.
13+
You can check the gateway configuration with 'kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o yaml'
14+
{{- end }}
15+
{{- else if .Values.ingress.enabled }}
16+
{{- range $host := .Values.ingress.hosts }}
17+
{{- range .paths }}
18+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
19+
{{- end }}
20+
{{- end }}
21+
{{- else if contains "NodePort" .Values.service.type }}
22+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "general-chart.fullname" . }})
23+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
24+
echo http://$NODE_IP:$NODE_PORT
25+
{{- else if contains "LoadBalancer" .Values.service.type }}
26+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
27+
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "general-chart.fullname" . }}'
28+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "general-chart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
29+
echo http://$SERVICE_IP:{{ .Values.service.port }}
30+
{{- else if contains "ClusterIP" .Values.service.type }}
31+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "general-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
32+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
33+
echo "Visit http://127.0.0.1:8080 to use your application"
34+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
35+
{{- end }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "general-chart.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "general-chart.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "general-chart.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "general-chart.labels" -}}
37+
helm.sh/chart: {{ include "general-chart.chart" . }}
38+
{{ include "general-chart.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "general-chart.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "general-chart.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "general-chart.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "general-chart.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "general-chart.fullname" . }}
5+
labels:
6+
{{- include "general-chart.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "general-chart.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "general-chart.labels" . | nindent 8 }}
22+
{{- with .Values.podLabels }}
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
25+
spec:
26+
{{- with .Values.imagePullSecrets }}
27+
imagePullSecrets:
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
30+
serviceAccountName: {{ include "general-chart.serviceAccountName" . }}
31+
{{- with .Values.podSecurityContext }}
32+
securityContext:
33+
{{- toYaml . | nindent 8 }}
34+
{{- end }}
35+
containers:
36+
- name: {{ .Chart.Name }}
37+
{{- with .Values.securityContext }}
38+
securityContext:
39+
{{- toYaml . | nindent 12 }}
40+
{{- end }}
41+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
42+
imagePullPolicy: {{ .Values.image.pullPolicy }}
43+
ports:
44+
- name: http
45+
containerPort: {{ .Values.service.port }}
46+
protocol: TCP
47+
{{- with .Values.livenessProbe }}
48+
livenessProbe:
49+
{{- toYaml . | nindent 12 }}
50+
{{- end }}
51+
{{- with .Values.readinessProbe }}
52+
readinessProbe:
53+
{{- toYaml . | nindent 12 }}
54+
{{- end }}
55+
{{- with .Values.resources }}
56+
resources:
57+
{{- toYaml . | nindent 12 }}
58+
{{- end }}
59+
{{- with .Values.volumeMounts }}
60+
volumeMounts:
61+
{{- toYaml . | nindent 12 }}
62+
{{- end }}
63+
{{- with .Values.volumes }}
64+
volumes:
65+
{{- toYaml . | nindent 8 }}
66+
{{- end }}
67+
{{- with .Values.nodeSelector }}
68+
nodeSelector:
69+
{{- toYaml . | nindent 8 }}
70+
{{- end }}
71+
{{- with .Values.affinity }}
72+
affinity:
73+
{{- toYaml . | nindent 8 }}
74+
{{- end }}
75+
{{- with .Values.tolerations }}
76+
tolerations:
77+
{{- toYaml . | nindent 8 }}
78+
{{- end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "general-chart.fullname" . }}
6+
labels:
7+
{{- include "general-chart.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "general-chart.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
{{- end }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{- if .Values.httpRoute.enabled -}}
2+
{{- $fullName := include "general-chart.fullname" . -}}
3+
{{- $svcPort := .Values.service.port -}}
4+
apiVersion: gateway.networking.k8s.io/v1
5+
kind: HTTPRoute
6+
metadata:
7+
name: {{ $fullName }}
8+
labels:
9+
{{- include "general-chart.labels" . | nindent 4 }}
10+
{{- with .Values.httpRoute.annotations }}
11+
annotations:
12+
{{- toYaml . | nindent 4 }}
13+
{{- end }}
14+
spec:
15+
parentRefs:
16+
{{- with .Values.httpRoute.parentRefs }}
17+
{{- toYaml . | nindent 4 }}
18+
{{- end }}
19+
{{- with .Values.httpRoute.hostnames }}
20+
hostnames:
21+
{{- toYaml . | nindent 4 }}
22+
{{- end }}
23+
rules:
24+
{{- range .Values.httpRoute.rules }}
25+
{{- with .matches }}
26+
- matches:
27+
{{- toYaml . | nindent 8 }}
28+
{{- end }}
29+
{{- with .filters }}
30+
filters:
31+
{{- toYaml . | nindent 8 }}
32+
{{- end }}
33+
backendRefs:
34+
- name: {{ $fullName }}
35+
port: {{ $svcPort }}
36+
weight: 1
37+
{{- end }}
38+
{{- end }}

0 commit comments

Comments
 (0)