-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (127 loc) · 5.02 KB
/
ci.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Continuous Integration
on:
pull_request: { branches: [ "main","develop" ] }
push:
branches: [ "main","develop" ]
tags: [ "*" ]
env:
KUBECONFIG: .kube/config
KUBECONFIG_FILE: ${{ secrets.KUBECONFIG }}
GIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build:
name: "Build Image"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- id: generate-image-tag
name: Generate Image Tag
env:
ref_name: "${{ github.ref_name }}"
head_ref: "${{ github.head_ref }}"
run: |
head_ref="${head_ref/\//-}"
ref_name="${head_ref:-${ref_name/main/latest}}"
echo "::set-output name=imageTag::${ref_name#v}"
- name: Login to Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Backend
uses: docker/build-push-action@v2
with:
context: ./backend
push: true
tags: |
ghcr.io/${{ github.repository }}/backend:${{ steps.generate-image-tag.outputs.imageTag }}
ghcr.io/${{ github.repository }}/backend:${{ github.event.pull_request.head.sha || github.sha }}
build-args: |
COMMIT_SHA=${{ github.sha }}
- uses: actions/setup-node@v3
with:
node-version: '17.x'
registry-url: 'https://npm.pkg.github.com/'
- run: npm ci --legacy-peer-deps
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: ./frontend
- run: npm run build
env:
CI: false
working-directory: ./frontend
- name: Build and Push Frontend
uses: docker/build-push-action@v2
with:
context: ./frontend
push: true
tags: |
ghcr.io/${{ github.repository }}/frontend:${{ steps.generate-image-tag.outputs.imageTag }}
ghcr.io/${{ github.repository }}/frontend:${{ github.event.pull_request.head.sha || github.sha }}
deploy_development:
needs: build
if: github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
steps:
- id: generate-image-tag
name: Generate Image Tag
env:
ref_name: "${{ github.ref_name }}"
head_ref: "${{ github.head_ref }}"
run: |
head_ref="${head_ref/\//-}"
ref_name="${head_ref:-${ref_name/main/latest}}"
echo "::set-output name=imageTag::${ref_name#v}"
- uses: actions/checkout@v2
- run: |
mkdir -p .kube
echo "${{ env.KUBECONFIG_FILE }}" > $KUBECONFIG
- uses: stefanprodan/kube-tools@v1
with:
helmv3: 3.12.0
command: |
kubectl get nodes
helmv3 repo add mda-deployment https://nfdi4health.github.io/mda-deployment/
helmv3 repo update
helmv3 upgrade mda-${{ steps.generate-image-tag.outputs.imageTag }} \
--install \
--set-json='images.backend="ghcr.io/${{ github.repository }}/backend:${{ github.event.pull_request.head.sha || github.sha }}"' \
--set-json='images.frontend="ghcr.io/${{ github.repository }}/frontend:${{ github.event.pull_request.head.sha || github.sha }}"' \
--set-json='images.prediction="gitlab.zbmed.de:5050/km/thesis/pierre-ba/backend:a7d3254ee488a236dade40ecedc646861aff9dbe"' \
--set-json='ingress.dns="${{ steps.generate-image-tag.outputs.imageTag }}.mda.qa.km.k8s.zbmed.de"' \
mda-deployment/metadata-annotation
deploy_main:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- id: generate-image-tag
name: Generate Image Tag
env:
ref_name: "${{ github.ref_name }}"
head_ref: "${{ github.head_ref }}"
run: |
head_ref="${head_ref/\//-}"
ref_name="${head_ref:-${ref_name/main/latest}}"
echo "::set-output name=imageTag::${ref_name#v}"
- uses: actions/checkout@v2
- run: |
mkdir -p .kube
echo "${{ env.KUBECONFIG_FILE }}" > $KUBECONFIG
- uses: stefanprodan/kube-tools@v1
with:
helmv3: 3.12.0
command: |
kubectl get nodes
helmv3 repo add mda-deployment https://nfdi4health.github.io/mda-deployment/
helmv3 repo update
helmv3 upgrade mda-${{ steps.generate-image-tag.outputs.imageTag }} \
--install \
--set-json='images.backend="ghcr.io/${{ github.repository }}/backend:${{ github.event.pull_request.head.sha || github.sha }}"' \
--set-json='images.frontend="ghcr.io/${{ github.repository }}/frontend:${{ github.event.pull_request.head.sha || github.sha }}"' \
--set-json='images.prediction="gitlab.zbmed.de:5050/km/thesis/pierre-ba/backend:a7d3254ee488a236dade40ecedc646861aff9dbe"' \
--set-json='ingress.dns="${{ steps.generate-image-tag.outputs.imageTag }}.mda.qa.km.k8s.zbmed.de"' \
mda-deployment/metadata-annotation