-
Notifications
You must be signed in to change notification settings - Fork 7
58 lines (51 loc) · 1.78 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
name: CI/CD
on:
push:
branches:
- "main"
env:
IMAGE_NAME: "project_badging"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Remove old Docker images
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
if docker inspect ${{ env.IMAGE_NAME }} >/dev/null 2>&1; then
docker stop ${{ env.IMAGE_NAME }}
docker rm ${{ env.IMAGE_NAME }}
docker images --filter "reference=${{ env.IMAGE_NAME }}*" -q | xargs docker rmi -f || true
fi
- name: Build Docker image
run: docker build -t ${{ env.IMAGE_NAME }}:${{ github.sha }} .
- name: Create image archive
run: docker save ${{ env.IMAGE_NAME }}:${{ github.sha }} -o badging.tar
- name: Upload image archive using appleboy/scp-action
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: badging.tar
target: ~/
- name: Extract and load image on droplet
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
docker load -i ~/badging.tar
docker run -d \
-p ${{ secrets.PORT }}:${{ secrets.PORT }} \
--env-file /home/${{ secrets.USERNAME }}/.env \
--network host \
--restart=always \
--name ${{ env.IMAGE_NAME }} \
${{ env.IMAGE_NAME }}:${{ github.sha }}