Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/k8s.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: K8S Build & Test

on:
pull_request:
workflow_dispatch:
push:
branches:
- "main"
tags:
- "v*"

permissions: {}

jobs:
container:
name: Build & publish container
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
id: metadata
with:
images: ghcr.io/esgf2-us/metadata-migrate-sync
tags: |
type=ref,event=pr
type=ref,event=tag
- uses: docker/build-push-action@v4
with:
cache-from: type=gha
cache-to: type=gha,mode=max
file: Dockerfile
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}

helm:
name: Publish Helm chart
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install jq
run: |
sudo apt-get install --yes jq
- name: Install yq
run: |
pip install yq
- name: Generate SemVer
id: semantic-version
run: |
CHART_VERSION=$(yq -r '.version' helm/Chart.yaml)
LOCAL_SEGMENT=+pr-${{ github.event.pull_request.number }}
GENERATED_VERSION=${CHART_VERSION}${LOCAL_SEGMENT}
yq -Y -i ".version = \"$GENERATED_VERSION\"" helm/Chart.yaml
echo "generated-semver=$GENERATED_VERSION" >> $GITHUB_OUTPUT
- name: Chart | Push
uses: appany/[email protected]
with:
name: esgf-sync
repository: esgf2-us
tag: ${{ steps.semantic-version.outputs.generated-semver }}
path: helm
registry: ghcr.io
registry_username: ${{ github.actor }}
registry_password: ${{ secrets.GITHUB_TOKEN }}
update_dependencies: "true"

test:
name: Test deployment
runs-on: ubuntu-latest
needs: [container, helm]
steps:
- uses: actions/checkout@v4
- name: Start minikube
uses: medyagh/setup-minikube@latest
- name: Set up Helm
uses: azure/[email protected]
- name: Install Helm Chart
run: |
helm install test oci://ghcr.io/esgf2-us/esgf-sync \
--version=${{ needs.helm.outputs.generated-semver }} \
--set image.tag=pr-${{ github.event.pull_request.number }} \
-f helm/ci/sync_dry_run.yaml \
--debug \
--wait

kubectl get pods
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim

# Install the project into `/app`
WORKDIR /app

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

# No need for a venv in a container
ENV UV_PROJECT_ENVIRONMENT=/usr/local

# Install the dependencies
COPY pyproject.toml uv.lock /app/
RUN uv sync --frozen --no-dev --no-cache --no-editable --no-install-project

# Install the app separately to avoid rebuilding the image when the app changes
COPY src/ README.md /app/
RUN uv sync --frozen --no-dev --no-cache --no-editable

# Reset the entrypoint, don't invoke `uv`
ENTRYPOINT ["esgf15mms"]

# Run the application
# CMD ["esgf15mms"]
23 changes: 23 additions & 0 deletions helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: esgf-sync
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
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.0

# 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: "1.16.0"
13 changes: 13 additions & 0 deletions helm/ci/sync_dry_run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
instances:
cmip6plus:
command: |-
while true; do
esgf15mms sync stage backup CMIP6Plus --prod --dry-run --start-time 2025-04-30 --work-dir /data
sleep 5m
done
drcdp:
command: |-
while true; do
esgf15mms sync stage backup DRCDP --prod --dry-run --start-time 2025-04-30 --work-dir /data
sleep 5m
done
62 changes: 62 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "esgf-sync.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "esgf-sync.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "esgf-sync.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "esgf-sync.labels" -}}
helm.sh/chart: {{ include "esgf-sync.chart" . }}
{{ include "esgf-sync.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "esgf-sync.selectorLabels" -}}
app.kubernetes.io/name: {{ include "esgf-sync.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "esgf-sync.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "esgf-sync.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions helm/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "esgf-sync.serviceAccountName" . }}
labels:
{{- include "esgf-sync.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
84 changes: 84 additions & 0 deletions helm/templates/statefulsets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{{- range $name, $spec := .Values.instances }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "esgf-sync.fullname" $ }}-{{ $name }}
labels:
{{- include "esgf-sync.labels" $ | nindent 4 }}
app.kubernetes.io/component: {{ $name }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "esgf-sync.selectorLabels" $ | nindent 6 }}
app.kubernetes.io/component: {{ $name }}
template:
metadata:
{{- with $.Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "esgf-sync.labels" $ | nindent 8 }}
app.kubernetes.io/component: {{ $name }}
{{- with $.Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with $.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "esgf-sync.serviceAccountName" $ }}
{{- with $.Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ $name }}
env:
- name: GLOBUS_CLIENT_ID
value: {{ $.Values.GLOBUS_CLIENT_ID | quote }}
- name: GLOBUS_CLIENT_SECRET
value: {{ $.Values.GLOBUS_CLIENT_SECRET | quote }}
command: ["/bin/sh", "-c"]
args:
- {{ $spec.command | quote }}
{{- with $.Values.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag | default $.Chart.AppVersion }}"
imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- with $.Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: {{ include "esgf-sync.fullname" $ }}-{{ $name }}
mountPath: /data
{{- with $.Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumeClaimTemplates:
- metadata:
name: {{ include "esgf-sync.fullname" $ }}-{{ $name }}
labels:
{{- include "esgf-sync.labels" $ | nindent 8 }}
app.kubernetes.io/component: {{ $name }}
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5G
---
{{- end }}
Loading
Loading