|
| 1 | +name: Build & Deploy Docs |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +env: |
| 9 | + REGISTRY: ghcr.io |
| 10 | + IMAGE: ghcr.io/${{ github.repository }} |
| 11 | + |
| 12 | +jobs: |
| 13 | + # ── Build docs Docker image ─────────────────────────────── |
| 14 | + build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + if: "!github.event.release.prerelease" |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + packages: write |
| 20 | + |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Log in to GitHub Container Registry |
| 25 | + uses: docker/login-action@v3 |
| 26 | + with: |
| 27 | + registry: ${{ env.REGISTRY }} |
| 28 | + username: ${{ github.actor }} |
| 29 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@v3 |
| 33 | + |
| 34 | + - name: Build and push |
| 35 | + uses: docker/build-push-action@v6 |
| 36 | + with: |
| 37 | + context: . |
| 38 | + file: .docker/Dockerfile |
| 39 | + push: true |
| 40 | + platforms: linux/amd64,linux/arm64 |
| 41 | + tags: | |
| 42 | + ${{ env.IMAGE }}:latest |
| 43 | + ${{ env.IMAGE }}:${{ github.event.release.tag_name || github.sha }} |
| 44 | + cache-from: type=gha,scope=docs |
| 45 | + cache-to: type=gha,mode=max,scope=docs |
| 46 | + |
| 47 | + # ── Deploy to production server ───────────────────────────── |
| 48 | + deploy: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + needs: [build] |
| 51 | + if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' |
| 52 | + |
| 53 | + steps: |
| 54 | + - name: Connect to WireGuard VPN |
| 55 | + run: | |
| 56 | + sudo apt-get install -y wireguard |
| 57 | + echo "${{ secrets.WG_CONFIG }}" | sudo tee /etc/wireguard/wg0.conf > /dev/null |
| 58 | + sudo chmod 600 /etc/wireguard/wg0.conf |
| 59 | + sudo wg-quick up wg0 |
| 60 | +
|
| 61 | + - name: Deploy via SSH |
| 62 | + uses: appleboy/ssh-action@v1 |
| 63 | + with: |
| 64 | + host: ${{ secrets.DEPLOY_HOST }} |
| 65 | + port: ${{ secrets.DEPLOY_SSH_PORT || 22 }} |
| 66 | + username: ${{ secrets.DEPLOY_USER }} |
| 67 | + key: ${{ secrets.DEPLOY_SSH_KEY }} |
| 68 | + script: | |
| 69 | + cd /servers/buggregator.dev.v2 |
| 70 | +
|
| 71 | + # Pull latest docs image |
| 72 | + docker compose pull buggregator-docs |
| 73 | +
|
| 74 | + # Restart docs container with new image |
| 75 | + docker compose up -d buggregator-docs |
| 76 | +
|
| 77 | + # Clean up old images |
| 78 | + docker image prune -f |
0 commit comments