Skip to content

Commit a336554

Browse files
authored
Development: Add K8s deployment (#2)
* Add K8s deployment * Add K8s deployment * Use specific image tag
1 parent 5fd8edd commit a336554

File tree

15 files changed

+527
-139
lines changed

15 files changed

+527
-139
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -57,71 +57,40 @@ jobs:
5757
deploy:
5858
needs: [build-artemis-adapter]
5959
runs-on: ubuntu-latest
60-
environment: hades-test
60+
environment:
61+
name: hades-artemis-adapter-k8s
62+
url: https://hades-artemis-connector.student.k8s.aet.cit.tum.de
6163
steps:
6264
- name: Checkout repository
6365
uses: actions/checkout@v6
6466

65-
- name: Create deployment directory on VM
66-
uses: appleboy/ssh-action@v1.2.5
67+
- name: Setup Helm
68+
uses: azure/setup-helm@v4
6769
with:
68-
host: ${{ vars.VM_HOST }}
69-
username: ${{ vars.VM_USERNAME }}
70-
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
71-
proxy_host: ${{ vars.DEPLOYMENT_GATEWAY_HOST }}
72-
proxy_username: ${{ vars.DEPLOYMENT_GATEWAY_USER }}
73-
proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }}
74-
proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }}
75-
script: mkdir -p /opt/hades/traefik
70+
version: v3.14.0
7671

77-
- name: Copy deployment files to VM
78-
uses: appleboy/scp-action@v1.0.0
72+
- name: Setup kubectl
73+
uses: azure/setup-kubectl@v4
7974
with:
80-
host: ${{ vars.VM_HOST }}
81-
username: ${{ vars.VM_USERNAME }}
82-
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
83-
proxy_host: ${{ vars.DEPLOYMENT_GATEWAY_HOST }}
84-
proxy_username: ${{ vars.DEPLOYMENT_GATEWAY_USER }}
85-
proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }}
86-
proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }}
87-
source: "docker-compose.test.yml,traefik/traefik.yml"
88-
target: /opt/hades
89-
strip_components: 0
75+
version: 'latest'
9076

91-
- name: Create .env file on VM
92-
uses: appleboy/ssh-action@v1.2.5
93-
with:
94-
host: ${{ vars.VM_HOST }}
95-
username: ${{ vars.VM_USERNAME }}
96-
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
97-
proxy_host: ${{ vars.DEPLOYMENT_GATEWAY_HOST }}
98-
proxy_username: ${{ vars.DEPLOYMENT_GATEWAY_USER }}
99-
proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }}
100-
proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }}
101-
script: |
102-
touch /opt/hades/traefik/acme.json
103-
chmod 600 /opt/hades/traefik/acme.json
104-
install -m 600 /dev/null /opt/hades/.env
105-
cat > /opt/hades/.env <<'EOF'
106-
IMAGE_TAG=${{ needs.build-artemis-adapter.outputs.image_tag }}
107-
HADES_API_HOST=${{ vars.HADES_API_HOST }}
108-
LETSENCRYPT_EMAIL=${{ vars.LETSENCRYPT_EMAIL }}
109-
ARTEMIS_BASE_URL=${{ vars.ARTEMIS_BASE_URL }}
110-
ARTEMIS_NEW_RESULT_ENDPOINT=${{ vars.ARTEMIS_NEW_RESULT_ENDPOINT }}
111-
ARTEMIS_AUTH_TOKEN=${{ secrets.ARTEMIS_AUTH_TOKEN }}
112-
EOF
77+
- name: Setup Kubeconfig
78+
run: |
79+
# Write kubeconfig from secret to file
80+
echo "${{ secrets.KUBECONFIG }}" > kubeconfig
81+
export KUBECONFIG=$PWD/kubeconfig
82+
chmod 600 kubeconfig
11383
114-
- name: Deploy with docker compose
115-
uses: appleboy/ssh-action@v1.2.5
116-
with:
117-
host: ${{ vars.VM_HOST }}
118-
username: ${{ vars.VM_USERNAME }}
119-
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
120-
proxy_host: ${{ vars.DEPLOYMENT_GATEWAY_HOST }}
121-
proxy_username: ${{ vars.DEPLOYMENT_GATEWAY_USER }}
122-
proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }}
123-
proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }}
124-
script: |
125-
cd /opt/hades
126-
docker compose -f docker-compose.test.yml up --pull=always -d --remove-orphans
127-
docker image prune -af --filter "until=24h"
84+
# Verify connection to cluster
85+
kubectl config get-contexts
86+
kubectl get nodes
87+
88+
- name: Deploy to Kubernetes
89+
env:
90+
KUBECONFIG: ${{ github.workspace }}/kubeconfig
91+
run: |
92+
helm upgrade --install hades-artemis-adapter ./helm/hades-artemis-adapter -f ./helm/values-deploy.yaml \
93+
--namespace hades-artemis-connector --create-namespace \
94+
--set image.tag="${{ needs.build-artemis-adapter.outputs.image_tag }}" \
95+
--set env.ARTEMIS_BASE_URL="https://artemis-test8.artemis.cit.tum.de" \
96+
--set env.ARTEMIS_AUTH_TOKEN="${{ secrets.ARTEMIS_AUTH_TOKEN }}"

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
# hades-artemis-adapter
1+
# hades-artemis-adapter
2+
3+
> [!WARNING]
4+
> This is a work in progress repository.
5+
6+
## Deployment
7+
8+
```shell
9+
10+
helm upgrade --install hades-artemis-adapter ./helm/hades-artemis-adapter -f ./helm/values-deploy.yaml \
11+
--namespace hades-artemis-connector --create-namespace \
12+
--set image.tag="main" \
13+
--set env.ARTEMIS_BASE_URL="https://artemis-test8.artemis.cit.tum.de" \
14+
--set env.ARTEMIS_AUTH_TOKEN="<TOKEN>"
15+
16+
```

