-
Notifications
You must be signed in to change notification settings - Fork 9
119 lines (98 loc) · 3.37 KB
/
cd-prod.yaml
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
name: Deploy to Production
concurrency: prod
on:
workflow_dispatch:
env:
artifact-retention-days: 7
jobs:
build-backend:
name: Build Backend Image
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build Image with Tag
run: |
docker build --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod" .
docker save "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod" --output "bt-backend-prod.tar"
- name: Upload Image as Artifact
uses: actions/upload-artifact@v4
with:
name: "bt-backend-prod.tar"
path: "bt-backend-prod.tar"
retention-days: ${{ env.artifact-retention-days }}
overwrite: true
build-frontend:
name: Build Frontend Image
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build Image with Tag
run: |
docker build --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod" .
docker save "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod" --output "bt-frontend-prod.tar"
- name: Upload Image as Artifact
uses: actions/upload-artifact@v4
with:
name: "bt-frontend-prod.tar"
path: "bt-frontend-prod.tar"
retention-days: ${{ env.artifact-retention-days }}
overwrite: true
push-backend:
name: Push Backend Image
needs: build-backend
runs-on: ubuntu-latest
environment: prod
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Download Artifact as Image
uses: actions/download-artifact@v4
with:
name: "bt-backend-prod.tar"
- name: Push Image to Docker Hub
run: |
docker import "bt-backend-prod.tar" "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod"
docker push "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod"
push-frontend:
name: Push Frontend Image
needs: build-frontend
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Download Artifact as Image
uses: actions/download-artifact@v4
with:
name: "bt-frontend-prod.tar"
- name: Push Image to Docker Hub
run: |
docker import "bt-frontend-prod.tar" "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod"
docker push "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod"
deploy:
name: Deploy with SSH
needs: [push-backend, push-frontend]
runs-on: ubuntu-latest
steps:
- name: SSH and Helm Install
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: root
key: ${{ secrets.SSH_KEY }}
script: |
cd ./infra
if helm status bt-prod-app ; then
kubectl rollout restart bt-prod-app-backend
kubectl rollout restart bt-prod-app-frontend
else
helm install bt-prod-app ./app --namespace=bt \
--set host=stanfurdtime.com
fi