-
Notifications
You must be signed in to change notification settings - Fork 0
48 lines (39 loc) · 1.43 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
name: Deploy to server
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker image
run: |
docker buildx build --platform linux/amd64 -t bluescript:latest .
- name: Save Docker image as tarball
run: |
docker save bluescript:latest | gzip > bluescript.tar.gz
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add server to known_hosts
run: ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
- name: Transfer Docker image to server
run: |
scp bluescript.tar.gz ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:${{ secrets.SERVER_DEPLOY_PATH }}
- name: Deploy Docker container on server
run: |
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} << 'ENDSSH'
cd ${{ secrets.SERVER_DEPLOY_PATH }}
gunzip -c bluescript.tar.gz | sudo docker load
sudo docker stop bluescript || true
sudo docker rm bluescript || true
sudo docker run -d --name bluescript --network web bluescript:latest
sudo docker system prune -f --volumes
ENDSSH