diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..1f89371 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,66 @@ +name: Deploy to LXC + +on: + push: + branches: [main] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Deploy via SSH + uses: appleboy/ssh-action@v1 + with: + host: ${{ secrets.DEPLOY_HOST }} + username: ${{ secrets.DEPLOY_USER }} + key: ${{ secrets.DEPLOY_KEY }} + port: ${{ secrets.DEPLOY_PORT || 22 }} + script: | + set -e + + APP_DIR="${{ secrets.DEPLOY_PATH || '/opt/buildfor-life-budget' }}" + + # Set up deploy key for private repo access + mkdir -p ~/.ssh + echo "${{ secrets.REPO_DEPLOY_KEY }}" > ~/.ssh/repo_deploy_key + chmod 600 ~/.ssh/repo_deploy_key + + # Configure SSH to use deploy key for git.b4l.co.th + if ! grep -q "git.b4l.co.th" ~/.ssh/config 2>/dev/null; then + cat >> ~/.ssh/config < First deploy, cloning..." + git clone git@git.b4l.co.th:B4L/buildfor_life_budget.git "$APP_DIR" + cd "$APP_DIR" + else + cd "$APP_DIR" + echo "==> Resetting local changes..." + git checkout -- . + echo "==> Pulling latest code..." + git pull origin main + fi + + echo "==> Installing dependencies..." + npm ci + + echo "==> Building..." + npm run build + + echo "==> Running migrations..." + npm run db:push + + echo "==> Restarting service..." + sudo systemctl restart buildfor-life-budget + + echo "==> Waiting for startup..." + sleep 2 + systemctl is-active --quiet buildfor-life-budget && echo "Deploy successful!" || (echo "Service failed to start!" && exit 1)