Skip to content

Deploy to Hetzner

Deploy to Hetzner #57

Workflow file for this run

name: Deploy to Hetzner
on:
push:
branches: [main]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build
run: bun run build
- name: Prepare standalone output
run: |
cp -r .next/static .next/standalone/.next/static
cp -r public .next/standalone/public
- name: Setup Tailscale
uses: tailscale/github-action@v3
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -p 1993 -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts
- name: Deploy standalone to server
run: |
rsync -avz --delete \
-e "ssh -i ~/.ssh/deploy_key -p 1993" \
.next/standalone/ ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/
- name: Write .env file
run: |
ssh -i ~/.ssh/deploy_key -p 1993 ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} "printf '%s\n' \
'PORT=3001' \
'HOSTNAME=127.0.0.1' \
'ANALYTICS_KEY=${{ secrets.ANALYTICS_KEY }}' \
'REDIS_URL=${{ secrets.REDIS_URL }}' \
> ${{ secrets.DEPLOY_PATH }}/.env"
- name: Restart PM2
run: |
ssh -i ~/.ssh/deploy_key -p 1993 ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} "\
cd ${{ secrets.DEPLOY_PATH }} && \
pm2 delete prayCalendar 2>/dev/null || true && \
set -a && source .env && set +a && \
HOSTNAME=127.0.0.1 pm2 start server.js --name prayCalendar && \
pm2 save"