Skip to content

Commit 584a6e6

Browse files
author
Zach Price
committed
Initial CI/CD Setup
1 parent bc53cbb commit 584a6e6

File tree

11 files changed

+420
-67
lines changed

11 files changed

+420
-67
lines changed

.github/workflows/k8s.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: K8S Build & Test
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- "main"
9+
tags:
10+
- "v*"
11+
12+
permissions: {}
13+
14+
jobs:
15+
container:
16+
name: Build & publish container
17+
runs-on: ubuntu-latest
18+
permissions:
19+
packages: write
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: docker/setup-buildx-action@v3
23+
- uses: docker/login-action@v3
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
- uses: docker/metadata-action@v5
29+
id: metadata
30+
with:
31+
images: ghcr.io/esgf2-us/metadata-migrate-sync
32+
tags: |
33+
type=ref,event=pr
34+
type=ref,event=tag
35+
- uses: docker/build-push-action@v4
36+
with:
37+
cache-from: type=gha
38+
cache-to: type=gha,mode=max
39+
file: Dockerfile
40+
push: true
41+
tags: ${{ steps.metadata.outputs.tags }}
42+
labels: ${{ steps.metadata.outputs.labels }}
43+
44+
helm:
45+
name: Publish Helm chart
46+
runs-on: ubuntu-latest
47+
permissions:
48+
packages: write
49+
steps:
50+
- uses: actions/checkout@v4
51+
- uses: actions/setup-python@v5
52+
- name: Install jq
53+
run: |
54+
sudo apt-get install --yes jq
55+
- name: Install yq
56+
run: |
57+
pip install yq
58+
- name: Generate SemVer
59+
id: semantic-version
60+
run: |
61+
CHART_VERSION=$(yq -r '.version' helm/Chart.yaml)
62+
LOCAL_SEGMENT=+pr-${{ github.event.pull_request.number }}
63+
GENERATED_VERSION=${CHART_VERSION}${LOCAL_SEGMENT}
64+
yq -Y -i ".version = \"$GENERATED_VERSION\"" helm/Chart.yaml
65+
echo "generated-semver=$GENERATED_VERSION" >> $GITHUB_OUTPUT
66+
- name: Chart | Push
67+
uses: appany/[email protected]
68+
with:
69+
name: esgf-sync
70+
repository: esgf2-us
71+
tag: ${{ steps.semantic-version.outputs.generated-semver }}
72+
path: helm
73+
registry: ghcr.io
74+
registry_username: ${{ github.actor }}
75+
registry_password: ${{ secrets.GITHUB_TOKEN }}
76+
update_dependencies: "true"
77+
78+
test:
79+
name: Test deployment
80+
runs-on: ubuntu-latest
81+
needs: [container, helm]
82+
steps:
83+
- uses: actions/checkout@v4
84+
- name: Start minikube
85+
uses: medyagh/setup-minikube@latest
86+
- name: Set up Helm
87+
uses: azure/[email protected]
88+
- name: Install Helm Chart
89+
run: |
90+
helm install test oci://ghcr.io/esgf2-us/esgf-sync \
91+
--set image.tag=pr-${{ github.event.pull_request.number }} \
92+
--debug \
93+
--wait
94+
95+
kubectl get pods

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
2+
3+
# Install the project into `/app`
4+
WORKDIR /app
5+
6+
# Enable bytecode compilation
7+
ENV UV_COMPILE_BYTECODE=1
8+
9+
# No need for a venv in a container
10+
ENV UV_PROJECT_ENVIRONMENT=/usr/local
11+
12+
# Install the dependencies
13+
COPY pyproject.toml uv.lock /app/
14+
RUN uv sync --frozen --no-dev --no-cache --no-editable --no-install-project
15+
16+
# Install the app separately to avoid rebuilding the image when the app changes
17+
COPY src/ README.md /app/
18+
RUN uv sync --frozen --no-dev --no-cache --no-editable
19+
20+
# Reset the entrypoint, don't invoke `uv`
21+
ENTRYPOINT ["esgf15mms"]
22+
23+
# Run the application
24+
# CMD ["esgf15mms"]

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.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: esgf-sync
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"

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

helm/templates/serviceaccount.yaml

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 "esgf-sync.serviceAccountName" . }}
6+
labels:
7+
{{- include "esgf-sync.labels" . | nindent 4 }}
8+
{{- with .Values.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
13+
{{- end }}

helm/templates/statefulsets.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{{- range $name, $spec := .Values.instances }}
2+
apiVersion: apps/v1
3+
kind: StatefulSet
4+
metadata:
5+
name: {{ include "esgf-sync.fullname" $ }}
6+
labels:
7+
{{- include "esgf-sync.labels" $ | nindent 4 }}
8+
app.kubernetes.io/component: {{ $name }}
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
{{- include "esgf-sync.selectorLabels" $ | nindent 6 }}
14+
app.kubernetes.io/component: {{ $name }}
15+
template:
16+
metadata:
17+
{{- with $.Values.podAnnotations }}
18+
annotations:
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
{{- include "esgf-sync.labels" $ | nindent 8 }}
23+
app.kubernetes.io/component: {{ $name }}
24+
{{- with $.Values.podLabels }}
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
spec:
28+
{{- with $.Values.imagePullSecrets }}
29+
imagePullSecrets:
30+
{{- toYaml . | nindent 8 }}
31+
{{- end }}
32+
serviceAccountName: {{ include "esgf-sync.serviceAccountName" $ }}
33+
{{- with $.Values.podSecurityContext }}
34+
securityContext:
35+
{{- toYaml . | nindent 8 }}
36+
{{- end }}
37+
containers:
38+
- name: {{ $name }}
39+
env:
40+
- name: GLOBUS_CLIENT_ID
41+
value: {{ $.Values.GLOBUS_CLIENT_ID | quote }}
42+
- name: GLOBUS_CLIENT_SECRET
43+
value: {{ $.Values.GLOBUS_CLIENT_SECRET | quote }}
44+
command: ["/bin/sh", "-c"]
45+
args:
46+
- {{ $spec.command | quote }}
47+
{{- with $.Values.securityContext }}
48+
securityContext:
49+
{{- toYaml . | nindent 12 }}
50+
{{- end }}
51+
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag | default $.Chart.AppVersion }}"
52+
imagePullPolicy: {{ $.Values.image.pullPolicy }}
53+
{{- with $.Values.resources }}
54+
resources:
55+
{{- toYaml . | nindent 12 }}
56+
{{- end }}
57+
volumeMounts:
58+
- name: {{ include "esgf-sync.fullname" $ }}
59+
mountPath: /data
60+
{{- with $.Values.nodeSelector }}
61+
nodeSelector:
62+
{{- toYaml . | nindent 8 }}
63+
{{- end }}
64+
{{- with $.Values.affinity }}
65+
affinity:
66+
{{- toYaml . | nindent 8 }}
67+
{{- end }}
68+
{{- with $.Values.tolerations }}
69+
tolerations:
70+
{{- toYaml . | nindent 8 }}
71+
{{- end }}
72+
volumeClaimTemplates:
73+
- metadata:
74+
name: {{ include "esgf-sync.fullname" $ }}-{{ $name }}
75+
labels:
76+
{{- include "esgf-sync.labels" $ | nindent 8 }}
77+
app.kubernetes.io/component: {{ $name }}
78+
spec:
79+
accessModes: ["ReadWriteOnce"]
80+
resources:
81+
requests:
82+
storage: 5G
83+
---
84+
{{- end }}

0 commit comments

Comments
 (0)