diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..8266df8 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,45 @@ +name: Deploy Production + +on: + push: + branches: [main] + +concurrency: + group: production-deploy + cancel-in-progress: true + +jobs: + deploy: + runs-on: self-hosted + + steps: + - name: Deploy portfolio Production + shell: bash + run: | + set -euo pipefail + + echo "============================" + echo " Starting deployment" + echo "============================" + + APP_DIR="/srv/apps/portfolio" + + cd "$APP_DIR" + + echo "Fetching latest code..." + git fetch origin main + + echo "Resetting local state..." + git reset --hard origin/main + + echo "Cleaning untracked files (keeping .env)" + git clean -fd -e .env + + echo "Pulling/building containers..." + docker compose pull || true + docker compose up -d --build --remove-orphans + + echo "Cleaning unused Docker images..." + docker image prune -f + + echo "Deployment finished successfully"