|
7 | 7 | push: |
8 | 8 | branches: |
9 | 9 | - 'v5' |
| 10 | + - 'feat/split-multi-arch-build' # FIXME test |
10 | 11 | schedule: |
11 | 12 | - cron: '42 3 * * 0' |
12 | 13 | workflow_dispatch: |
13 | 14 |
|
14 | 15 | jobs: |
15 | | - test: |
| 16 | + build: |
16 | 17 | strategy: |
17 | 18 | fail-fast: false |
18 | 19 | matrix: |
19 | | - php_version: ['8.5', '8.4', '8.3','8.2','8.1'] |
| 20 | +# php_version: ['8.5', '8.4', '8.3','8.2','8.1'] |
| 21 | + php_version: ['8.5'] |
20 | 22 | variant: ['apache','cli','fpm'] |
21 | | -# builder: [ {arch: "amd64", os: "ubuntu-latest"}, {arch: "arm64", os: "macos-latest"}] |
22 | | - builder: [ {arch: "amd64", os: "ubuntu-24.04"}, {arch: "arm64", os: "ubuntu-24.04"}] |
| 23 | + builder: [ {arch: "amd64", os: "ubuntu-24.04"}, {arch: "arm64", os: "ubuntu-24.04-arm"}] |
23 | 24 | runs-on: ${{ matrix.builder.os }} |
24 | | - name: Test ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }} only |
| 25 | + name: Build&test ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }} |
25 | 26 | steps: |
26 | 27 | - name: Checkout |
27 | 28 | uses: actions/checkout@v4 |
28 | 29 | - name: Set up Docker |
29 | | - # /!\ this action is marked as experimental |
30 | | - # It's required only for macos |
31 | | - if: ${{ matrix.builder.os == 'macos-latest' }} |
32 | 30 | uses: docker-practice/actions-setup-docker@master |
33 | | - - name: Set up QEMU |
34 | | - uses: docker/setup-qemu-action@v3 |
| 31 | + - name: Login to GHCR |
| 32 | + uses: docker/login-action@v3 |
| 33 | + with: |
| 34 | + registry: ghcr.io |
| 35 | + username: ${{ github.actor }} |
| 36 | + password: ${{ secrets.GITHUB_TOKEN }} |
35 | 37 | - name: Set up Docker Buildx |
36 | 38 | uses: docker/setup-buildx-action@v3 |
37 | 39 | - name: Build |
38 | 40 | run: | |
39 | 41 | PHP_VERSION="${{ matrix.php_version }}" |
| 42 | + # Get last cached successful builds |
| 43 | + TAGS=$(REPO="ghcr.io/${{ github.repository_owner }}/php" TAG_PREFIX="" docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --progress=quiet --print | jq -r '.target[].tags[]') |
| 44 | + for TAG in $TAGS; do |
| 45 | + docker pull --quiet ${TAG} || echo "" |
| 46 | + done; |
| 47 | + # Build the current builds |
| 48 | + REPO="ghcr.io/${{ github.repository_owner }}/php" \ |
| 49 | + ARCH_SUFFIX="-${{ matrix.builder.arch }}" \ |
40 | 50 | TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ |
41 | 51 | docker buildx bake \ |
42 | 52 | --set "*.platform=linux/${{ matrix.builder.arch }}" \ |
43 | 53 | --set "*.output=type=docker" \ |
44 | | - --load \ |
| 54 | + --load --progress=quiet \ |
45 | 55 | php${PHP_VERSION//.}-${{ matrix.variant }}-all |
46 | 56 | - name: Display tags built |
47 | 57 | run: | |
48 | | - docker image ls --filter="reference=thecodingmachine/php" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}" |
| 58 | + docker image ls --filter="reference=ghcr.io/${{ github.repository_owner }}/php" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}" |
49 | 59 | - name: Test |
50 | 60 | run: | |
| 61 | + REPO="ghcr.io/${{ github.repository_owner }}/php" \ |
51 | 62 | TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ |
52 | 63 | PHP_VERSION="${{ matrix.php_version }}" \ |
| 64 | + ARCH_SUFFIX="-${{ matrix.builder.arch }}" \ |
53 | 65 | BRANCH="v5" \ |
54 | 66 | VARIANT="${{ matrix.variant }}" \ |
55 | 67 | PLATFORM="linux/${{ matrix.builder.arch }}" \ |
56 | 68 | ./tests-suite/bash_unit -f tap ./tests-suite/*.sh |
| 69 | + - name: Publish specific arch version |
| 70 | + if: > # Only from the main repo |
| 71 | + github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || |
| 72 | + (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) |
| 73 | + run: | |
| 74 | + PHP_VERSION="${{ matrix.php_version }}" |
| 75 | + TAGS=$(REPO="ghcr.io/${{ github.repository_owner }}/php" \ |
| 76 | + ARCH_SUFFIX="-${{ matrix.builder.arch }}" \ |
| 77 | + TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ |
| 78 | + docker buildx bake \ |
| 79 | + --print --progress=quiet \ |
| 80 | + php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq -r '.target[].tags[]'); |
| 81 | + for TAG in $TAGS; do docker push --quiet ${TAG}; done; |
57 | 82 |
|
58 | | - publish: |
59 | | - # push ~ schedule |
| 83 | + merge-and-publish: |
60 | 84 | if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} |
61 | 85 | needs: |
62 | | - - test |
| 86 | + - build |
63 | 87 | runs-on: ubuntu-latest |
64 | | - name: Publish ${{ matrix.php_version }}-${{ matrix.variant }} multi-arch to dockerhub |
| 88 | + name: Merge and publish ${{ matrix.php_version }}-${{ matrix.variant }} |
65 | 89 | strategy: |
66 | 90 | fail-fast: false |
67 | 91 | matrix: |
68 | | - php_version: ['8.5', '8.4', '8.3','8.2','8.1'] |
| 92 | +# php_version: ['8.5', '8.4', '8.3','8.2','8.1'] |
| 93 | + php_version: ['8.5'] |
69 | 94 | variant: ['apache','cli','fpm'] |
70 | 95 | steps: |
71 | 96 | - name: Checkout |
72 | 97 | uses: actions/checkout@v4 |
73 | | - - name: Set up QEMU |
74 | | - uses: docker/setup-qemu-action@v3 |
75 | 98 | - name: Set up Docker Buildx |
76 | 99 | uses: docker/setup-buildx-action@v3 |
| 100 | + - name: Login to GHCR |
| 101 | + uses: docker/login-action@v3 |
| 102 | + with: |
| 103 | + registry: ghcr.io |
| 104 | + username: ${{ github.actor }} |
| 105 | + password: ${{ secrets.GITHUB_TOKEN }} |
77 | 106 | - name: Login to DockerHub |
78 | 107 | uses: docker/login-action@v3 |
| 108 | + if: ${{ github.repository_owner == 'thecodingmachine' }} |
79 | 109 | with: |
80 | 110 | username: ${{ secrets.DOCKERHUB_USERNAME }} |
81 | 111 | password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 112 | + - name: Install regctl |
| 113 | + uses: regclient/actions/regctl-installer@main |
| 114 | + with: |
| 115 | + release: 'v0.8.1' |
82 | 116 | - name: Fetch minor version of php |
83 | 117 | run: | |
84 | | - # Build slim one |
85 | | - PHP_VERSION="${{ matrix.php_version }}" |
86 | | - TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ |
87 | | - docker buildx bake \ |
88 | | - --set "*.platform=linux/amd64" \ |
89 | | - --set "*.output=type=docker" \ |
90 | | - --load \ |
91 | | - php${PHP_VERSION//.}-slim-${{ matrix.variant }} |
| 118 | + # Pull amd64 slim image to get PHP version |
| 119 | + docker pull --quiet ghcr.io/${{ github.repository_owner }}/php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v5-slim-${{ matrix.variant }}-amd64 |
92 | 120 | # Retrieve minor |
93 | | - PHP_PATCH_MINOR=`docker run --rm thecodingmachine/php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v5-slim-${{ matrix.variant }} php -v | head -n1 | grep -P '\d+\.\d+\.\d+' -o | head -n1` |
| 121 | + PHP_PATCH_MINOR=`docker run --rm ghcr.io/${{ github.repository_owner }}/php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v5-slim-${{ matrix.variant }}-amd64 php -v | head -n1 | grep -P '\d+\.\d+\.\d+' -o | head -n1` |
| 122 | + echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}" |
94 | 123 | echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}" >> $GITHUB_ENV |
95 | | - - name: Display tags to build |
| 124 | + - name: Get list of images for this variant |
| 125 | + id: get-images |
96 | 126 | run: | |
97 | 127 | PHP_VERSION="${{ matrix.php_version }}" |
98 | | - PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" \ |
| 128 | + REPO="ghcr.io/${{ github.repository_owner }}/php" \ |
99 | 129 | TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ |
100 | | - IS_RELEASE="1" \ |
101 | | - docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --print --progress plain | jq ".target[].tags | join(\" \")" -r > "/tmp/tags.log" |
102 | | - cat "/tmp/tags.log" |
103 | | - - name: Build and push ${{ matrix.php_version }}-${{ matrix.variant }} |
| 130 | + docker buildx bake \ |
| 131 | + --print --progress=quiet \ |
| 132 | + php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq '.target[].tags[]' |
| 133 | + - name: Create multiarch manifests |
104 | 134 | run: | |
105 | 135 | PHP_VERSION="${{ matrix.php_version }}" |
106 | | - PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" \ |
107 | | - TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ |
108 | | - IS_RELEASE="1" \ |
109 | | - docker buildx bake \ |
110 | | - --set "*.platform=linux/amd64,linux/arm64" \ |
111 | | - --set "*.output=type=registry" \ |
112 | | - php${PHP_VERSION//.}-${{ matrix.variant }}-all |
113 | | - - name: Push artifacts |
114 | | - uses: actions/upload-artifact@v4 |
115 | | - with: |
116 | | - name: ${{ matrix.php_version }}-${{ matrix.variant }} |
117 | | - path: /tmp/tags.log |
118 | | - retention-days: 60 |
| 136 | +
|
| 137 | + # Get all targets from the bake group |
| 138 | + TARGETS=$(docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --progress=quiet --print | jq -r ".group[\"php${PHP_VERSION//.}-${{ matrix.variant }}-all\"].targets[]") |
| 139 | +
|
| 140 | + for TARGET in $TARGETS; do |
| 141 | + TAG_ORI=$(REPO="ghcr.io/${{ github.repository_owner }}/php" TAG_PREFIX="rc${GITHUB_RUN_ID}-" docker buildx bake ${TARGET} --progress=quiet --print | jq -r ".target | to_entries[] | select(.key == \"${TARGET}\") | .value.tags[0]") |
| 142 | + TAG_PATH=$(REPO="php" PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" docker buildx bake ${TARGET} --progress=quiet --print | jq -r ".target | to_entries[] | select(.key == \"${TARGET}\") | .value.tags[0]") |
| 143 | + TAG_MINOR=$(REPO="php" docker buildx bake ${TARGET} --progress=quiet --print | jq -r ".target | to_entries[] | select(.key == \"${TARGET}\") | .value.tags[0]") |
| 144 | +
|
| 145 | + # Create manifest for rc tag (always) |
| 146 | + echo "Creating manifest: ${TARGET} - ${TAG_ORI}" |
| 147 | + docker buildx imagetools create --progress=plain -t "${TAG_ORI}" "${TAG_ORI}-amd64" "${TAG_ORI}-arm64" |
| 148 | +
|
| 149 | + # Create manifest for PHP_PATCH |
| 150 | + regctl image copy "${TAG_ORI}" "ghcr.io/${{ github.repository_owner }}/${TAG_PATH}" |
| 151 | + # Create manifest for PHP_MINOR |
| 152 | + regctl image copy "${TAG_ORI}" "ghcr.io/${{ github.repository_owner }}/${TAG_MINOR}" |
| 153 | +
|
| 154 | + # SAME FOR DOCKERHUB (for the official repository) |
| 155 | + if [ "${{ github.repository_owner }}" == "thecodingmachine" ]; then |
| 156 | + # Create manifest for PHP_PATCH_MINOR |
| 157 | + regctl image copy "${TAG_ORI}" "thecodingmachine/${TAG_PATH}" |
| 158 | + # Create manifest for PHP_VERSION |
| 159 | + regctl image copy "${TAG_ORI}" "thecodingmachine/${TAG_MINOR}" |
| 160 | + fi |
| 161 | + done |
0 commit comments