Skip to content

Commit daeea79

Browse files
committed
Add helm chart
Add the-deep api helmchart: deployment, ingress, configmap, secrets, argohooks, workers
1 parent ffe2b2f commit daeea79

File tree

16 files changed

+798
-12
lines changed

16 files changed

+798
-12
lines changed

.github/workflows/ci.yml

Lines changed: 100 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,93 @@
11
name: Deep server 🤓 GH Action 🚧
22

33
on:
4+
workflow_call:
5+
inputs:
6+
push_docker_image:
7+
type: string # true or false
8+
default: "false"
9+
outputs:
10+
docker_image_name:
11+
description: "Only docker image name"
12+
value: ${{ jobs.build_test.outputs.docker_image_name }}
13+
docker_image_tag:
14+
description: "Only docker image tag"
15+
value: ${{ jobs.build_test.outputs.docker_image_tag }}
16+
docker_image:
17+
description: "docker image with tag"
18+
value: ${{ jobs.build_test.outputs.docker_image }}
419
pull_request:
5-
push:
6-
branches:
7-
- develop
20+
# NOTE: For other, they should be run through helm github action ./helm-publish.yml
21+
822

923
jobs:
1024
build_test:
1125
name: 🚴 Build + Test 🚴 # Match the name below (8398a7/action-slack).
1226
runs-on: ubuntu-latest
27+
28+
outputs:
29+
docker_image_name: ${{ steps.prep.outputs.tagged_image_name }}
30+
docker_image_tag: ${{ steps.prep.outputs.tag }}
31+
docker_image: ${{ steps.prep.outputs.tagged_image }}
32+
1333
steps:
1434
- uses: actions/checkout@master
1535

36+
- name: Login to GitHub Container Registry
37+
uses: docker/login-action@v3
38+
if: ${{ inputs.push_docker_image }}
39+
with:
40+
registry: ghcr.io
41+
username: ${{ github.actor }}
42+
password: ${{ secrets.GITHUB_TOKEN }}
43+
1644
- name: 🐳 Prepare Docker
1745
id: prep
46+
env:
47+
IMAGE_NAME: ghcr.io/${{ github.repository }}
1848
run: |
19-
TAG=$(echo $GITHUB_SHA | head -c7)
20-
IMAGE="docker.pkg.github.com/the-deep/server"
21-
echo "tagged_image=${IMAGE}:${TAG}" >> $GITHUB_OUTPUT
49+
BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|:|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//')
50+
51+
# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
52+
if [[ "$BRANCH_NAME" == *"/"* ]]; then
53+
# XXX: Change the docker image package to -alpha
54+
IMAGE_NAME="$IMAGE_NAME-alpha"
55+
TAG="$(echo "$BRANCH_NAME" | sed 's|/|-|g').$(echo $GITHUB_SHA | head -c7)"
56+
else
57+
TAG="$BRANCH_NAME.$(echo $GITHUB_SHA | head -c7)"
58+
fi
59+
60+
IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')
61+
echo "tagged_image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
2262
echo "tag=${TAG}" >> $GITHUB_OUTPUT
63+
echo "tagged_image=${IMAGE_NAME}:${TAG}" >> $GITHUB_OUTPUT
64+
echo "::notice::Tagged docker image: ${IMAGE_NAME}:${TAG}"
65+
2366
- name: 🐳 Set up Docker Buildx
2467
id: buildx
25-
uses: docker/setup-buildx-action@master
68+
uses: docker/setup-buildx-action@v3
69+
70+
- name: 🐳 Cache Docker layers
71+
uses: actions/cache@v4
72+
with:
73+
path: /tmp/.buildx-cache
74+
key: ${{ runner.os }}-buildx-${{ github.ref }}
75+
restore-keys: |
76+
${{ runner.os }}-buildx-refs/develop
77+
${{ runner.os }}-buildx-
2678
2779
- name: 🐳 Build image
28-
uses: docker/build-push-action@v4
80+
uses: docker/build-push-action@v6
2981
with:
3082
context: .
3183
builder: ${{ steps.buildx.outputs.name }}
3284
file: Dockerfile
3385
push: false # This would be set to true in a real world deployment scenario.
3486
load: true
35-
target: worker # this has all the dep
87+
provenance: false # XXX: Without this we have untagged images in ghcr.io
3688
tags: ${{ steps.prep.outputs.tagged_image }}
37-
# Using experimental GH api: https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api
38-
cache-from: type=gha
39-
cache-to: type=gha,mode=max
89+
cache-from: type=local,src=/tmp/.buildx-cache
90+
cache-to: type=local,dest=/tmp/.buildx-cache-new
4091

