|
1 |
| -#name: Docker |
2 |
| - |
3 |
| -# This workflow uses actions that are not certified by GitHub. |
4 |
| -# They are provided by a third-party and are governed by |
5 |
| -# separate terms of service, privacy policy, and support |
6 |
| -# documentation. |
7 |
| - |
8 |
| -#on: |
9 |
| - #schedule: |
10 |
| - # - cron: '42 9 * * *' |
11 |
| -# push: |
12 |
| -# branches: |
13 |
| -# - main |
14 |
| - # Publish semver tags as releases. |
15 |
| - # Every release in a branch will be tagged, so it is not necessary to specify additional branches. |
16 |
| - #tags: [ 'v*.*.*' ] |
17 |
| -# tags: |
18 |
| -# - 'v*' |
19 |
| -# pull_request: |
20 |
| -# branches: [ main ] |
21 |
| - |
22 |
| -#env: |
23 |
| - # Use GitHub Container Repository |
24 |
| -# REGISTRY_GITHUB: ghcr.io |
25 |
| - |
26 |
| - # Use docker.io for Docker Hub if empty |
27 |
| -# REGISTRY_DOCKER_HUB: docker.io |
28 |
| - |
29 |
| - # github.repository as <account>/<repo> |
30 |
| -# IMAGE_NAME: geschke/php-fpm-swrm |
31 |
| - # was: ${{ github.repository }} |
32 |
| - # GitHub repository is named as "docker-<image_name>" to differ Docker images from other contents |
33 |
| - |
34 |
| - |
35 |
| -#jobs: |
36 |
| -# build: |
37 |
| - |
38 |
| -# runs-on: ubuntu-latest |
39 |
| -# permissions: |
40 |
| -# contents: read |
41 |
| -# packages: write |
42 |
| - |
43 |
| -# steps: |
44 |
| -# - name: Checkout repository |
45 |
| -# uses: actions/checkout@v3 |
46 |
| - |
47 |
| -# - name: Set up Docker Buildx |
48 |
| -# id: buildx |
49 |
| -# uses: docker/setup-buildx-action@v2 |
50 |
| - |
51 |
| -# - name: Inspect builder |
52 |
| -# run: | |
53 |
| -# echo "Name: ${{ steps.buildx.outputs.name }}" |
54 |
| -# echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" |
55 |
| -# echo "Status: ${{ steps.buildx.outputs.status }}" |
56 |
| -# echo "Flags: ${{ steps.buildx.outputs.flags }}" |
57 |
| -# echo "Platforms: ${{ steps.buildx.outputs.platforms }}" |
58 |
| -# echo "image name: ${{ env.IMAGE_NAME }}" |
59 |
| - |
60 |
| - # Login against an container registry except on PR |
61 |
| - # https://github.com/docker/login-action |
62 |
| - |
63 |
| - # Login to GitHub Container Repository |
64 |
| -# - name: Log into registry ${{ env.REGISTRY_GITHUB }} |
65 |
| -# if: github.event_name != 'pull_request' |
66 |
| -# uses: docker/login-action@v2 |
67 |
| -# with: |
68 |
| -# registry: ${{ env.REGISTRY_GITHUB }} |
69 |
| -# username: ${{ github.actor }} |
70 |
| -# password: ${{ secrets.GITHUB_TOKEN }} |
71 |
| - |
72 |
| - # Login to Docker Hub (default when no registry variable exists) |
73 |
| -# - name: Login to DockerHub |
74 |
| -# if: github.event_name != 'pull_request' |
75 |
| -# uses: docker/login-action@v2 |
76 |
| -# with: |
77 |
| -# username: ${{ secrets.DOCKER_USERNAME }} |
78 |
| -# password: ${{ secrets.DOCKER_PASSWORD }} |
79 |
| - |
80 |
| - # Extract metadata (tags, labels) for Docker |
81 |
| - # https://github.com/docker/metadata-action |
82 |
| - |
83 |
| - # - name: Extract Docker metadata |
84 |
| - # id: meta |
85 |
| - # uses: docker/metadata-action@v4 |
86 |
| - # with: |
87 |
| - # tags: | |
88 |
| - # type=raw,value=latest,enable=${{ endsWith(GitHub.ref, 'main') }} |
89 |
| - # type=match,pattern=v(.*),group=1 |
90 |
| - # flavor: | |
91 |
| - # latest=false |
92 |
| - # images: ${{ env.REGISTRY_DOCKER_HUB }}/${{ env.IMAGE_NAME }},${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }} |
93 |
| - |
94 |
| - # - name: Show some information after meta run |
95 |
| - # id: showinfo |
96 |
| - # run: | |
97 |
| - # echo "GitHub event name: ${{ github.event_name }}" |
98 |
| - # echo "Tags: ${{ steps.meta.outputs.tags }}" |
99 |
| - # echo "Labels: ${{ steps.meta.outputs.labels }}" |
100 |
| - # echo "Image name: ${{ env.IMAGE_NAME }}" |
101 |
| - |
102 |
| - |
103 |
| - # Build and push Docker image with Buildx (don't push on PR) |
104 |
| - # https://github.com/docker/build-push-action |
105 |
| - # - name: Build and push Docker image |
106 |
| - # uses: docker/build-push-action@v4 |
107 |
| - # with: |
108 |
| - # context: . |
109 |
| - # push: ${{ github.event_name != 'pull_request' }} |
110 |
| - # tags: ${{ steps.meta.outputs.tags }} |
111 |
| - # labels: ${{ steps.meta.outputs.labels }} |
112 |
| - |
113 |
| -#name: Docker Build and Push |
114 |
| - |
115 |
| -#on: |
116 |
| -# push: |
117 |
| -# branches: |
118 |
| -# - main |
119 |
| - |
120 |
| -#env: |
121 |
| -# # Registries for Docker Hub and GitHub Container Registry |
122 |
| -# REGISTRY_GITHUB: ghcr.io |
123 |
| -# REGISTRY_DOCKER_HUB: docker.io |
124 |
| - |
125 |
| -#jobs: |
126 |
| -# build: |
127 |
| -# runs-on: ubuntu-latest |
128 |
| -# permissions: |
129 |
| -# contents: read |
130 |
| -# packages: write |
131 |
| - |
132 |
| -# steps: |
133 |
| -# - name: Checkout repository |
134 |
| -# uses: actions/checkout@v3 |
135 |
| - |
136 |
| -# - name: Set up Docker Buildx |
137 |
| -# uses: docker/setup-buildx-action@v2 |
138 |
| - |
139 |
| -# - name: Log into GitHub Container Registry |
140 |
| -# if: github.event_name != 'pull_request' |
141 |
| -# uses: docker/login-action@v2 |
142 |
| -# with: |
143 |
| -# registry: ${{ env.REGISTRY_GITHUB }} |
144 |
| -# username: ${{ github.actor }} |
145 |
| -# password: ${{ secrets.GITHUB_TOKEN }} |
146 |
| - |
147 |
| -# - name: Log into Docker Hub |
148 |
| -# if: github.event_name != 'pull_request' |
149 |
| -# uses: docker/login-action@v2 |
150 |
| -# with: |
151 |
| -# username: ${{ secrets.DOCKER_USERNAME }} |
152 |
| -# password: ${{ secrets.DOCKER_PASSWORD }} |
153 |
| - |
154 |
| -# - name: Load image mappings and set IMAGE_NAME |
155 |
| -# run: | |
156 |
| -# source ./image_mappings.sh |
157 |
| -# echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV |
158 |
| -# echo "Image name: $IMAGE_NAME" |
159 |
| - |
160 |
| -# - name: Build and Push Docker Images |
161 |
| -# uses: docker/build-push-action@v4 |
162 |
| -# with: |
163 |
| -# context: . |
164 |
| -# push: false |
165 |
| -# # ${{ github.event_name != 'pull_request' }} |
166 |
| -# tags: | |
167 |
| -# ${{ env.REGISTRY_DOCKER_HUB }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} |
168 |
| -# ${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} |
169 |
| -# platforms: linux/amd64,linux/arm64 |
170 |
| - |
171 |
| - |
172 |
| -name: Docker Build and Push |
| 1 | +name: Build and Push Docker Image |
173 | 2 |
|
174 | 3 | on:
|
175 | 4 | push:
|
176 | 5 | branches:
|
177 | 6 | - main
|
178 | 7 |
|
179 |
| -env: |
180 |
| - # Registries for Docker Hub and GitHub Container Registry |
181 |
| - REGISTRY_GITHUB: ghcr.io |
182 |
| - REGISTRY_DOCKER_HUB: docker.io |
183 |
| - |
184 | 8 | jobs:
|
185 |
| - build: |
| 9 | + build-and-push-image: |
186 | 10 | runs-on: ubuntu-latest
|
| 11 | + strategy: |
| 12 | + fail-fast: false |
| 13 | + matrix: |
| 14 | + include: |
| 15 | + - directory: ./ubuntu-22.04/ |
| 16 | + tagging: v8.1-fpm |
| 17 | + image: geschke/php-fpm-swrm |
| 18 | + - directory: ./ubuntu-22.04-sury-8.2/ |
| 19 | + tagging: v8.2-fpm-ubuntu22.04-sury |
| 20 | + image: geschke/php-fpm-swrm |
187 | 21 | permissions:
|
188 | 22 | contents: read
|
189 | 23 | packages: write
|
190 |
| - |
191 | 24 | steps:
|
192 |
| - # Check out the repository |
193 |
| - - name: Checkout repository |
194 |
| - uses: actions/checkout@v3 |
195 |
| - |
196 |
| - # Set up Docker Buildx for multi-platform builds |
197 |
| - - name: Set up Docker Buildx |
198 |
| - uses: docker/setup-buildx-action@v2 |
199 |
| - |
200 |
| - # Log in to GitHub Container Registry (GHCR) |
201 |
| - - name: Log into GitHub Container Registry |
202 |
| - if: github.event_name != 'pull_request' |
203 |
| - uses: docker/login-action@v2 |
| 25 | + - |
| 26 | + name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + - |
| 29 | + name: Set up QEMU |
| 30 | + uses: docker/setup-qemu-action@v3 |
| 31 | + - |
| 32 | + name: Set up Docker Buildx |
| 33 | + uses: docker/setup-buildx-action@v3 |
| 34 | + - |
| 35 | + name: Login to Docker Hub |
| 36 | + uses: docker/login-action@v3 |
204 | 37 | with:
|
205 |
| - registry: ${{ env.REGISTRY_GITHUB }} |
206 |
| - username: ${{ github.actor }} |
207 |
| - password: ${{ secrets.GITHUB_TOKEN }} |
208 |
| - |
209 |
| - # Log in to Docker Hub |
210 |
| - - name: Log into Docker Hub |
211 |
| - if: github.event_name != 'pull_request' |
212 |
| - uses: docker/login-action@v2 |
213 |
| - with: |
214 |
| - username: ${{ secrets.DOCKER_USERNAME }} |
215 |
| - password: ${{ secrets.DOCKER_PASSWORD }} |
216 |
| - |
217 |
| - # Load the image mappings and set IMAGE_NAME |
218 |
| - - name: Load image mappings and define IMAGE_NAME |
219 |
| - id: load_mappings |
| 38 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 39 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 40 | + - |
| 41 | + name: Copy composer installation file |
220 | 42 | run: |
|
221 |
| - source ./image_mappings.sh |
222 |
| - echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV |
223 |
| -
|
224 |
| - # Iterate over the directories, load versions, and check tags |
225 |
| - - name: Check tags and set build status for each directory |
226 |
| - id: check_tags |
227 |
| - run: | |
228 |
| - source ./image_mappings.sh |
229 |
| - for dir in "${!images[@]}"; do |
230 |
| - version_file="./$dir/version.txt" |
231 |
| - if [[ -f "$version_file" ]]; then |
232 |
| - version=$(cat "$version_file") |
233 |
| - full_tag="${images[$dir]}-${version}" |
234 |
| - echo "Checking tag $full_tag in directory $dir" |
235 |
| -
|
236 |
| - # Check Docker Hub for the tag |
237 |
| - TAG_EXISTS_DOCKERHUB=$(curl -s https://hub.docker.com/v2/repositories/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}/tags/${full_tag} | jq -r '.name') |
238 |
| - if [ "$TAG_EXISTS_DOCKERHUB" == "${full_tag}" ]; then |
239 |
| - echo "DOCKERHUB_TAG_EXISTS_$dir=true" >> $GITHUB_ENV |
240 |
| - else |
241 |
| - echo "DOCKERHUB_TAG_EXISTS_$dir=false" >> $GITHUB_ENV |
242 |
| - fi |
243 |
| -
|
244 |
| - else |
245 |
| - echo "Error: No version.txt found in $dir" |
246 |
| - exit 1 |
247 |
| - fi |
248 |
| - done |
249 |
| -
|
250 |
| - # Perform a Dry-Run (Build but do not push) if the tags don't already exist |
251 |
| - - name: Build Docker Images (Dry Run) |
252 |
| - run: | |
253 |
| - source ./image_mappings.sh |
254 |
| - for dir in "${!images[@]}"; do |
255 |
| - # Read the dynamically set environment variables from previous step |
256 |
| - DOCKERHUB_EXISTS=$(eval echo \$DOCKERHUB_TAG_EXISTS_$dir) |
257 |
| - |
258 |
| - if [ "$DOCKERHUB_EXISTS" == "false" ]; then |
259 |
| - version_file="./$dir/version.txt" |
260 |
| - version=$(cat "$version_file") |
261 |
| - full_tag="${images[$dir]}-${version}" |
262 |
| -
|
263 |
| - echo "Building and pushing image $full_tag from directory $dir" |
264 |
| -
|
265 |
| - # Copy install-composer.sh to the directory before building the image |
266 |
| - cp ./install-composer.sh ./$dir/ |
267 |
| - if [[ $? -ne 0 ]]; then |
268 |
| - echo "Error copying install-composer.sh to $dir" |
269 |
| - exit 1 |
270 |
| - fi |
271 |
| -
|
272 |
| - # Build the Docker image with Dry Run (no push) |
273 |
| - docker buildx build --platform linux/amd64,linux/arm64 \ |
274 |
| - -t "$REGISTRY_DOCKER_HUB/$IMAGE_NAME:$full_tag" \ |
275 |
| - -t "$REGISTRY_GITHUB/$IMAGE_NAME:$full_tag" \ |
276 |
| - --push=false ./$dir |
277 |
| -
|
278 |
| - # Clean up: Remove install-composer.sh from the directory |
279 |
| - rm ./$dir/install-composer.sh |
280 |
| -
|
281 |
| - # Simulate push by outputting the commands (this is just a log, no actual push happens) |
282 |
| - echo "Dry Run completed for $IMAGE_NAME:$full_tag" |
283 |
| - echo "Push command would be:" |
284 |
| - echo "docker push $REGISTRY_DOCKER_HUB/$IMAGE_NAME:$full_tag" |
285 |
| - echo "docker push $REGISTRY_GITHUB/$IMAGE_NAME:$full_tag" |
286 |
| - else |
287 |
| - echo "Skipping build for $full_tag as it already exists." |
288 |
| - fi |
289 |
| - done |
| 43 | + cp ./install-composer.sh ./${{ matrix.directory }} |
| 44 | + - |
| 45 | + name: Build and push |
| 46 | + uses: docker/build-push-action@v6 |
| 47 | + with: |
| 48 | + context: . |
| 49 | + file: ${{ matrix.directory }}/Dockerfile |
| 50 | + push: false |
| 51 | + tags: ${{ matrix.tagging }} |
0 commit comments