-
Notifications
You must be signed in to change notification settings - Fork 4
103 lines (88 loc) · 3.54 KB
/
build-deploy-k8s-test-hetzner.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Build, Migrate & Deploy to Test on Hetzner
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/[email protected]
- name: 'Login into ACR'
uses: azure/docker-login@v2
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: 'Build & Push image'
run: |
docker build -f Dockerfile . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/alkemio-server:${{ github.sha }} -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/alkemio-server:latest
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/alkemio-server:${{ github.sha }}
migrate:
needs: build
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/[email protected]
- name: Install Kubectl
uses: azure/[email protected]
with:
version: 'v1.27.6' # Ensure this matches the version used in your cluster
- name: Set up Kubeconfig for Hetzner k3s
run: |
mkdir -p $HOME/.kube # Ensure the .kube directory exists
echo "${{ secrets.KUBECONFIG_SECRET_HETZNER_TEST }}" > $HOME/.kube/config
chmod 600 $HOME/.kube/config
- name: Create Image Pull Secret
run: |
kubectl create secret docker-registry alkemio-server-secret \
--docker-server=${{ secrets.REGISTRY_LOGIN_SERVER }} \
--docker-username=${{ secrets.REGISTRY_USERNAME }} \
--docker-password=${{ secrets.REGISTRY_PASSWORD }} \
--dry-run=client -o yaml | kubectl apply -f -
- uses: azure/[email protected]
with:
manifests: |
manifests/26-server-migration.yaml
images: |
${{ secrets.REGISTRY_LOGIN_SERVER }}/alkemio-server:${{ github.sha }}
imagepullsecrets: |
alkemio-server-secret
- name: Delete old job
continue-on-error: true
run: |
kubectl delete job alkemio-server-migration-job
- name: Create migration job
run: |
kubectl create job --from=cronjob/alkemio-server-migration alkemio-server-migration-job
deploy:
needs: migrate
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/[email protected]
- name: Install Kubectl
uses: azure/[email protected]
with:
version: 'v1.27.6' # Ensure this matches the version used in your cluster
- name: Set up Kubeconfig for Hetzner k3s
run: |
mkdir -p $HOME/.kube # Ensure the .kube directory exists
echo "${{ secrets.KUBECONFIG_SECRET_HETZNER_TEST }}" > $HOME/.kube/config
chmod 600 $HOME/.kube/config
- name: Create Image Pull Secret
run: |
kubectl create secret docker-registry alkemio-server-secret \
--docker-server=${{ secrets.REGISTRY_LOGIN_SERVER }} \
--docker-username=${{ secrets.REGISTRY_USERNAME }} \
--docker-password=${{ secrets.REGISTRY_PASSWORD }} \
--dry-run=client -o yaml | kubectl apply -f -
- name: Deploy to k3s on Hetzner
uses: azure/[email protected]
with:
manifests: |
manifests/25-server-deployment-dev.yaml
manifests/30-server-service.yaml
images: |
${{ secrets.REGISTRY_LOGIN_SERVER }}/alkemio-server:${{ github.sha }}
imagepullsecrets: |
alkemio-server-secret