4192
- name: 🕮 Validate latest graphql schema.
4293
env:
@@ -78,6 +129,22 @@ jobs:
78129
branch: gh-pages
79130
folder: ./coverage/htmlcov
80131

132+
- name: 🐳 Docker push
133+
if: ${{ inputs.push_docker_image }}
134+
uses: docker/build-push-action@v6
135+
with:
136+
tags: ${{ steps.prep.outputs.tagged_image }}
137+
push: true
138+
139+
# Temp fix
140+
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
141+
# https://github.com/docker/build-push-action/issues/252
142+
# https://github.com/moby/buildkit/issues/1896
143+
- name: 🐳 Move docker cache (🧙 Hack fix)
144+
run: |
145+
rm -rf /tmp/.buildx-cache
146+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
147+
81148
- uses: 8398a7/action-slack@v3
82149
with:
83150
status: custom
@@ -94,3 +161,24 @@ jobs:
94161
env:
95162
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
96163
if: always() # Pick up events even if the job fails or is canceled.
164+
165+
validate_helm:
166+
name: 🚴 Validate Helm 🚴
167+
runs-on: ubuntu-latest
168+
169+
steps:
170+
- uses: actions/checkout@main
171+
172+
- name: Install Helm
173+
uses: azure/setup-helm@v4
174+
175+
- name: 🐳 Helm dependency
176+
run: |
177+
yq --indent 0 '.dependencies | map(["helm", "repo", "add", .name, .repository] | join(" ")) | .[]' ./helm/Chart.lock | sh --
178+
helm dependency build ./helm
179+
180+
- name: 🐳 Helm lint
181+
run: helm lint ./helm --values ./helm/values-test.yaml
182+
183+
- name: 🐳 Helm template
184+
run: helm template ./helm --values ./helm/values-test.yaml

