-
Notifications
You must be signed in to change notification settings - Fork 9
195 lines (189 loc) · 6.13 KB
/
build.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
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
185
186
187
188
189
190
191
192
193
194
195
name: Build Docker images
on:
pull_request:
paths:
- .github/workflows/build.yml
- .github/workflows/generate-matrix
- "base/**"
- "installed/**"
- data/versions.json
push:
branches:
- main
tags-ignore:
- "**"
paths:
- .github/workflows/build.yml
- .github/workflows/generate-matrix
- "base/**"
- "installed/**"
- data/versions.json
repository_dispatch:
types:
- build
- publish
jobs:
check_envoronment:
name: Check environment
runs-on: ubuntu-latest
outputs:
action: ${{ steps.inspect.outputs.action }}
steps:
-
name: Inspect environment
id: inspect
run: |
action=none
echo 'action=none' >> $GITHUB_OUTPUT
case ${{ github.event_name }} in
repository_dispatch)
case "${{ github.event.event_type }}" in
build)
action=build
;;
publish)
action=publish
;;
*)
echo 'Unrecognized event type: ${{ github.event.event_type }}'
exit 1
;;
esac
;;
push)
case "${{ github.event.head_commit.message }}" in
\[skip\ ci\]*)
;;
*)
action=publish
;;
esac
;;
pull_request)
action=build
;;
esac
echo "action=$action" >> $GITHUB_OUTPUT
-
name: Print environment info
run: |
printf 'github.event_name: %s\n' "${{ github.event_name }}"
printf 'github.ref: %s\n' "${{ github.ref }}"
printf 'Action to be performed: %s\n' "${{ steps.inspect.outputs.action }}"
build_base:
name: Build base image
needs:
- check_envoronment
runs-on: ubuntu-latest
if: needs.check_envoronment.outputs.action != 'none'
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Build
run: docker build --force-rm --rm --tag ghcr.io/concrete5-community/docker5:base ./base
-
name: Save base Docker image
if: needs.check_envoronment.outputs.action == 'build'
run: docker save ghcr.io/concrete5-community/docker5:base | gzip > /tmp/base-image.tgz
-
name: Upload artifact
if: needs.check_envoronment.outputs.action == 'build'
uses: actions/upload-artifact@v3
with:
name: base-image
path: /tmp/base-image.tgz
-
name: Login to the Docker container registry
if: needs.check_envoronment.outputs.action == 'publish'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Publish image
if: needs.check_envoronment.outputs.action == 'publish'
run: docker push ghcr.io/concrete5-community/docker5:base
generate_matrix:
name: Generate matrix
runs-on: ubuntu-latest
outputs:
generated-matrix: ${{ steps.generate-matrix.outputs.generated-matrix }}
steps:
-
name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: none
tools: none
coverage: none
-
name: Checkout
uses: actions/checkout@v3
-
name: Generate matrix
id: generate-matrix
run: ./.github/workflows/generate-matrix build.yml "$GITHUB_OUTPUT"
build:
name: Build ${{ matrix.data.image_tag }}
runs-on: ubuntu-latest
needs:
- check_envoronment
- build_base
- generate_matrix
if: needs.check_envoronment.outputs.action != 'none'
strategy:
matrix:
data: ${{ fromJSON(needs.generate_matrix.outputs.generated-matrix) }}
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Download base image
if: needs.check_envoronment.outputs.action == 'build'
uses: actions/download-artifact@v3
with:
name: base-image
path: /tmp/
-
name: Load base image
if: needs.check_envoronment.outputs.action == 'build'
run: docker load --input /tmp/base-image.tgz
-
name: Build with starting point ${{ matrix.data.c5_startingpoint }}
run: |
docker build \
--build-arg CCM_PHP_VERSION=${{ matrix.data.php_version }} \
--build-arg CCM_COMPOSER_VERSION=${{ matrix.data.composer_version }} \
--build-arg CCM_PHPUNIT_VERSION=${{ matrix.data.phpunit_version }} \
--build-arg CCM_C5_ARCHIVE=${{ matrix.data.c5_archive }} \
--build-arg CCM_STARTING_POINT=${{ matrix.data.c5_startingpoint }} \
--build-arg CCM_PATCH_ENVIRONMENT_ONLY=${{ matrix.data.patch_environment_only }} \
--tag ghcr.io/concrete5-community/docker5:${{ matrix.data.image_tag }} \
./installed
for additional_tag in ${{ matrix.data.additional_tags }}; do
docker tag ghcr.io/concrete5-community/docker5:${{ matrix.data.image_tag }} ghcr.io/concrete5-community/docker5:$additional_tag
done
-
name: Check that MariaDB works
run: docker run --rm --entrypoint='' ghcr.io/concrete5-community/docker5:${{ matrix.data.image_tag }} ccm-service start db
-
name: Remove base Docker image
if: needs.check_envoronment.outputs.action == 'publish'
run: docker rmi ghcr.io/concrete5-community/docker5:base || true
-
name: Login to the Docker container registry
if: needs.check_envoronment.outputs.action == 'publish'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Publish image
if: needs.check_envoronment.outputs.action == 'publish'
run: docker push --all-tags ghcr.io/concrete5-community/docker5