|
| 1 | +name: Build Docker |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | +concurrency: |
| 5 | + group: build-docker-${{ github.event_name }}-${{ github.ref }} |
| 6 | + cancel-in-progress: true |
| 7 | + |
| 8 | +jobs: |
| 9 | + prepare: |
| 10 | + name: Prepare |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + timeout-minutes: 5 # 2025-11-20: Takes just a few seconds. |
| 15 | + outputs: |
| 16 | + php-version: ${{ steps.buildargs.outputs.php-version }} |
| 17 | + composer-version: ${{ steps.buildargs.outputs.composer-version }} |
| 18 | + node-version: ${{ steps.buildargs.outputs.node-version }} |
| 19 | + pnpm-version: ${{ steps.buildargs.outputs.pnpm-version }} |
| 20 | + labels: ${{ steps.buildargs.outputs.labels }} |
| 21 | + tags: ${{ steps.buildargs.outputs.tags }} |
| 22 | + images: ${{ steps.buildargs.outputs.images }} |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v6 |
| 26 | + |
| 27 | + - name: Fetch build args |
| 28 | + id: buildargs |
| 29 | + env: |
| 30 | + LABELS: | |
| 31 | + org.opencontainers.image.title=Jetpack Development Environment |
| 32 | + org.opencontainers.image.description=Unified environment for developing in the Jetpack Monorepo using Docker containers. |
| 33 | + org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}/blob/trunk/tools/docker/README.md |
| 34 | + run: | |
| 35 | + source .github/versions.sh |
| 36 | + source .github/files/gh-funcs.sh |
| 37 | +
|
| 38 | + gh_set_output php-version "$PHP_VERSION" |
| 39 | + gh_set_output composer-version "$COMPOSER_VERSION" |
| 40 | + gh_set_output node-version "$NODE_VERSION" |
| 41 | + gh_set_output pnpm-version "$PNPM_VERSION" |
| 42 | + gh_set_output labels "$LABELS" |
| 43 | +
|
| 44 | + # We're not git-tagging for the env. Just tag all trunk builds as latest. |
| 45 | + if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then |
| 46 | + gh_set_output tags "type=raw,latest" |
| 47 | + gh_set_output images $'automattic/jetpack-wordpress-dev\nghcr.io/automattic/jetpack-wordpress-dev' |
| 48 | + elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then |
| 49 | + gh_set_output tags "type=ref,event=pr" |
| 50 | + gh_set_output images "ghcr.io/automattic/jetpack-wordpress-dev" |
| 51 | + elif [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then |
| 52 | + if [[ "$GITHUB_REF" == "refs/heads/trunk" ]]; then |
| 53 | + gh_set_output tags "type=raw,latest" |
| 54 | + gh_set_output images $'automattic/jetpack-wordpress-dev\nghcr.io/automattic/jetpack-wordpress-dev' |
| 55 | + else |
| 56 | + echo "Workflow dispatch for non-trunk ref $GITHUB_REF is not supported" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + else |
| 60 | + echo "Unknown GITHUB_EVENT_NAME $GITHUB_EVENT_NAME" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + build: |
| 65 | + name: Build Jetpack Dev Environment (${{ matrix.platform }}) |
| 66 | + runs-on: ${{ matrix.runner }} |
| 67 | + needs: prepare |
| 68 | + permissions: |
| 69 | + packages: write |
| 70 | + contents: read |
| 71 | + timeout-minutes: 15 # 2025-11-20: Arm64 build takes about 6 minutes, amd64 build about 3. |
| 72 | + strategy: |
| 73 | + matrix: |
| 74 | + include: |
| 75 | + - runner: ubuntu-latest |
| 76 | + platform: amd64 |
| 77 | + - runner: ubuntu-24.04-arm |
| 78 | + platform: arm64 |
| 79 | + |
| 80 | + steps: |
| 81 | + - uses: actions/checkout@v6 |
| 82 | + |
| 83 | + - name: Set up Docker Buildx |
| 84 | + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 |
| 85 | + |
| 86 | + - name: Log in to Docker Hub |
| 87 | + uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 |
| 88 | + with: |
| 89 | + username: matticbot |
| 90 | + password: ${{ secrets.DOCKER_HUB_MATTICBOT_TOKEN }} |
| 91 | + |
| 92 | + - name: Log in to GitHub Packages |
| 93 | + uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 |
| 94 | + with: |
| 95 | + registry: ghcr.io |
| 96 | + username: ${{ github.actor }} |
| 97 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + |
| 99 | + - name: Extract Docker metadata |
| 100 | + id: meta |
| 101 | + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 |
| 102 | + with: |
| 103 | + flavor: latest=false |
| 104 | + images: ${{ needs.prepare.outputs.images }} |
| 105 | + labels: ${{ needs.prepare.outputs.labels }} |
| 106 | + |
| 107 | + - name: Build and push by digest |
| 108 | + id: build |
| 109 | + uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0 |
| 110 | + with: |
| 111 | + context: tools/docker |
| 112 | + platforms: linux/${{ matrix.platform }} |
| 113 | + # For push by digest, the "tags" are just the images. We tag later. |
| 114 | + tags: ${{ needs.prepare.outputs.images }} |
| 115 | + labels: ${{ steps.meta.outputs.labels }} |
| 116 | + outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
| 117 | + build-args: | |
| 118 | + PHP_VERSION=${{ needs.prepare.outputs.php-version }} |
| 119 | + COMPOSER_VERSION=${{ needs.prepare.outputs.composer-version }} |
| 120 | + NODE_VERSION=${{ needs.prepare.outputs.node-version }} |
| 121 | + PNPM_VERSION=${{ needs.prepare.outputs.pnpm-version }} |
| 122 | +
|
| 123 | + - name: Export digest |
| 124 | + env: |
| 125 | + TEMP: ${{ runner.temp }} |
| 126 | + DIGEST: ${{ steps.build.outputs.digest }} |
| 127 | + run: | |
| 128 | + mkdir -p "$TEMP/digests" |
| 129 | + touch "$TEMP/digests/${DIGEST#sha256:}" |
| 130 | +
|
| 131 | + - name: Upload digest |
| 132 | + uses: actions/upload-artifact@v7 |
| 133 | + with: |
| 134 | + name: digests-linux-${{ matrix.platform }} |
| 135 | + path: ${{ runner.temp }}/digests/* |
| 136 | + if-no-files-found: error |
| 137 | + retention-days: 1 |
| 138 | + |
| 139 | + merge: |
| 140 | + name: Merge and publish Jetpack Dev Environment |
| 141 | + runs-on: ubuntu-latest |
| 142 | + needs: [ prepare, build ] |
| 143 | + permissions: |
| 144 | + packages: write |
| 145 | + contents: read |
| 146 | + timeout-minutes: 5 # 2025-11-20: Merge takes less than a minute. |
| 147 | + |
| 148 | + steps: |
| 149 | + - name: Download digests |
| 150 | + uses: actions/download-artifact@v8 |
| 151 | + with: |
| 152 | + path: ${{ runner.temp }}/digests |
| 153 | + pattern: digests-* |
| 154 | + merge-multiple: true |
| 155 | + |
| 156 | + - name: Set up Docker Buildx |
| 157 | + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 |
| 158 | + |
| 159 | + - name: Log in to Docker Hub |
| 160 | + uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 |
| 161 | + with: |
| 162 | + username: matticbot |
| 163 | + password: ${{ secrets.DOCKER_HUB_MATTICBOT_TOKEN }} |
| 164 | + |
| 165 | + - name: Log in to GitHub Packages |
| 166 | + uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 |
| 167 | + with: |
| 168 | + registry: ghcr.io |
| 169 | + username: ${{ github.actor }} |
| 170 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 171 | + |
| 172 | + - name: Extract Docker metadata |
| 173 | + id: meta |
| 174 | + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 |
| 175 | + with: |
| 176 | + flavor: latest=false |
| 177 | + tags: ${{ needs.prepare.outputs.tags }} |
| 178 | + images: ${{ needs.prepare.outputs.images }} |
| 179 | + labels: ${{ needs.prepare.outputs.labels }} |
| 180 | + |
| 181 | + - name: Create manifest list and push |
| 182 | + working-directory: ${{ runner.temp }}/digests |
| 183 | + run: | |
| 184 | + while IFS= read -r IMAGE; do |
| 185 | + echo "=== $IMAGE ===" |
| 186 | + docker buildx imagetools create $(jq -cr --arg IMG "$IMAGE" '.tags | map( select( startswith( $IMG + ":" ) ) | "-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 187 | + $(printf "$IMAGE@sha256:%s " *) |
| 188 | + done < <( jq -r '.tags[] | sub( ":.*"; "" )' <<< "$DOCKER_METADATA_OUTPUT_JSON" ) |
| 189 | +
|
| 190 | + - name: Inspect image |
| 191 | + env: |
| 192 | + VERSION: ${{ steps.meta.outputs.version }} |
| 193 | + run: | |
| 194 | + while IFS= read -r IMAGE; do |
| 195 | + echo "=== $IMAGE ===" |
| 196 | + docker buildx imagetools inspect "$IMAGE:$VERSION" |
| 197 | + done < <( jq -r '.tags[] | sub( ":.*"; "" )' <<< "$DOCKER_METADATA_OUTPUT_JSON" ) |
0 commit comments