Skip to content

Merge pull request #134 from null-open-security-community/main #14

Merge pull request #134 from null-open-security-community/main

Merge pull request #134 from null-open-security-community/main #14

Workflow file for this run

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 --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