Add docker compose and traefik #5
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 | |
# Pull latest changes and rebuild | |
docker-compose pull || true | |
docker-compose build --no-cache | |
# Bring down existing containers | |
docker-compose down | |
# Start new containers | |
docker-compose up -d | |
# Clean up | |
docker image prune -f | |
# Wait for the application to start | |
echo "Waiting for application to start..." | |
sleep 10 | |
# Health check | |
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:80) | |
if [ $response -eq 200 ]; then | |
echo "Health check passed: Application is running" | |
else | |
echo "Health check failed: Application is not responding (Status code: $response)" | |
exit 1 | |
fi |