name: build and deploy on: push: branches: [main] pull_request: branches: [main] env: REGISTRY: ghcr.io jobs: build: name: build ${{ matrix.service }} runs-on: ubuntu-latest permissions: contents: read packages: write strategy: fail-fast: false matrix: service: [fetcher, generator, edge] outputs: image_tag: ${{ steps.tag.outputs.value }} steps: - uses: actions/checkout@v4 - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - name: Log in to GHCR if: github.event_name == 'push' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Compute image tag (sha-) id: tag env: SHA: ${{ github.sha }} run: echo "value=sha-${SHA:0:7}" >> "$GITHUB_OUTPUT" - name: Compute image name (lowercase) id: img env: OWNER: ${{ github.repository_owner }} SERVICE: ${{ matrix.service }} run: echo "name=${REGISTRY}/${OWNER,,}/ghstats-${SERVICE}" >> "$GITHUB_OUTPUT" - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ steps.img.outputs.name }} tags: | type=raw,value=${{ steps.tag.outputs.value }} type=raw,value=latest,enable={{is_default_branch}} - name: Build ${{ matrix.service }} image uses: docker/build-push-action@v6 with: context: ./${{ matrix.service }} platforms: linux/amd64,linux/arm64 push: ${{ github.event_name == 'push' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha,scope=${{ matrix.service }} cache-to: type=gha,mode=max,scope=${{ matrix.service }} deploy: name: deploy to mini PC needs: build if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: self-hosted steps: - uses: actions/checkout@v4 - name: Deploy compose stack env: IMAGE_TAG: ${{ needs.build.outputs.image_tag }} GITHUB_PAT: ${{ secrets.FETCHER_GITHUB_PAT }} FETCHER_INTERNAL_TOKEN: ${{ secrets.FETCHER_INTERNAL_TOKEN }} GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }} GH_OAUTH_CLIENT_SECRET: ${{ secrets.GH_OAUTH_CLIENT_SECRET }} GENERATOR_SECRET_KEY: ${{ secrets.GENERATOR_SECRET_KEY }} ALLOWED_ORIGINS: ${{ secrets.ALLOWED_ORIGINS }} DEV_DASHBOARD_USER: ${{ secrets.DEV_DASHBOARD_USER }} DEV_DASHBOARD_PASSWORD: ${{ secrets.DEV_DASHBOARD_PASSWORD }} run: ./deploy/deploy.sh