Merge pull request #16 from safe1ine/main #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ci | |
| on: | |
| pull_request: | |
| paths: | |
| - "docker/**" | |
| - "scripts/**" | |
| - ".github/workflows/**" | |
| - "README.md" | |
| push: | |
| branches: [main] | |
| tags: ["*"] | |
| env: | |
| REGISTRY: ghcr.io/chaitin/monkeycode-runner | |
| # Default to TUNA mirrors (optimized for mainland China/Asia). You can override these | |
| # per repo/org by defining GitHub variables DEBIAN_MIRROR and DEBIAN_SECURITY_MIRROR | |
| # if runners are primarily located elsewhere and builds are slow. | |
| DEBIAN_MIRROR: ${{ vars.DEBIAN_MIRROR || 'https://mirrors.tuna.tsinghua.edu.cn/debian' }} | |
| DEBIAN_SECURITY_MIRROR: ${{ vars.DEBIAN_SECURITY_MIRROR || 'https://mirrors.tuna.tsinghua.edu.cn/debian-security' }} | |
| jobs: | |
| build-base: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| STACK: base | |
| VERSION: bookworm | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.STACK }} | |
| tags: | | |
| type=raw,value=${{ env.VERSION }} | |
| type=raw,value=${{ env.VERSION }}-${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/heads/') && github.ref != 'refs/heads/main' }} | |
| type=ref,event=tag | |
| type=raw,value=${{ env.VERSION }}-${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }} | |
| type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| if: github.event_name == 'push' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build base (no push on PR) | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: docker/${{ env.STACK }}/${{ env.VERSION }}/Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| DEBIAN_MIRROR=${{ env.DEBIAN_MIRROR }} | |
| DEBIAN_SECURITY_MIRROR=${{ env.DEBIAN_SECURITY_MIRROR }} | |
| push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
| build-stacks: | |
| needs: build-base | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - stack: devbox | |
| version: bookworm | |
| - stack: golang | |
| version: 1.25-bookworm | |
| - stack: frontend | |
| version: node20 | |
| - stack: rust | |
| version: 1.91-bookworm | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| STACK: ${{ matrix.stack }} | |
| VERSION: ${{ matrix.version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ matrix.stack }} | |
| tags: | | |
| type=raw,value=${{ matrix.version }} | |
| type=raw,value=${{ matrix.version }}-${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/heads/') && github.ref != 'refs/heads/main' }} | |
| type=ref,event=tag | |
| type=raw,value=${{ matrix.version }}-${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }} | |
| type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| if: github.event_name == 'push' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build (no push on PR) | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: docker/${{ matrix.stack }}/${{ matrix.version }}/Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |