-
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathservice_docker-build-and-publish.yml
More file actions
184 lines (167 loc) · 6.93 KB
/
Copy pathservice_docker-build-and-publish.yml
File metadata and controls
184 lines (167 loc) · 6.93 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: Build and Publish
on:
workflow_call:
inputs:
authenticate_with_ghcr:
default: true
type: boolean
description: 'Whether to authenticate with DockerHub.'
tag-prefix:
required: true
type: string
description: 'The prefix to use for the Docker image tags.'
php-versions-file:
type: string
default: 'scripts/conf/php-versions.yml'
description: 'The path to the PHP versions file.'
registry-repositories:
type: string
required: true
description: 'The Docker registry repositories to push the images to. Separate multiple repositories with a comma (example: docker.io/serversideup/php,ghcr.io/serversideup/php)'
release-type:
type: string
default: 'testing'
description: 'The type of release to create. Options: testing, latest'
push-to-registry:
type: boolean
default: true
description: 'Whether to push the images to the registry.'
ref:
type: string
default: ${{ github.ref }}
description: 'The git ref to checkout (branch, tag, or commit SHA)'
jobs:
setup-matrix:
runs-on: depot-ubuntu-24.04
outputs:
php-version-map-json: ${{ steps.get-php-versions.outputs.php-version-map-json }}
steps:
- name: Check out code
uses: actions/checkout@v6
with:
ref: ${{ inputs.ref }}
- name: Prepare PHP versions for the matrix. 😎
run: |
chmod +x ./scripts/get-php-versions.sh
./scripts/get-php-versions.sh
env:
SKIP_DOWNLOAD: false
- name: Ensure our PHP Versions file exists.
run: |
if [ ! -f "${{ inputs.php-versions-file }}" ]; then
echo "PHP Versions file does not exist. Exiting."
exit 1
else
cat ${{ inputs.php-versions-file }}
fi
- name: Assemble PHP versions into the matrix. 😎
id: get-php-versions
run: |
MATRIX_JSON=$(bash ./scripts/generate-matrix.sh '${{ inputs.php-versions-file }}')
echo "php-version-map-json=${MATRIX_JSON}" >> $GITHUB_OUTPUT
echo "${MATRIX_JSON}" | jq '.'
- name: Upload the php-versions.yml file
uses: actions/upload-artifact@v7
with:
name: php-versions.yml
path: ${{ inputs.php-versions-file }}
docker-publish:
needs: setup-matrix
runs-on: depot-ubuntu-24.04-8
strategy:
matrix: ${{fromJson(needs.setup-matrix.outputs.php-version-map-json)}}
steps:
- name: Check out code.
uses: actions/checkout@v6
with:
ref: ${{ inputs.ref }}
- name: Download PHP Versions file
uses: actions/download-artifact@v8
with:
name: php-versions.yml
path: ./artifacts
- name: Move PHP Versions file
run: mv ./artifacts/php-versions.yml ${{ inputs.php-versions-file }}
- name: Set up Depot CLI
uses: depot/setup-action@v1
##
# Docker build & publish
##
- name: Login to DockerHub
uses: docker/login-action@v4
if: ${{ inputs.push-to-registry }}
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
if: ${{ inputs.push-to-registry && inputs.authenticate_with_ghcr }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "📦 Assemble the Docker Tags"
run: |
chmod +x ./scripts/assemble-docker-tags.sh
./scripts/assemble-docker-tags.sh
env:
PHP_VERSIONS_FILE: "${{ inputs.php-versions-file }}"
PHP_BUILD_VERSION: ${{ matrix.patch_version }}
PHP_BUILD_VARIATION: ${{ matrix.php_variation }}
PHP_BUILD_BASE_OS: ${{ matrix.base_os }}
DOCKER_TAG_PREFIX: ${{ inputs.tag-prefix }}
DOCKER_REGISTRY_REPOSITORIES: ${{ inputs.registry-repositories }}
RELEASE_TYPE: ${{ inputs.release-type }}
GITHUB_RELEASE_TAG: ${{ github.ref_name }}
GITHUB_REF_TYPE: ${{ github.ref_type }}
- name: Set REPOSITORY_BUILD_VERSION
id: set_version
run: |
if [[ "${{ github.ref_type }}" == "tag" || "${{ inputs.ref }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# Building from a tag (release or scheduled task)
echo "🚀 Setting REPOSITORY_BUILD_VERSION to Tag + Run ID"
if [[ "${{ github.ref_type }}" == "tag" ]]; then
VERSION="${{ github.ref_name }}"
else
VERSION="${{ inputs.ref }}"
fi
echo "REPOSITORY_BUILD_VERSION=${VERSION}-${{ github.run_id }}" >> $GITHUB_ENV
else
# Regular git build (PR, branch push, etc)
echo "👨🔬 Setting REPOSITORY_BUILD_VERSION to Git SHA + Run ID"
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
echo "REPOSITORY_BUILD_VERSION=git-${SHORT_SHA}-${{ github.run_id }}" >> $GITHUB_ENV
fi
- name: Compute NGINX build-arg (only for fpm-nginx)
id: compute_nginx
if: ${{ matrix.php_variation == 'fpm-nginx' }}
run: |
if command -v yq >/dev/null 2>&1; then
VERSION=$(yq -r '.operating_systems[].versions[] | select(.version == "${{ matrix.base_os }}") | .nginx_version' '${{ inputs.php-versions-file }}' | head -n1)
else
VERSION=$(awk -v key="${{ matrix.base_os }}" 'BEGIN{found=0} $1=="version:" && $2==key {found=1} found && $1=="nginx_version:" {print $2; exit}' "${{ inputs.php-versions-file }}")
fi
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
echo "Unable to determine NGINX version for OS ${{ matrix.base_os }}" 1>&2
exit 1
fi
echo "nginx_arg=NGINX_VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Build images
uses: depot/build-push-action@v1
with:
project: ${{ secrets.DEPOT_PROJECT_ID }}
token: ${{ secrets.DEPOT_PROJECT_TOKEN }}
file: src/variations/${{ matrix.php_variation }}/Dockerfile
build-args: |
BASE_OS_VERSION=${{ matrix.base_os }}
PHP_VERSION=${{ matrix.patch_version }}
PHP_VARIATION=${{ matrix.php_variation }}
REPOSITORY_BUILD_VERSION=${{ env.REPOSITORY_BUILD_VERSION }}
${{ steps.compute_nginx.outputs.nginx_arg }}
platforms: |
linux/amd64
linux/arm64/v8
pull: true
push: ${{ inputs.push-to-registry }}
tags: ${{ env.DOCKER_TAGS }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Supercharge your PHP experience with Docker images that are based off the official PHP images but are optimized to be run in production environments for Laravel and WordPress and more