Skip to content

Commit 780baab

Browse files
authored
Merge pull request #5 from HumanBrainProject/feat_migration
feat: add helm deploy
2 parents 3215ef0 + 02e7084 commit 780baab

23 files changed

+604
-380
lines changed

.github/workflows/dockerimage.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: '[build] docker image'
2+
3+
env:
4+
DOCKER_REPO: docker-registry.ebrains.eu
5+
DOCKER_NAMESPACE: hbp-spatial-backend
6+
DOCKER_IMAGE: server
7+
DOCKER_TAG: latest
8+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
9+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
10+
11+
on:
12+
push:
13+
branches:
14+
- main
15+
jobs:
16+
build-server-image:
17+
if: github.repository_owner == 'HumanBrainProject' and ${{ env.DOCKER_USERNAME != '' }} and ${{ env.DOCKER_PASSWORD != '' }}
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: 'Build and Push'
22+
run: |
23+
FULL_TAG=${{ env.DOCKER_REPO }}/${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}
24+
echo FULL_TAG: $FULL_TAG
25+
docker build -t $FULL_TAG -f Dockerfile.server .
26+
echo Build successful
27+
echo Login
28+
docker login \
29+
-u '${{ env.DOCKER_USERNAME }}' \
30+
-P '${{ env.DOCKER_PASSWORD }}' \
31+
${{ env.DOCKER_REPO }}
32+
echo Login Successful
33+
echo Pushing image
34+
docker push $FULL_TAG
35+
echo Pushing image successful

.github/workflows/tox.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ name: '[tox]'
33
on: [push]
44
jobs:
55
build:
6-
runs-on: ubuntu-latest
6+
runs-on: ${{ matrix.os }}
77
strategy:
88
fail-fast: false
99
matrix:
1010
# Python versions used in BrainVISA base images (i.e. Ubuntu LTS,
1111
# at the moment 18.04 and 20.04) + the latest stable Python version
12-
python-version: [ '3.10', '3.8', '3.6' ]
12+
python-version: [ '3.10', '3.8' ]
13+
os: ['ubuntu-latest']
14+
include:
15+
- python-version: '3.6'
16+
# see https://github.com/actions/setup-python/issues/355#issuecomment-1335042510
17+
os: 'ubuntu-20.04'
1318
steps:
1419
- uses: actions/checkout@v2
1520
- name: Set up Python ${{ matrix.python-version }}

.helm/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Deploying to production
2+
3+
This document is intended for a documentation on how hbp-spatial-backend can be deployed to a [kubernetes (k8s)](https://kubernetes.io/) cluster via [helm](https://helm.sh/).
4+
5+
Whilst the helm chart is produced with a rancher installation at https://rancher.tc.humanbrainproject.eu/ , the concept should be applicable to other k8s installations.
6+
7+
## Get started
8+
9+
1/ Create resources listed in adhoc (they may need to be adjusted based on the cluster you are working on) with:
10+
11+
```sh
12+
kubectl apply -f .helm/adhoc/*.yaml
13+
```
14+
2/ cp the static files needed to startup the service:
15+
16+
```sh
17+
pod_name=$(kubectl get pod -l app=busy-box -o jsonpath="{.items[0].metadata.name}")
18+
19+
for f in $(find /volatile/hbp-spatial-transformations-data/)
20+
do
21+
22+
kubectl cp $f $pod_name:/static-data/${f#/volatile/hbp-spatial-transformations-data/}
23+
done
24+
```
25+
26+
3/ Start application with `helm install prod .helm/hbp_spatial_backend`

.helm/adhoc/certificate.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: Certificate
3+
metadata:
4+
name: siibra-spatial-backend
5+
spec:
6+
commonName: siibra-spatial-backend.apps.tc.humanbrainproject.eu
7+
isCA: false
8+
dnsNames:
9+
- siibra-spatial-backend.apps.tc.humanbrainproject.eu
10+
issuerRef:
11+
kind: ClusterIssuer
12+
name: letsencrypt-production-issuer-1
13+
privateKey:
14+
algorithm: RSA
15+
encoding: PKCS1
16+
size: 2048
17+
renewBefore: 120h
18+
secretName: siibra-spatial-backend-secret
19+
usages:
20+
- server auth

.helm/adhoc/deployment-busybox.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: busy-box
5+
labels:
6+
app: busy-box
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: busy-box
12+
template:
13+
metadata:
14+
labels:
15+
app: busy-box
16+
spec:
17+
volumes:
18+
- name: data-volume
19+
persistentVolumeClaim:
20+
claimName: data-volume-claim
21+
containers:
22+
- name: busybox
23+
image: busybox:latest
24+
command: ["tail"]
25+
args: ["-f", "/dev/null"]
26+
resources:
27+
limits:
28+
cpu: 100m
29+
memory: 128Mi
30+
requests:
31+
cpu: 100m
32+
memory: 128Mi
33+
volumeMounts:
34+
- mountPath: /static-data
35+
name: data-volume

.helm/adhoc/pvc-data.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: data-volume-claim
5+
labels:
6+
type: longhorn-pvc
7+
spec:
8+
# https://wiki.ebrains.eu/bin/view/Collabs/migration-faq/EBRAINS%20Kubernetes%20README/?srid=01ZnoA2n#HDownloadandconfigureyourkubeconfigfile
9+
storageClassName: longhorn-1
10+
resources:
11+
requests:
12+
storage: 40Gi
13+
accessModes:
14+
- ReadWriteMany

.helm/hbp_spatial_backend/.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/hbp_spatial_backend/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: hbp-spatial-backend
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: "0.0.3"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "hbp_spatial_backend.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "hbp_spatial_backend.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "hbp_spatial_backend.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "hbp_spatial_backend.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22+
{{- 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 "hbp_spatial_backend.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 "hbp_spatial_backend.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 "hbp_spatial_backend.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "hbp_spatial_backend.labels" -}}
37+
helm.sh/chart: {{ include "hbp_spatial_backend.chart" . }}
38+
{{ include "hbp_spatial_backend.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 "hbp_spatial_backend.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "hbp_spatial_backend.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 "hbp_spatial_backend.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "hbp_spatial_backend.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

0 commit comments

Comments
 (0)