name: Build & Deploy on: push # push: # branches: [main] env: REGISTRY: ${{ gitea.server_url && 'git.aggtaa.com' || 'localhost' }} IMAGE_PREFIX: ${{ gitea.repository }} # owner/blockly3d jobs: # ── BUILD SERVER ───────────────────────────────────────────────────────────── build-server: runs-on: ubuntu-latest if: | contains(toJSON(github.event.commits.*.modified), 'server/') || contains(toJSON(github.event.commits.*.modified), 'pnpm-lock.yaml') || contains(toJSON(github.event.commits.*.modified), 'server.Dockerfile') steps: - uses: actions/checkout@v4 - name: Login to Gitea Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build & push server uses: docker/build-push-action@v5 with: context: . file: server.Dockerfile push: true tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/server:latest ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/server:${{ gitea.sha }} cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/server:cache cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/server:cache,mode=max # ── BUILD WEBCLIENT ─────────────────────────────────────────────────────────── build-webclient: runs-on: ubuntu-latest if: | contains(toJSON(github.event.commits.*.modified), 'webclient/') || contains(toJSON(github.event.commits.*.modified), 'pnpm-lock.yaml') || contains(toJSON(github.event.commits.*.modified), 'webclient.Dockerfile') steps: - uses: actions/checkout@v4 - name: Login to Gitea Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build & push webclient uses: docker/build-push-action@v5 with: context: . file: webclient.Dockerfile push: true tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/webclient:latest ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/webclient:${{ gitea.sha }} cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/webclient:cache cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/webclient:cache,mode=max # ── DEPLOY ──────────────────────────────────────────────────────────────────── deploy: runs-on: ubuntu-latest needs: [build-server, build-webclient] # Запускается даже если один из build-job-ов был пропущен if: always() && !failure() && !cancelled() steps: - name: Deploy via SSH uses: appleboy/ssh-action@v1 with: host: ${{ secrets.DEPLOY_HOST }} username: ${{ secrets.DEPLOY_USER }} key: ${{ secrets.DEPLOY_SSH_KEY }} script: | cd /opt/blockly3d git pull origin main docker compose pull docker compose up -d --remove-orphans docker image prune -f