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