-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.yml
121 lines (103 loc) · 3.83 KB
/
deploy.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
name: Deploy
on:
push:
branches:
- main
jobs:
build-backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: setup go
uses: actions/setup-go@v2
with:
go-version: ^1.17
- name: login to github docker registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: publish backend docker image to registry
env:
COMMIT_SHA: ${{ github.sha }}
REPO_REGISTRY: ghcr.io/${{ github.repository }}
run: |
docker build \
-t $REPO_REGISTRY/${GITHUB_REPOSITORY#*/}-backend:${GITHUB_REF##*/} \
-t $REPO_REGISTRY/${GITHUB_REPOSITORY#*/}-backend:$COMMIT_SHA \
-t $REPO_REGISTRY/${GITHUB_REPOSITORY#*/}-backend:latest .
docker push -a $REPO_REGISTRY/${GITHUB_REPOSITORY#*/}-backend
working-directory: ./backend
build-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: setup node
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: login to github docker registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: publish frontend docker image to registry
env:
COMMIT_SHA: ${{ github.sha }}
REPO_REGISTRY: ghcr.io/${{ github.repository }}
run: |
docker build \
-t $REPO_REGISTRY/${GITHUB_REPOSITORY#*/}-frontend:${GITHUB_REF##*/} \
-t $REPO_REGISTRY/${GITHUB_REPOSITORY#*/}-frontend:$COMMIT_SHA \
-t $REPO_REGISTRY/${GITHUB_REPOSITORY#*/}-frontend:latest .
docker push -a $REPO_REGISTRY/${GITHUB_REPOSITORY#*/}-frontend
working-directory: ./frontend
deploy:
needs: [build-backend, build-frontend]
runs-on: ubuntu-latest
environment:
name: Production
url: 'https://batnoter.com'
steps:
- name: Setup kubectl with kubeconfig
uses: azure/k8s-set-context@v2
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}
- name: Create namespace if not exist
run: |
kubectl create namespace bn --dry-run=client -o yaml | kubectl apply -f -
- name: Set regcred secret
uses: azure/k8s-create-secret@v2
with:
namespace: 'bn'
secret-type: 'kubernetes.io/dockerconfigjson'
secret-name: 'regcred'
data: ${{ secrets.REGCRED_SECRET }}
- name: Set postgres-secret
uses: azure/k8s-create-secret@v2
with:
namespace: 'bn'
secret-type: 'generic'
secret-name: postgres-secret
data: ${{ secrets.POSTGRES_SECRET }}
- name: Set auth-secret
uses: azure/k8s-create-secret@v2
with:
namespace: 'bn'
secret-type: 'generic'
secret-name: auth-secret
data: ${{ secrets.AUTH_SECRET }}
- name: Setup helm
uses: azure/setup-helm@v1
- name: Deploy to production
run: |
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo add jetstack https://charts.jetstack.io
helm repo add batnoter https://vivekweb2013.github.io/batnoter-charts
helm repo update
helm upgrade ingress-nginx ingress-nginx/ingress-nginx -n ingress-nginx --create-namespace --install --wait --version v4.0.19 --set controller.publishService.enabled=true
helm upgrade cert-manager jetstack/cert-manager -n cert-manager --create-namespace --install --wait --version v1.8.0 --set installCRDs=true
helm upgrade batnoter batnoter/batnoter -n bn --create-namespace --install --wait