Skip to content
name: 🚀 Deploy To Production Workflow
on:
release:
types: [ created ]
jobs:
upload-to-docker-hub:
name: Upload image with tag version to Docker Hub 🐳
runs-on: ubuntu-latest
strategy:
matrix:
tag:
- ${{ github.event.release.tag_name }}
- latest
steps:
- name: Checkout GitHub repository 📡
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
fetch-depth: 0
fetch-tags: true
- name: Log in to Docker Hub 🔐
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build and push Docker image 🐳
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: antoinezanardi/werewolves-assistant-api:${{ matrix.tag }}
deploy-to-production:
name: Deploy to production server 🚀
runs-on: ubuntu-latest
needs: upload-to-docker-hub
steps:
- name: Deploy to production server 🚀
env:
SSH_PRIVATE_KEY: ${{ secrets.PRODUCTION_SERVER_SSH_PRIVATE_KEY }}
SSH_USER: ${{ secrets.PRODUCTION_SERVER_SSH_USER }}
SSH_SERVER_IP: ${{ secrets.PRODUCTION_SERVER_SSH_ADDRESS }}
UPDATE_SCRIPT_FULL_PATH: ${{ secrets.PRODUCTION_UPDATE_SCRIPT_FULL_PATH }}
run: |
eval $(ssh-agent -s)
echo "$SSH_PRIVATE_KEY" | ssh-add -
ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_SERVER_IP << EOF
$UPDATE_SCRIPT_FULL_PATH
EOF