-
Notifications
You must be signed in to change notification settings - Fork 2
137 lines (124 loc) · 4.77 KB
/
docker-publish.yml
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
name: Build and Push Docker Image
on:
push:
branches:
- main
env:
# Use GitHub Container Repository
REGISTRY_GITHUB: ghcr.io
# Use docker.io for Docker Hub if empty
REGISTRY_DOCKER_HUB: docker.io
# github.repository as <account>/<repo>
IMAGE_NAME: geschke/php-fpm-swrm
# was: ${{ github.repository }}
# GitHub repository is named as "docker-<image_name>" to differ Docker images from other contents
jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- directory: ./ubuntu-22.04/
tagging: 8.1-fpm
latest: false
- directory: ./ubuntu-24.04/
tagging: 8.3-fpm
latest: true
- directory: ./ubuntu-22.04-sury-8.1/
tagging: 8.1-fpm-ubuntu22.04-sury
latest: false
- directory: ./ubuntu-22.04-sury-8.2/
tagging: 8.2-fpm-ubuntu22.04-sury
latest: false
- directory: ./ubuntu-22.04-sury-8.3/
tagging: 8.3-fpm-ubuntu22.04-sury
latest: false
- directory: ./ubuntu-24.04-sury-8.2/
tagging: 8.2-fpm-ubuntu24.04-sury
latest: false
- directory: ./ubuntu-24.04-sury-8.3/
tagging: 8.3-fpm-ubuntu24.04-sury
latest: false
permissions:
contents: read
packages: write
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Login to GitHub Container Repository
- name: Log into registry ${{ env.REGISTRY_GITHUB }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_GITHUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Copy composer installation file
run: |
cp ./install-composer.sh ./${{ matrix.directory }}
-
name: Build full tag based on version file
id: generate_tag
run: |
version_file="${{ matrix.directory }}version.txt"
if [[ -f "$version_file" ]]; then
version=$(cat "$version_file")
full_tag="${{ matrix.tagging }}-${version}"
echo "Full tag is: $full_tag"
echo "full_tag=$full_tag" >> "$GITHUB_OUTPUT"
fi
- name: Query existing Docker image tags
if: github.event_name != 'pull_request'
id: query_tag
run: |
echo "full tag built in previous step:"
echo "Tag ${{ steps.generate_tag.outputs.full_tag }}"
TAG_EXISTS=$(curl -s "https://hub.docker.com/v2/repositories/${{ env.IMAGE_NAME }}/tags/?page_size=100" | jq -r '.results[].name' | grep -w "${{ steps.generate_tag.outputs.full_tag }}" || true)
if [ -n "$TAG_EXISTS" ]; then
echo "Tag ${{ steps.generate_tag.outputs.full_tag }} already exists, so don't build the docker image!"
echo "run_build=false" >> "$GITHUB_OUTPUT"
else
echo "Tag ${{ steps.generate_tag.outputs.full_tag }} does not exist, proceed with building the image."
echo "run_build=true" >> "$GITHUB_OUTPUT"
fi
- name: Test build image
if: "${{ steps.query_tag.outputs.run_build == 'true' && steps.generate_tag.outputs.full_tag != '' }}"
run: |
echo "build docker image ${{ matrix.directory }} ${{ env.IMAGE_NAME }} here... with tag ${{ steps.generate_tag.outputs.full_tag }} "
-
name: Build and push
if: "${{ steps.query_tag.outputs.run_build == 'true' && steps.generate_tag.outputs.full_tag != '' }}"
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.directory }}/Dockerfile
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.full_tag }}
${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.full_tag }}
- name: Tag as latest if applicable
if: "${{ matrix.latest == 'true' && steps.query_tag.outputs.run_build == 'true' }}"
uses: docker/build-push-action@v6
with:
context: ./${{ matrix.directory }}
file: ${{ matrix.directory }}/Dockerfile
push: true
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }}:latest