Skip to content

Commit 31508de

Browse files
committed
Refactor GitHub Actions workflow to modularize PHP image builds, streamline Docker setup, and improve tagging consistency. Update documentation link.
1 parent 99f7b0f commit 31508de

File tree

2 files changed

+205
-44
lines changed

2 files changed

+205
-44
lines changed

.github/workflows/build.yml

Lines changed: 204 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
required: true
1919

2020
jobs:
21-
Build:
21+
Build-Base:
2222
runs-on: 'ubuntu-latest'
2323
strategy:
2424
matrix:
@@ -39,17 +39,6 @@ jobs:
3939
- name: Install requirements
4040
run: pip install -r requirements.txt
4141

42-
- name: Set up Docker
43-
uses: docker/setup-docker-action@v4
44-
with:
45-
daemon-config: |
46-
{
47-
"debug": true,
48-
"features": {
49-
"containerd-snapshotter": true
50-
}
51-
}
52-
5342
- name: Log into registry
5443
uses: docker/login-action@v3
5544
with:
@@ -64,106 +53,278 @@ jobs:
6453
uses: docker/setup-buildx-action@v3
6554

6655
- name: Generate Dockerfiles
67-
run: python3 ./build.py ${{ matrix.php-version }} --build-base --build-cli --build-fpm --build-fpm-apache --build-fpm-nginx --build-nginx
56+
run: python3 ./build.py ${{ matrix.php-version }} --build-base
6857

6958
- name: Build Docker image base
7059
uses: docker/build-push-action@v5
7160
with:
7261
context: .
7362
file: Dockerfile-php-${{ matrix.php-version }}-base
7463
platforms: linux/amd64,linux/arm64
75-
push: false
76-
load: true
64+
push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
7765
tags: |
7866
byjg/php:${{ matrix.php-version }}-base,
7967
byjg/php:${{ matrix.php-version }}-base-${{ env.YEAR }}.${{ env.MONTH }}
8068
labels: ${{ steps.meta.outputs.labels }}
8169

70+
Build-CLI:
71+
if: github.ref == 'refs/heads/master'
72+
needs: Build-Base
73+
runs-on: 'ubuntu-latest'
74+
strategy:
75+
matrix:
76+
php-version:
77+
- "8.5"
78+
- "8.4"
79+
- "8.3"
80+
- "8.2"
81+
82+
steps:
83+
- name: Get current date
84+
run: |
85+
echo "YEAR=$(date +'%Y')" >> $GITHUB_ENV
86+
echo "MONTH=$(date +'%m')" >> $GITHUB_ENV
87+
88+
- uses: actions/checkout@v4
89+
90+
- name: Install requirements
91+
run: pip install -r requirements.txt
92+
93+
- name: Log into registry
94+
uses: docker/login-action@v3
95+
with:
96+
registry: ${{ secrets.DOCKER_REGISTRY }}
97+
username: ${{ secrets.DOCKER_REGISTRY_USER }}
98+
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
99+
100+
- name: Set up QEMU
101+
uses: docker/setup-qemu-action@v3
102+
103+
- name: Set up Docker Buildx
104+
uses: docker/setup-buildx-action@v3
105+
106+
- name: Generate Dockerfiles
107+
run: python3 ./build.py ${{ matrix.php-version }} --build-cli
108+
82109
- name: Build Docker image cli
83110
uses: docker/build-push-action@v5
84111
with:
85112
context: .
86113
file: Dockerfile-php-${{ matrix.php-version }}-cli
87114
platforms: linux/amd64,linux/arm64
88-
push: false
89-
load: true
115+
push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
90116
tags: |
91117
byjg/php:${{ matrix.php-version }}-cli,
92118
byjg/php:${{ matrix.php-version }}-cli-${{ env.YEAR }}.${{ env.MONTH }}
93119
labels: ${{ steps.meta.outputs.labels }}
94120

