Skip to content

Commit 0007875

Browse files
authored
DEVOPS-450 deployment (#8)
* add go build gh action for DEVOPS-7450 * fix go version in gh action * add dockerfile, docker workflow, update action versions * helm chart for mod-cyclops * add substitution for module name
1 parent 282ff6a commit 0007875

8 files changed

Lines changed: 412 additions & 0 deletions

File tree

.github/workflows/helm.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: publish-chart
2+
3+
permissions:
4+
packages: write
5+
contents: read
6+
7+
on:
8+
# we only publish the chart after succesful Docker build so we trigger
9+
# a full build when chart templates are changed, this is slightly suboptimal
10+
# TODO automatically bump chart version during build
11+
workflow_run:
12+
workflows: ["publish-image"]
13+
types: [completed]
14+
branches: ["main"]
15+
16+
jobs:
17+
publish-chart:
18+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
19+
runs-on: ubuntu-latest
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- chart_name: mod-cyclops
25+
chart_base_version: "0.1.0-main.${{ github.run_number }}"
26+
chart_path: ./chart
27+
md_path: ./descriptors/ModuleDescriptor-template.json
28+
steps:
29+
- uses: actions/checkout@v6
30+
31+
- name: Calculate chart and app version with short SHA
32+
run: |
33+
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
34+
ARTIFACT_ID=$(sed -n 's|^module .*/||p' go.mod)
35+
CHART_VERSION="${{ matrix.chart_base_version }}+sha.$SHORT_SHA"
36+
APP_VERSION="sha-$SHORT_SHA"
37+
echo "ARTIFACT_ID=$ARTIFACT_ID" >> $GITHUB_ENV
38+
echo "CHART_VERSION=$CHART_VERSION" >> $GITHUB_ENV
39+
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
40+
41+
- name: Process MD for okapi-hooks
42+
if: ${{ matrix.md_path }}
43+
run: |
44+
sed -i -e "s/@artifactId@/$ARTIFACT_ID/g" -e "s/@version@/$CHART_VERSION/g" ${{ matrix.md_path }}
45+
sed 's/^/ /' ${{ matrix.md_path }} > indented.json
46+
sed -i -e '/@descriptor@/{
47+
r indented.json
48+
d
49+
}' ${{ matrix.chart_path }}/values.yaml
50+
51+
- name: helm lint
52+
run: |
53+
helm lint ${{ matrix.chart_path }}
54+
55+
- name: helm login
56+
run: |
57+
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io -u $ --password-stdin
58+
59+
- name: helm dependency
60+
run: |
61+
helm dependency build ${{ matrix.chart_path }}
62+
63+
- name: helm package
64+
run: |
65+
helm package ${{ matrix.chart_path }} --version "$CHART_VERSION" --app-version "$APP_VERSION"
66+
67+
- name: helm push
68+
run: |
69+
helm push "${{ matrix.chart_name }}-$CHART_VERSION.tgz" oci://ghcr.io/${{ github.repository_owner }}/charts

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/

chart/Chart.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v2
2+
name: mod-cyclops
3+
description: Mod Cyclops
4+
type: application
5+
6+
# Use semver, note that this is replaced by the publish action
7+
version: 0.1.0
8+
9+
# appVersion is used as the Docker image tag by the chart
10+
appVersion: "main"
11+
12+
dependencies:
13+
- name: okapi-hooks
14+
repository: oci://ghcr.io/indexdata/charts
15+
version: ">0.1.0-0"
16+
condition: okapi-hooks.enabled

chart/templates/_helpers.tpl

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 "..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 "..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 "..chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "..labels" -}}
37+
helm.sh/chart: {{ include "..chart" . }}
38+
{{ include "..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 "..selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "..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 "..serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "..fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

chart/templates/deployment.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "..fullname" . }}
5+
labels:
6+
{{- include "..labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "..selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "..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 "..serviceAccountName" . }}
31+
securityContext:
32+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
33+
containers:
34+
- name: {{ .Chart.Name }}
35+
env:
36+
- name: HTTP_PORT
37+
value: "{{ .Values.containerPort }}"
38+
{{- range $k, $v := .Values.env }}
39+
{{- if ne $k "HTTP_PORT" }}
40+
- name: {{ $k }}
41+
value: "{{ $v }}"
42+
{{- end }}
43+
{{- end }}
44+
{{- range $k, $v := .Values.envSecrets }}
45+
{{- if ne $k "HTTP_PORT" }}
46+
- name: {{ $k }}
47+
valueFrom:
48+
secretKeyRef:
49+
name: "{{ $v.name }}"
50+
key: "{{ $v.key }}"
51+
{{- end }}
52+
{{- end }}
53+
{{- range $k, $v := .Values.envConfigMaps }}
54+
{{- if ne $k "HTTP_PORT" }}
55+
- name: {{ $k }}
56+
valueFrom:
57+
configMapKeyRef:
58+
name: "{{ $v.name }}"
59+
key: "{{ $v.key }}"
60+
{{- end }}
61+
{{- end }}
62+
securityContext:
63+
{{- toYaml .Values.securityContext | nindent 12 }}
64+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
65+
imagePullPolicy: {{ .Values.image.pullPolicy }}
66+
ports:
67+
- name: http
68+
containerPort: {{ .Values.containerPort }}
69+
protocol: TCP
70+
# there is no healthz. -ih
71+
#livenessProbe:
72+
# httpGet:
73+
# path: /healthz
74+
# port: http
75+
#readinessProbe:
76+
# httpGet:
77+
# path: /healthz
78+
# port: http
79+
resources:
80+
{{- toYaml .Values.resources | nindent 12 }}
81+
{{- with .Values.volumeMounts }}
82+
volumeMounts:
83+
{{- toYaml . | nindent 12 }}
84+
{{- end }}
85+
{{- with .Values.volumes }}
86+
volumes:
87+
{{- toYaml . | nindent 8 }}
88+
{{- end }}
89+
{{- with .Values.nodeSelector }}
90+
nodeSelector:
91+
{{- toYaml . | nindent 8 }}
92+
{{- end }}
93+
{{- with .Values.affinity }}
94+
affinity:
95+
{{- toYaml . | nindent 8 }}
96+
{{- end }}
97+
{{- with .Values.tolerations }}
98+
tolerations:
99+
{{- toYaml . | nindent 8 }}
100+
{{- end }}

chart/templates/service.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "..fullname" . }}
5+
{{- with .Values.serviceAnnotations }}
6+
annotations:
7+
{{- toYaml . | nindent 8 }}
8+
{{- end }}
9+
labels:
10+
{{- include "..labels" . | nindent 4 }}
11+
spec:
12+
type: {{ .Values.service.type }}
13+
ports:
14+
- port: {{ .Values.service.httpPort }}
15+
targetPort: {{ .Values.service.httpTargetPort }}
16+
protocol: TCP
17+
name: http
18+
selector:
19+
{{- include "..selectorLabels" . | nindent 4 }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if .Values.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "..serviceAccountName" . }}
6+
labels:
7+
{{- include "..labels" . | nindent 4 }}
8+
{{- with .Values.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
13+
{{- end }}

0 commit comments

Comments
 (0)