|
| 1 | +name: Build and Push Dependency Images |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: [ main ] |
| 7 | + paths: |
| 8 | + - 'install_deps.sh' |
| 9 | + - 'docker/Dockerfile.deps' |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + # amd64 和 arm64 都用各自架构的原生 runner 构建(和 create-release.yml 的策略保持一致), |
| 17 | + # 不使用 QEMU 模拟,避免影响构建速度。 |
| 18 | + build: |
| 19 | + runs-on: ${{ matrix.os }} |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + packages: write |
| 23 | + strategy: |
| 24 | + matrix: |
| 25 | + os: [ubuntu-latest, ubuntu-24.04-arm] |
| 26 | + version: ["ubuntu:noble", "ubuntu:jammy", "ubuntu:focal", "debian:trixie", "debian:bookworm", "debian:bullseye"] |
| 27 | + fail-fast: false |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v5 |
| 32 | + |
| 33 | + - name: Set up Docker Buildx |
| 34 | + uses: docker/setup-buildx-action@v3 |
| 35 | + |
| 36 | + - name: Log in to Container Registry |
| 37 | + uses: docker/login-action@v3 |
| 38 | + with: |
| 39 | + registry: ${{ env.REGISTRY }} |
| 40 | + username: ${{ github.actor }} |
| 41 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + |
| 43 | + - name: Compute image tag |
| 44 | + id: vars |
| 45 | + run: | |
| 46 | + CODENAME=$(echo "${{ matrix.version }}" | cut -d':' -f2) |
| 47 | + ARCH="amd64" |
| 48 | + [[ "${{ matrix.os }}" == *arm* ]] && ARCH="arm64" |
| 49 | + echo "codename=${CODENAME}" >> $GITHUB_OUTPUT |
| 50 | + echo "arch=${ARCH}" >> $GITHUB_OUTPUT |
| 51 | +
|
| 52 | + - name: Build and push |
| 53 | + uses: docker/build-push-action@v5 |
| 54 | + with: |
| 55 | + context: . |
| 56 | + file: ./docker/Dockerfile.deps |
| 57 | + build-args: | |
| 58 | + BASE_IMAGE=${{ matrix.version }} |
| 59 | + push: true |
| 60 | + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:deps-${{ steps.vars.outputs.codename }}-${{ steps.vars.outputs.arch }} |
| 61 | + cache-from: type=gha,scope=deps-${{ steps.vars.outputs.codename }}-${{ steps.vars.outputs.arch }} |
| 62 | + cache-to: type=gha,mode=max,scope=deps-${{ steps.vars.outputs.codename }}-${{ steps.vars.outputs.arch }} |
0 commit comments