121+
Build-FPM:
122+
if: github.ref == 'refs/heads/master'
123+
needs: Build-Base
124+
runs-on: 'ubuntu-latest'
125+
strategy:
126+
matrix:
127+
php-version:
128+
- "8.5"
129+
- "8.4"
130+
- "8.3"
131+
- "8.2"
132+
133+
steps:
134+
- name: Get current date
135+
run: |
136+
echo "YEAR=$(date +'%Y')" >> $GITHUB_ENV
137+
echo "MONTH=$(date +'%m')" >> $GITHUB_ENV
138+
139+
- uses: actions/checkout@v4
140+
141+
- name: Install requirements
142+
run: pip install -r requirements.txt
143+
144+
- name: Log into registry
145+
uses: docker/login-action@v3
146+
with:
147+
registry: ${{ secrets.DOCKER_REGISTRY }}
148+
username: ${{ secrets.DOCKER_REGISTRY_USER }}
149+
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
150+
151+
- name: Set up QEMU
152+
uses: docker/setup-qemu-action@v3
153+
154+
- name: Set up Docker Buildx
155+
uses: docker/setup-buildx-action@v3
156+
157+
- name: Generate Dockerfiles
158+
run: python3 ./build.py ${{ matrix.php-version }} --build-fpm
159+
95160
- name: Build Docker image fpm
96161
uses: docker/build-push-action@v5
97162
with:
98163
context: .
99164
file: Dockerfile-php-${{ matrix.php-version }}-fpm
100165
platforms: linux/amd64,linux/arm64
101-
push: false
102-
load: true
166+
push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
103167
tags: |
104168
byjg/php:${{ matrix.php-version }}-fpm,
105169
byjg/php:${{ matrix.php-version }}-fpm-${{ env.YEAR }}.${{ env.MONTH }}
106170
labels: ${{ steps.meta.outputs.labels }}
107171

172+
Build-FPM-Apache:
173+
if: github.ref == 'refs/heads/master'
174+
needs: Build-FPM
175+
runs-on: 'ubuntu-latest'
176+
strategy:
177+
matrix:
178+
php-version:
179+
- "8.5"
180+
- "8.4"
181+
- "8.3"
182+
- "8.2"
183+
184+
steps:
185+
- name: Get current date
186+
run: |
187+
echo "YEAR=$(date +'%Y')" >> $GITHUB_ENV
188+
echo "MONTH=$(date +'%m')" >> $GITHUB_ENV
189+
190+
- uses: actions/checkout@v4
191+
192+
- name: Install requirements
193+
run: pip install -r requirements.txt
194+
195+
- name: Log into registry
196+
uses: docker/login-action@v3
197+
with:
198+
registry: ${{ secrets.DOCKER_REGISTRY }}
199+
username: ${{ secrets.DOCKER_REGISTRY_USER }}
200+
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
201+
202+
- name: Set up QEMU
203+
uses: docker/setup-qemu-action@v3
204+
205+
- name: Set up Docker Buildx
206+
uses: docker/setup-buildx-action@v3
207+
208+
- name: Generate Dockerfiles
209+
run: python3 ./build.py ${{ matrix.php-version }} --build-fpm-apache
210+
108211
- name: Build Docker image fpm-apache
109212
uses: docker/build-push-action@v5
110213
with:
111214
context: .
112215
file: Dockerfile-php-${{ matrix.php-version }}-fpm-apache
113216
platforms: linux/amd64,linux/arm64
114-
push: false
115-
load: true
217+
push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
116218
tags: |
117219
byjg/php:${{ matrix.php-version }}-fpm-apache,
118220
byjg/php:${{ matrix.php-version }}-fpm-apache-${{ env.YEAR }}.${{ env.MONTH }}
119221
labels: ${{ steps.meta.outputs.labels }}
120222

223+
Build-FPM-Nginx:
224+
if: github.ref == 'refs/heads/master'
225+
needs: Build-FPM
226+
runs-on: 'ubuntu-latest'
227+
strategy:
228+
matrix:
229+
php-version:
230+
- "8.5"
231+
- "8.4"
232+
- "8.3"
233+
- "8.2"
234+
235+
steps:
236+
- name: Get current date
237+
run: |
238+
echo "YEAR=$(date +'%Y')" >> $GITHUB_ENV
239+
echo "MONTH=$(date +'%m')" >> $GITHUB_ENV
240+
241+
- uses: actions/checkout@v4
242+
243+
- name: Install requirements
244+
run: pip install -r requirements.txt
245+
246+
- name: Log into registry
247+
uses: docker/login-action@v3
248+
with:
249+
registry: ${{ secrets.DOCKER_REGISTRY }}
250+
username: ${{ secrets.DOCKER_REGISTRY_USER }}
251+
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
252+
253+
- name: Set up QEMU
254+
uses: docker/setup-qemu-action@v3
255+
256+
- name: Set up Docker Buildx
257+
uses: docker/setup-buildx-action@v3
258+
259+
- name: Generate Dockerfiles
260+
run: python3 ./build.py ${{ matrix.php-version }} --build-fpm-nginx
261+
121262
- name: Build Docker image fpm-nginx
122263
uses: docker/build-push-action@v5
123264
with:
124265
context: .
125266
file: Dockerfile-php-${{ matrix.php-version }}-fpm-nginx
126267
platforms: linux/amd64,linux/arm64
127-
push: false
128-
load: true
268+
push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
129269
tags: |
130270
byjg/php:${{ matrix.php-version }}-fpm-nginx,
131271
byjg/php:${{ matrix.php-version }}-fpm-nginx-${{ env.YEAR }}.${{ env.MONTH }}
132272
labels: ${{ steps.meta.outputs.labels }}
133273

