-
Notifications
You must be signed in to change notification settings - Fork 8
48 lines (40 loc) · 1.74 KB
/
staging.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 Staging
on:
push:
branches:
- staging
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
run: |
docker build . -t null_jobs_backend:latest
- name: Save Docker image as tar
if: success()
run: docker save null_jobs_backend:latest > null_job_backend_latest.tar
- name: Transfer Docker image to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: null_job_backend_latest.tar
target: /tmp/null_job_backend_latest.tar
- name: SSH into server and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
docker load -i /tmp/null_job_backend_latest.tar/null_job_backend_latest.tar
docker stop null_jobs_backend || true
docker rm null_jobs_backend || true
docker run -d --network null_jobs -v /home/dev@null/projects/nulljobs/backend/media:/workspace/media --env-file /home/dev@null/projects/nulljobs/backend/.env null_jobs_backend:latest python manage.py migrate
docker run -d --name null_jobs_backend --network null_jobs --restart always --env-file /home/dev@null/projects/nulljobs/backend/.env null_jobs_backend:latest python manage.py runserver 0.0.0.0:8000
rm -r /tmp/null_job_backend_latest.tar