-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (56 loc) · 2.12 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
name: Deploy Frontend and Backend
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
service: [frontend, backend]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.service }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.service }}-
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
run: |
docker buildx build --cache-from type=local,src=/tmp/.buildx-cache --cache-to type=local,dest=/tmp/.buildx-cache-new --push --tag devruby/l2s-${{ matrix.service }}:latest ./${{ matrix.service }}
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
deploy:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
service: [frontend, backend]
steps:
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_PRIVATE_KEY }}
script: |
sudo docker stop l2s-${{ matrix.service }} || true
sudo docker rm l2s-${{ matrix.service }} || true
sudo docker image rm devruby/l2s-${{ matrix.service }} || true
sudo docker pull devruby/l2s-${{ matrix.service }}:latest
if [ "${{ matrix.service }}" == "frontend" ]; then
sudo docker run -d --name l2s-${{ matrix.service }} -p 3001:3000 devruby/l2s-${{ matrix.service }}:latest
else
sudo docker run -d --name l2s-${{ matrix.service }} -v l2s-data:/workspace/data -p 8001:8000 devruby/l2s-${{ matrix.service }}:latest
fi