Skip to content

Commit c9022d7

Browse files
chore: github action for staging
1 parent 83612bc commit c9022d7

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches:
6+
- "staging"
7+
8+
env:
9+
IMAGE_NAME: "project_badging_staging"
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Remove old Docker images
17+
uses: appleboy/[email protected]
18+
with:
19+
host: ${{ secrets.HOST }}
20+
username: ${{ secrets.USERNAME }}
21+
password: ${{ secrets.PASSWORD }}
22+
script: |
23+
if docker inspect ${{ env.IMAGE_NAME }} >/dev/null 2>&1; then
24+
docker stop ${{ env.IMAGE_NAME }}
25+
docker rm ${{ env.IMAGE_NAME }}
26+
docker images --filter "reference=${{ env.IMAGE_NAME }}*" -q | xargs docker rmi -f || true
27+
fi
28+
29+
- name: Build Docker image
30+
run: docker build -t ${{ env.IMAGE_NAME }}:${{ github.sha }} .
31+
32+
- name: Create image archive
33+
run: docker save ${{ env.IMAGE_NAME }}:${{ github.sha }} -o badging-staging.tar
34+
35+
- name: Upload image archive using appleboy/scp-action
36+
uses: appleboy/[email protected]
37+
with:
38+
host: ${{ secrets.HOST }}
39+
username: ${{ secrets.USERNAME }}
40+
password: ${{ secrets.PASSWORD }}
41+
source: badging.tar
42+
target: ~/
43+
44+
- name: Extract and load image on droplet
45+
uses: appleboy/[email protected]
46+
with:
47+
host: ${{ secrets.HOST }}
48+
username: ${{ secrets.USERNAME }}
49+
password: ${{ secrets.PASSWORD }}
50+
script: |
51+
docker load -i ~/badging-staging.tar
52+
docker run -d \
53+
-p ${{ secrets.PORT }}:${{ secrets.PORT }} \
54+
--env-file /home/${{ secrets.USERNAME }}/staging/.env \
55+
--network host \
56+
--restart=always \
57+
--name ${{ env.IMAGE_NAME }} \
58+
${{ env.IMAGE_NAME }}:${{ github.sha }}

0 commit comments

Comments
 (0)