|
| 1 | +name: Latest |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - .github/workflows/latest.yaml |
| 7 | + - latest/** |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + paths: |
| 12 | + - .github/workflows/latest.yaml |
| 13 | + - latest/** |
| 14 | + |
| 15 | +env: |
| 16 | + AWS_REGION: us-east-1 |
| 17 | + DOCKERHUB_SLUG: composer/composer |
| 18 | + ECR_SLUG: public.ecr.aws/u0u1j5s3/composer |
| 19 | + GHCR_SLUG: ghcr.io/composer/docker |
| 20 | + DIRECTORY: latest |
| 21 | + |
| 22 | +jobs: |
| 23 | + |
| 24 | + prepare: |
| 25 | + |
| 26 | + runs-on: ubuntu-latest |
| 27 | + |
| 28 | + outputs: |
| 29 | + full-annotations: ${{ steps.meta-full.outputs.annotations }} |
| 30 | + full-labels: ${{ steps.meta-full.outputs.labels }} |
| 31 | + full-json: ${{ steps.meta-full.outputs.json }} |
| 32 | + bin-annotations: ${{ steps.meta-bin.outputs.annotations }} |
| 33 | + bin-labels: ${{ steps.meta-bin.outputs.labels }} |
| 34 | + bin-json: ${{ steps.meta-bin.outputs.json }} |
| 35 | + |
| 36 | + steps: |
| 37 | + |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Determine Composer version from Dockerfile |
| 42 | + uses: ./.github/actions/determine-composer-version |
| 43 | + with: |
| 44 | + working-directory: ${{ env.DIRECTORY }} |
| 45 | + |
| 46 | + - name: Docker metadata (full image) |
| 47 | + id: meta-full |
| 48 | + uses: docker/metadata-action@v5 |
| 49 | + with: |
| 50 | + images: | |
| 51 | + ${{ env.DOCKERHUB_SLUG }} |
| 52 | + ${{ env.ECR_SLUG }} |
| 53 | + ${{ env.GHCR_SLUG }} |
| 54 | + flavor: | |
| 55 | + latest=false |
| 56 | + tags: | |
| 57 | + type=semver,pattern={{version}},value=${{ env.COMPOSER_VERSION_MAJOR_MINOR_PATCH }} |
| 58 | + type=semver,pattern={{major}}.{{minor}},value=${{ env.COMPOSER_VERSION_MAJOR_MINOR_PATCH }} |
| 59 | + latest |
| 60 | + labels: | |
| 61 | + org.opencontainers.image.vendor=Composer |
| 62 | + org.opencontainers.image.title=Composer |
| 63 | + org.opencontainers.image.description=PHP runtime image with Composer |
| 64 | +
|
| 65 | + - name: Docker metadata (binary-only image) |
| 66 | + id: meta-bin |
| 67 | + uses: docker/metadata-action@v5 |
| 68 | + with: |
| 69 | + images: | |
| 70 | + ${{ env.DOCKERHUB_SLUG }} |
| 71 | + ${{ env.ECR_SLUG }} |
| 72 | + ${{ env.GHCR_SLUG }} |
| 73 | + flavor: | |
| 74 | + latest=false |
| 75 | + suffix=-bin |
| 76 | + tags: | |
| 77 | + type=semver,pattern={{version}},value=${{ env.COMPOSER_VERSION_MAJOR_MINOR_PATCH }} |
| 78 | + type=semver,pattern={{major}}.{{minor}},value=${{ env.COMPOSER_VERSION_MAJOR_MINOR_PATCH }} |
| 79 | + lts |
| 80 | + labels: | |
| 81 | + org.opencontainers.image.vendor=Composer |
| 82 | + org.opencontainers.image.title=Composer |
| 83 | + org.opencontainers.image.description=Image with Composer binary only |
| 84 | +
|
| 85 | + build: |
| 86 | + |
| 87 | + runs-on: ubuntu-latest |
| 88 | + timeout-minutes: 20 |
| 89 | + |
| 90 | + needs: |
| 91 | + - prepare |
| 92 | + |
| 93 | + strategy: |
| 94 | + matrix: |
| 95 | + platform: |
| 96 | + - linux/amd64 |
| 97 | + - linux/arm/v6 |
| 98 | + - linux/arm/v7 |
| 99 | + - linux/arm64/v8 |
| 100 | + - linux/i386 |
| 101 | + - linux/ppc64le |
| 102 | + - linux/riscv64 |
| 103 | + - linux/s390x |
| 104 | + |
| 105 | + defaults: |
| 106 | + run: |
| 107 | + working-directory: ${{ env.DIRECTORY }} |
| 108 | + |
| 109 | + steps: |
| 110 | + |
| 111 | + - name: Checkout |
| 112 | + uses: actions/checkout@v4 |
| 113 | + |
| 114 | + - name: Prepare |
| 115 | + run: | |
| 116 | + platform=${{ matrix.platform }} |
| 117 | + echo "PLATFORM_SLUG=${platform//\//-}" >> $GITHUB_ENV |
| 118 | +
|
| 119 | + - name: Set up QEMU |
| 120 | + uses: docker/setup-qemu-action@v3 |
| 121 | + with: |
| 122 | + platforms: ${{ matrix.platform }} |
| 123 | + |
| 124 | + - name: Set up Docker Buildx |
| 125 | + uses: docker/setup-buildx-action@v3 |
| 126 | + |
| 127 | + - name: Login to Docker Hub |
| 128 | + #if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
| 129 | + uses: docker/login-action@v3 |
| 130 | + with: |
| 131 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 132 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 133 | + |
| 134 | + - name: Login to Amazon Public ECR |
| 135 | + #if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
| 136 | + uses: docker/login-action@v3 |
| 137 | + with: |
| 138 | + registry: public.ecr.aws |
| 139 | + username: ${{ secrets.AWS_ECR_ACCESS_KEY }} |
| 140 | + password: ${{ secrets.AWS_ECR_SECRET_KEY }} |
| 141 | + |
| 142 | + - name: Login to Github Container Registry |
| 143 | + #if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
| 144 | + uses: docker/login-action@v3 |
| 145 | + with: |
| 146 | + registry: ghcr.io |
| 147 | + username: ${{ github.repository_owner }} |
| 148 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 149 | + |
| 150 | + - name: Build full image |
| 151 | + id: build-full |
| 152 | + uses: docker/build-push-action@v5 |
| 153 | + with: |
| 154 | + context: ${{ env.DIRECTORY }} |
| 155 | + target: binary-with-runtime |
| 156 | + annotations: ${{ needs.prepare.outputs.full-annotations }} |
| 157 | + platforms: ${{ matrix.platform }} |
| 158 | + outputs: type=image,"name=${{ env.DOCKERHUB_SLUG }},${{ env.ECR_SLUG }},${{ env.GHCR_SLUG }}",push-by-digest=true,name-canonical=true,push=true #if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
| 159 | + |
| 160 | + - name: Build binary-only image |
| 161 | + id: build-bin |
| 162 | + uses: docker/build-push-action@v5 |
| 163 | + with: |
| 164 | + context: ${{ env.DIRECTORY }} |
| 165 | + target: standalone-binary |
| 166 | + annotations: ${{ needs.prepare.outputs.bin-annotations }} |
| 167 | + platforms: ${{ matrix.platform }} |
| 168 | + outputs: type=image,"name=${{ env.DOCKERHUB_SLUG }},${{ env.ECR_SLUG }},${{ env.GHCR_SLUG }}",push-by-digest=true,name-canonical=true,push=true #if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
| 169 | + |
| 170 | + - name: Export digests |
| 171 | + run: | |
| 172 | + mkdir -p /tmp/digests/{full,bin} |
| 173 | + digest="${{ steps.build-full.outputs.digest }}" |
| 174 | + touch "/tmp/digests/full/${digest#sha256:}" |
| 175 | + digest="${{ steps.build-bin.outputs.digest }}" |
| 176 | + touch "/tmp/digests/bin/${digest#sha256:}" |
| 177 | +
|
| 178 | + - name: Upload digests |
| 179 | + uses: actions/upload-artifact@v4 |
| 180 | + with: |
| 181 | + name: digests-${{ env.PLATFORM_SLUG }} |
| 182 | + path: | |
| 183 | + /tmp/digests/full/* |
| 184 | + /tmp/digests/bin/* |
| 185 | + if-no-files-found: error |
| 186 | + retention-days: 1 |
| 187 | + |
| 188 | + merge: |
| 189 | + |
| 190 | + #if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
| 191 | + |
| 192 | + runs-on: ubuntu-latest |
| 193 | + |
| 194 | + needs: |
| 195 | + - prepare |
| 196 | + - build |
| 197 | + |
| 198 | + steps: |
| 199 | + |
| 200 | + - name: Download digests |
| 201 | + uses: actions/download-artifact@v4 |
| 202 | + with: |
| 203 | + path: /tmp/digests |
| 204 | + pattern: digests-* |
| 205 | + merge-multiple: true |
| 206 | + |
| 207 | + - name: Set up Docker Buildx |
| 208 | + uses: docker/setup-buildx-action@v3 |
| 209 | + |
| 210 | + - name: Login to Docker Hub |
| 211 | + uses: docker/login-action@v3 |
| 212 | + with: |
| 213 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 214 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 215 | + |
| 216 | + - name: Login to Amazon Public ECR |
| 217 | + uses: docker/login-action@v3 |
| 218 | + with: |
| 219 | + registry: public.ecr.aws |
| 220 | + username: ${{ secrets.AWS_ECR_ACCESS_KEY }} |
| 221 | + password: ${{ secrets.AWS_ECR_SECRET_KEY }} |
| 222 | + |
| 223 | + - name: Login to Github Container Registry |
| 224 | + uses: docker/login-action@v3 |
| 225 | + with: |
| 226 | + registry: ghcr.io |
| 227 | + username: ${{ github.repository_owner }} |
| 228 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 229 | + |
| 230 | + - name: Create manifest list for full image and push |
| 231 | + working-directory: /tmp/digests/full |
| 232 | + env: |
| 233 | + JSON: ${{ needs.prepare.outputs.full-json }} |
| 234 | + run: | |
| 235 | + docker buildx imagetools create $(jq -cr '.tags | map(select(startswith("${{ env.DOCKERHUB_SLUG }}")) | "--tag " + .) | join(" ")' <<< "$JSON") \ |
| 236 | + $(printf '${{ env.DOCKERHUB_SLUG }}@sha256:%s ' *) |
| 237 | + docker buildx imagetools create $(jq -cr '.tags | map(select(startswith("${{ env.ECR_SLUG }}")) | "--tag " + .) | join(" ")' <<< "$JSON") \ |
| 238 | + $(printf '${{ env.ECR_SLUG }}@sha256:%s ' *) |
| 239 | + docker buildx imagetools create $(jq -cr '.tags | map(select(startswith("${{ env.GHCR_SLUG }}")) | "--tag " + .) | join(" ")' <<< "$JSON") \ |
| 240 | + $(printf '${{ env.GHCR_SLUG }}@sha256:%s ' *) |
| 241 | +
|
| 242 | + - name: Create manifest list for binary-only image and push |
| 243 | + working-directory: /tmp/digests/bin |
| 244 | + env: |
| 245 | + JSON: ${{ needs.prepare.outputs.bin-json }} |
| 246 | + run: | |
| 247 | + docker buildx imagetools create $(jq -cr '.tags | map(select(startswith("${{ env.DOCKERHUB_SLUG }}")) | "--tag " + .) | join(" ")' <<< "$JSON") \ |
| 248 | + $(printf '${{ env.DOCKERHUB_SLUG }}@sha256:%s ' *) |
| 249 | + docker buildx imagetools create $(jq -cr '.tags | map(select(startswith("${{ env.ECR_SLUG }}")) | "--tag " + .) | join(" ")' <<< "$JSON") \ |
| 250 | + $(printf '${{ env.ECR_SLUG }}@sha256:%s ' *) |
| 251 | + docker buildx imagetools create $(jq -cr '.tags | map(select(startswith("${{ env.GHCR_SLUG }}")) | "--tag " + .) | join(" ")' <<< "$JSON") \ |
| 252 | + $(printf '${{ env.GHCR_SLUG }}@sha256:%s ' *) |
0 commit comments