docker-compose.deploy.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

docker-compose.test.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.
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/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: hades-artemis-adapter
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"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.httpRoute.enabled }}
3+
{{- if .Values.httpRoute.hostnames }}
4+
export APP_HOSTNAME={{ .Values.httpRoute.hostnames | first }}
5+
{{- else }}
6+
export APP_HOSTNAME=$(kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o jsonpath="{.spec.listeners[0].hostname}")
7+
{{- end }}
8+
{{- if and .Values.httpRoute.rules (first .Values.httpRoute.rules).matches (first (first .Values.httpRoute.rules).matches).path.value }}
9+
echo "Visit http://$APP_HOSTNAME{{ (first (first .Values.httpRoute.rules).matches).path.value }} to use your application"
10+
11+
NOTE: Your HTTPRoute depends on the listener configuration of your gateway and your HTTPRoute rules.
12+
The rules can be set for path, method, header and query parameters.
13+
You can check the gateway configuration with 'kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o yaml'
14+
{{- end }}
15+
{{- else if .Values.ingress.enabled }}
16+
{{- range $host := .Values.ingress.hosts }}
17+
{{- range .paths }}
18+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
19+
{{- end }}
20+
{{- end }}
21+
{{- else if contains "NodePort" .Values.service.type }}
22+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "hades-artemis-adapter.fullname" . }})
23+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
24+
echo http://$NODE_IP:$NODE_PORT
25+
{{- else if contains "LoadBalancer" .Values.service.type }}
26+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
27+
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "hades-artemis-adapter.fullname" . }}'
28+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "hades-artemis-adapter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
29+
echo http://$SERVICE_IP:{{ .Values.service.port }}
30+
{{- else if contains "ClusterIP" .Values.service.type }}
31+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "hades-artemis-adapter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
32+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
33+
echo "Visit http://127.0.0.1:8080 to use your application"
34+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
35+
{{- end }}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "hades-artemis-adapter.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 "hades-artemis-adapter.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 "hades-artemis-adapter.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "hades-artemis-adapter.labels" -}}
37+
helm.sh/chart: {{ include "hades-artemis-adapter.chart" . }}
38+
{{ include "hades-artemis-adapter.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 "hades-artemis-adapter.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "hades-artemis-adapter.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}

0 commit comments

Comments
 (0)