Skip to content

feat: Add GitHub Actions workflow for deploying KeyCrypt app to Hetzner #1

feat: Add GitHub Actions workflow for deploying KeyCrypt app to Hetzner

feat: Add GitHub Actions workflow for deploying KeyCrypt app to Hetzner #1

Workflow file for this run

name: Deploy KeyCrypt App to Hetzner
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to Hetzner server
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
PROJECT_PATH: ${{ secrets.PROJECT_PATH }}
SERVICE_NAME: ${{ secrets.SERVICE_NAME }}
run: |
ssh -i ~/.ssh/id_ed25519 $SSH_USER@$SSH_HOST << EOF
set -e
cd $PROJECT_PATH
echo "Pulling latest changes..."
git pull origin master || { echo "Failed to pull changes"; exit 1; }
echo "Activating and updating virtual environment..."
# Ensure uv environment is properly activated
export VIRTUAL_ENV="$PROJECT_PATH/.venv"
export PATH="$VIRTUAL_ENV/bin:$PATH"
echo "Syncing dependencies..."
/home/keycrypt/.local/bin/uv sync || { echo "Failed to sync dependencies"; exit 1; }
echo "Running migrations..."
/home/keycrypt/.local/bin/uv run manage.py migrate --noinput || { echo "Failed to run migrations"; exit 1; }
echo "Collecting static files..."
/home/keycrypt/.local/bin/uv run manage.py collectstatic --noinput || { echo "Failed to collect static files"; exit 1; }
echo "Restarting service..."
sudo /bin/systemctl restart $SERVICE_NAME || { echo "Failed to restart service"; exit 1; }
echo "Deployment completed successfully"
EOF