.github/workflows/helm-publish.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Builds and pushes Docker Images and Helm charts to Github Registry
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- develop
8+
- project/*
9+
# XXX: To add tags: Update the -alpha logic
10+
11+
permissions:
12+
packages: write
13+
14+
jobs:
15+
ci:
16+
name: CI
17+
uses: ./.github/workflows/ci.yml
18+
with:
19+
push_docker_image: true
20+
21+
build:
22+
name: Publish Helm
23+
needs: ci
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
30+
- name: Login to GitHub Container Registry
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Install Helm
38+
uses: azure/setup-helm@v3
39+
40+
- name: 🐳 Helm dependency
41+
run: |
42+
yq --indent 0 '.dependencies | map(["helm", "repo", "add", .name, .repository] | join(" ")) | .[]' ./helm/Chart.lock | sh --
43+
helm dependency build ./helm
44+
45+
- name: Tag docker image in Helm Chart values.yaml
46+
env:
47+
IMAGE_NAME: ${{ needs.ci.outputs.docker_image_name }}
48+
IMAGE_TAG: ${{ needs.ci.outputs.docker_image_tag }}
49+
run: |
50+
# Update values.yaml with latest docker image
51+
sed -i "s|SET-BY-CICD-IMAGE|$IMAGE_NAME|" helm/values.yaml
52+
sed -i "s/SET-BY-CICD-TAG/$IMAGE_TAG/" helm/values.yaml
53+
54+
- name: Package Helm Chart
55+
id: set-variables
56+
env:
57+
IMAGE_TAG: ${{ needs.ci.outputs.docker_image_tag }}
58+
run: |
59+
# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
60+
if [[ "$GITHUB_REF_NAME" == *"/"* ]]; then
61+
# XXX: Change the helm chart to <chart-name>-alpha
62+
sed -i 's/^name: \(.*\)/name: \1-alpha/' helm/Chart.yaml
63+
fi
64+
65+
sed -i "s/SET-BY-CICD/$IMAGE_TAG/g" helm/Chart.yaml
66+
helm package ./helm -d .helm-charts
67+
68+
- name: Push Helm Chart
69+
env:
70+
IMAGE: ${{ needs.ci.outputs.docker_image }}
71+
OCI_REPO: oci://ghcr.io/${{ github.repository }}
72+
run: |
73+
OCI_REPO=$(echo $OCI_REPO | tr '[:upper:]' '[:lower:]')
74+
PACKAGE_FILE=$(ls .helm-charts/*.tgz | head -n 1)
75+
echo "# Helm Chart" >> $GITHUB_STEP_SUMMARY
76+
echo "" >> $GITHUB_STEP_SUMMARY
77+
echo "Tagged Image: **$IMAGE**" >> $GITHUB_STEP_SUMMARY
78+
echo "" >> $GITHUB_STEP_SUMMARY
79+
echo "Helm push output" >> $GITHUB_STEP_SUMMARY
80+
echo "" >> $GITHUB_STEP_SUMMARY
81+
echo '```bash' >> $GITHUB_STEP_SUMMARY
82+
helm push "$PACKAGE_FILE" $OCI_REPO >> $GITHUB_STEP_SUMMARY
83+
echo '```' >> $GITHUB_STEP_SUMMARY

helm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
charts
2+
values-local.yaml

helm/.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/

helm/Chart.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dependencies:
2+
- name: redis
3+
repository: https://charts.bitnami.com/bitnami
4+
version: 20.2.1
5+
- name: postgresql
6+
repository: https://charts.bitnami.com/bitnami
7+
version: 15.5.32
8+
digest: sha256:d9755a578cb81acf58b8d5fe937eb76d14f210666d8e2859328c9055a9dfba8a
9+
generated: "2024-12-29T10:25:00.270180265+05:45"

helm/Chart.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v2
2+
name: the-deep-helm
3+
description: "Helm Chart to deploy the deep server Infrastructure"
4+
5+
type: application
6+
version: 0.0.1-SET-BY-CICD
7+
sources:
8+
- https://github.com/the-deep/server
9+
10+
dependencies:
11+
- name: redis
12+
version: "20.2.1"
13+
repository: https://charts.bitnami.com/bitnami
14+
condition: redis.enabled
15+
- name: postgresql
16+
version: 15.5.32
17+
condition: postgresql.enabled
18+
repository: https://charts.bitnami.com/bitnami

helm/templates/_helpers.tpl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "the-deep.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+
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
13+
*/}}
14+
{{- define "the-deep.fullname" -}}
15+
{{- if .Values.fullnameOverride }}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
17+
{{- else }}
18+
{{- $name := default .Chart.Name .Values.nameOverride }}
19+
{{- if contains $name .Release.Name }}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
21+
{{- else }}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
23+
{{- end }}
24+
{{- end }}
25+
{{- end }}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "the-deep.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
32+
{{- end }}
33+
34+
{{/*
35+
Create the name of the service account to use
36+
*/}}
37+
{{- define "the-deep.serviceAccountName" -}}
38+
{{- if .Values.serviceAccount.create }}
39+
{{- default (include "the-deep.fullname" .) .Values.serviceAccount.name }}
40+
{{- else }}
41+
{{- default "default" .Values.serviceAccount.name }}
42+
{{- end }}
43+
{{- end }}
44+
45+
{{/*
46+
Create the name of the secret to be used by the the-deep
47+
*/}}
48+
{{- define "the-deep.secretname" -}}
49+
{{- if .Values.secretsName }}
50+
{{- .Values.secretsName -}}
51+
{{- else }}
52+
{{- printf "%s-secret" (include "the-deep.fullname" .) -}}
53+
{{- end -}}
54+
{{- end -}}

0 commit comments

Comments
 (0)