feat: add Docker deployment with GitHub Actions #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Production | |
on: | |
push: | |
branches: [ main ] | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Copy files to server | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
source: "." | |
target: "/opt/court-allocation" | |
- name: Deploy to server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
cd /opt/court-allocation | |
# Build the new image | |
docker build -t court-allocation:latest . | |
# Stop and remove the existing container if it exists | |
docker stop court-allocation || true | |
docker rm court-allocation || true | |
# Run the new container | |
docker run -d \ | |
--name court-allocation \ | |
--restart unless-stopped \ | |
-p 80:7860 \ | |
court-allocation:latest | |
# Clean up old images | |
docker image prune -f |