274+
Build-Nginx:
275+
if: github.ref == 'refs/heads/master'
276+
needs: Build-Base
277+
runs-on: 'ubuntu-latest'
278+
strategy:
279+
matrix:
280+
php-version:
281+
- "8.5"
282+
- "8.4"
283+
- "8.3"
284+
- "8.2"
285+
286+
steps:
287+
- name: Get current date
288+
run: |
289+
echo "YEAR=$(date +'%Y')" >> $GITHUB_ENV
290+
echo "MONTH=$(date +'%m')" >> $GITHUB_ENV
291+
292+
- uses: actions/checkout@v4
293+
294+
- name: Install requirements
295+
run: pip install -r requirements.txt
296+
297+
- name: Log into registry
298+
uses: docker/login-action@v3
299+
with:
300+
registry: ${{ secrets.DOCKER_REGISTRY }}
301+
username: ${{ secrets.DOCKER_REGISTRY_USER }}
302+
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
303+
304+
- name: Set up QEMU
305+
uses: docker/setup-qemu-action@v3
306+
307+
- name: Set up Docker Buildx
308+
uses: docker/setup-buildx-action@v3
309+
310+
- name: Generate Dockerfiles
311+
run: python3 ./build.py ${{ matrix.php-version }} --build-nginx
312+
134313
- name: Build Docker image nginx
135314
uses: docker/build-push-action@v5
136315
with:
137316
context: .
138317
file: Dockerfile-php-${{ matrix.php-version }}-nginx
139318
platforms: linux/amd64,linux/arm64
140-
push: false
141-
load: true
319+
push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
142320
tags: |
143321
byjg/php:${{ matrix.php-version }}-nginx,
144322
byjg/php:${{ matrix.php-version }}-nginx-${{ env.YEAR }}.${{ env.MONTH }}
145323
labels: ${{ steps.meta.outputs.labels }}
146324

147-
- name: Push all built images
148-
if: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
149-
run: |
150-
docker images
151-
docker push byjg/php:${{ matrix.php-version }}-base
152-
docker push byjg/php:${{ matrix.php-version }}-base-${{ env.YEAR }}.${{ env.MONTH }}
153-
docker push byjg/php:${{ matrix.php-version }}-cli
154-
docker push byjg/php:${{ matrix.php-version }}-cli-${{ env.YEAR }}.${{ env.MONTH }}
155-
docker push byjg/php:${{ matrix.php-version }}-fpm
156-
docker push byjg/php:${{ matrix.php-version }}-fpm-${{ env.YEAR }}.${{ env.MONTH }}
157-
docker push byjg/php:${{ matrix.php-version }}-fpm-apache
158-
docker push byjg/php:${{ matrix.php-version }}-fpm-apache-${{ env.YEAR }}.${{ env.MONTH }}
159-
docker push byjg/php:${{ matrix.php-version }}-fpm-nginx
160-
docker push byjg/php:${{ matrix.php-version }}-fpm-nginx-${{ env.YEAR }}.${{ env.MONTH }}
161-
docker push byjg/php:${{ matrix.php-version }}-nginx
162-
docker push byjg/php:${{ matrix.php-version }}-nginx-${{ env.YEAR }}.${{ env.MONTH }}
163-
164325
Documentation:
165326
if: github.ref == 'refs/heads/master'
166-
needs: Build
327+
needs: [Build-Base, Build-CLI, Build-FPM, Build-FPM-Apache, Build-FPM-Nginx, Build-Nginx]
167328
uses: byjg/byjg.github.io/.github/workflows/add-doc.yaml@master
168329
with:
169330
folder: devops

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ A complete, lightweight, and versatile PHP Docker image collection based on Alpi
2929
- [Dockerfile Reference](docs/dockerfile.md) - Dockerfile details
3030
- [Tagging Convention](docs/tagging.md) - Understanding image tags
3131

32-
**See full documentation at: [https://opensource.byjg.com/devops/docker-php](https://opensource.byjg.com/devops/docker-php)**
32+
**See full documentation at: [https://opensource.byjg.com/docs/devops/docker-php](https://opensource.byjg.com/docs/devops/docker-php)**
3333

3434
## Quick Start
3535

0 commit comments

Comments
 (0)