-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (160 loc) · 6.82 KB
/
boolock-dev-cicd.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: ci/cd action
on:
push:
branches: ['dev']
pull_request:
branches: ['dev']
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ hashFiles('Dockerfile', 'Dockerfile.base', 'docker-compose.yml') }}
restore-keys: |
${{ runner.os }}-docker-
- name: Set BE .env
run: |
echo "MONGO_URI=${{ secrets.DEPLOY_MONGO_URI }}" > apps/server/.env
echo "IS_LOCAL=false" >> apps/server/.env
echo "SERVER_CORS_ACCEPT=${{ secrets.DEPLOY_SERVER_CORS_ACCEPT }}" >> apps/server/.env
echo "S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }}" >> apps/server/.env
echo "S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }}" >> apps/server/.env
echo "S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}" >> apps/server/.env
echo "NODE_ENV=production" >> apps/server/.env
- name: Set FE .env
run: |
echo "VITE_SERVER_URL=${{ secrets.DEPLOY_VITE_SERVER_URL }}" > apps/client/.env
echo "VITE_MIXPANEL_TOKEN=${{ secrets.VITE_MIXPANEL_TOKEN }}" >> apps/client/.env
echo "VITE_STATIC_STORAGE_URL=${{ secrets.VITE_STATIC_STORAGE_URL }}" >> apps/client/.env
- name: Set Nginx SSL files
run: |
mkdir -p apps/client/ssl
echo "${{ secrets.SSL_FULLCHAIN }}" > apps/client/ssl/fullchain.pem
echo "${{ secrets.SSL_PRIVKEY }}" > apps/client/ssl/privkey.pem
# - name: Clear Docker Cache
# run: |
# docker builder prune --all --force
# docker image prune --all --force
# - name: Build and Push Base Image
# uses: docker/build-push-action@v4
# with:
# context: .
# file: Dockerfile.base
# push: true
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest
# cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest,mode=max
# cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest,mode=max
# outputs: type=docker
- name: Build and Save Base Image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile.base
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest,mode=max
cache-to: |
type=inline
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest,mode=max
- name: Pull Base Image (Remote)
run: docker pull docker.io/${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest
- name: Verify Base Image
run: docker images ${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest
- name: Retag Base Image Locally
run: docker tag ${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest base-image:latest
- name: Save Base Image to File
run: docker save base-image:latest -o base-image.tar
- name: Load Base Image from File
run: docker load -i base-image.tar
- name: Build and Push Frontend Image
uses: docker/build-push-action@v4
with:
context: .
file: apps/client/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/boolock_client_test:latest
cache-from: |
type=inline
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/boolock_client_test:latest,mode=max
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/boolock_client_test:latest,mode=max
build-args: |
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
- name: Build and Push Backend Image
uses: docker/build-push-action@v4
with:
context: .
file: apps/server/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/boolock_server_test:latest
cache-from: |
type=inline
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/boolock_server_test:latest,mode=max
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/boolock_server_test:latest,mode=max
build-args: |
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
# - name: Build and Push Base Image
# uses: docker/build-push-action@v4
# with:
# context: .
# file: Dockerfile.base
# push: true
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/base-image:latest
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache
# - name: Build and Push Frontend Image
# uses: docker/build-push-action@v4
# with:
# context: .
# file: apps/client/Dockerfile
# push: true
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/boolock_client_test:latest
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache
# build-args: |
# DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
# - name: Build and Push Backend Image
# uses: docker/build-push-action@v4
# with:
# context: .
# file: apps/server/Dockerfile
# push: true
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/boolock_server_test:latest
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache
# build-args: |
# DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy with docker
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
cd boolock/refactor-web31-BooLock
git fetch origin
git checkout refactor/13
git pull origin refactor/13
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" > .env
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
sudo docker compose pull
sudo docker compose down
sudo docker compose up -d