Skip to content

Commit e323a96

Browse files
committedApr 12, 2020
Build multiple PHP versions per git release tag
1 parent 8517eeb commit e323a96

File tree

3 files changed

+53
-85
lines changed

3 files changed

+53
-85
lines changed
 

‎README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ services:
215215
build:
216216
context: https://github.com/dirtsimple/php-server.git
217217
args:
218+
- PHP_VER=7.2 # build from php:7.2-fpm-alpine3.10
219+
- OS_VER=3.10
218220
- EXTRA_APKS=ghostscript graphviz
219221
- EXTRA_EXTS=xmlrpc pspell ldap memcached
220222
environment:
@@ -268,15 +270,13 @@ Builds of this image are tagged with multiple aliases to make it easy to pin spe
268270
* `7.1-1.x`, `7.1.33-1.x` -- PHP version plus container major release
269271
* `7.1.33-1.4.6` -- an exact PHP revision and container release
270272

271-
The `unstable` tag tracks the `master` branch during development, with the highest PHP version currently in test.
272-
273273
#### Version History
274274

275275
| Tags | PHP | nginx | mod lua | alpine | Notes |
276276
| ------------- | ------ | ------ | ------- | ------ | ----- |
277-
| 7.2.29-2.0.x | 7.2.29 | 1.16.2 | 0.10.15 | 3.10 | New extension build method for all 7.x-2.x versions |
278-
| 7.2.26-2.0.x | 7.2.26 | 1.14.2 | 0.10.15 | 3.9 ||
279-
| 7.1.33-2.0.x | 7.1.33 | 1.14.2 | 0.10.15 | 3.9 ||
277+
| 7.3-2.0.x | 7.3.13 | 1.14.2 | 0.10.15 | 3.9 | New extension build method for all 7.x-2.x versions |
278+
| 7.2-2.0.x | 7.2.26 | 1.14.2 | 0.10.15 | 3.9 ||
279+
| 7.1-2.0.x | 7.1.33 | 1.14.2 | 0.10.15 | 3.9 |`latest` tag currently tracks 7.1|
280280
| | | | | |   |
281281
| 7.2.26-1.4.x | 7.2.26 | 1.14.2 | 0.10.15 | 3.9 | Old extension build method used from here down |
282282
| 7.1.33-1.4.x | 7.1.33 | 1.14.2 | 0.10.15 | 3.9 ||

‎hooks/README.md

+47-79
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,28 @@ This directory is for controlling the build of multiple repository versions. It
44

55
When you have complex build rules, the docker hub UI is incredibly inconvenient, since you cannot edit existing build rules, the full tag/sourcename rules aren't visible, etc. So putting them in a file like this lets them be easily edited, revision-controlled, etc.
66

7-
This script is not project-specific; you can target any image by changing the `image:` line to target your project, and running `fetch` to get your initial settings, and then editing the file to match them. (See under [Implementation](#implementation), below.)
7+
### Build Rules
8+
9+
For each git release tag (e.g. 2.0.0, 2.0.1, etc.), we want to build multiple PHP versions. "Minor" versions are only accessible via an exact PHP version request, while "major" versions are also available under the major version tag variants. So `major 7.2.26` means to tag PHP 7.2.26 under the `7.2` tag as well as under 7.2.26. The "latest" tag is like "major", except that the version is also tagged as "latest".
10+
11+
```shell
12+
build-rules() {
13+
image "dirtsimple/php-server"
14+
15+
latest "7.1.33"
16+
major "7.2.26"
17+
major "7.3.13"
18+
19+
#minor "7.2.29" # alpine 3.10
20+
#minor "7.3.16"
21+
22+
#version "master" "unstable" Branch b62210f7-f252-4006-b1ad-c545d08bf969
23+
}
24+
```
825

926
### Basic Settings
1027

1128
```yaml
12-
image: dirtsimple/php-server # image name: this is the only required setting
1329
envvars: []
1430

1531
autotests: 'OFF' # 'OFF', 'SOURCE_ONLY', or 'SOURCE_AND_FORKS'
@@ -32,84 +48,30 @@ repo_links: false # boolean true or false; true equals "enable for base im
3248

3349
Each entry under `build_settings` describes a build rule. Note that UUIDs are optional, but should not be copied from one project or rule to another.
3450

35-
For convenience in specifying the rules, we'll define some variables first:
51+
For convenience in specifying the rules, we'll define some functions:
3652

3753
```shell
38-
# Pattern matches
39-
dot='[.]'
40-
num='[0-9]+'
41-
tail="$dot[0-9.]+"
42-
release="($num)$tail"
43-
export match="($tail)?-$release"
44-
45-
# Tag interpolation
46-
export major='{\1}'
47-
export minor='{\1}{\2}'
48-
export majorx="$major-{\3}.x"
49-
export minorx="$minor-{\3}.x"
50-
export all="{sourceref},$major,$minor,$majorx,$minorx"
51-
```
52-
53-
54-
55-
```yaml
56-
build_settings:
57-
58-
# Treat 7.1 tags as 'latest'
59-
- source_type: Tag
60-
source_name: "/^(7.1)\\(env.match)$/"
61-
tag: "\\(env.all),latest"
62-
build_context: /
63-
dockerfile: Dockerfile
64-
autobuild: true
65-
nocache: false
66-
uuid: e023fa4f-1a9d-48ba-bb96-65a999709273
67-
68-
# Build 7.2+ according to pattern
69-
- source_type: Tag
70-
source_name: "/^(7.[2-4])\\(env.match)$/"
71-
tag: "\\(env.all)"
72-
build_context: /
73-
dockerfile: Dockerfile
74-
autobuild: true
75-
nocache: false
76-
uuid: 4a4f8d0c-a522-4dc8-a7b4-ce5f876f39b6
77-
78-
# master is unstable
79-
- source_type: Branch
80-
source_name: "master"
81-
tag: "unstable"
82-
autobuild: true
83-
nocache: false
84-
build_context: /
85-
dockerfile: Dockerfile
86-
uuid: b62210f7-f252-4006-b1ad-c545d08bf969
87-
54+
latest(){ major "$1" "${2:+$2,}latest" "${@:3}"; }
55+
major(){ minor "$1" "${2:+$2,}${1%.*},${1%.*}-{sourceref},${1%.*}-{\\1}.x" "${@:3}"; }
56+
minor(){ version "([0-9]+)\\.[0-9.]+" "$1-{sourceref},$1-{\\1}.x${2:+,$2}" Tag "${@:3}"; }
57+
58+
version() {
59+
local t='jqmd_data({
60+
build_settings: [{
61+
source_type: "\($kind)",
62+
source_name: "/^\($match)$/",
63+
tag: "\($build)",
64+
autobuild: true,
65+
build_context: "/",
66+
dockerfile: "Dockerfile",
67+
nocache: false,
68+
"uuid":"\($uuid)"
69+
}]
70+
})'
71+
APPLY "$t" match="$1" build="$2" kind="${3:-Tag}" uuid="${4-}"
72+
}
8873
```
8974

90-
Legacy builds (not included in push):
91-
92-
~~~yaml
93-
build_settings:
94-
# Fixed version from master
95-
- source_type: Branch
96-
source_name: "master"
97-
tag: "latest"
98-
dockerfile: /
99-
autobuild: false
100-
nocache: true
101-
uuid: 3361111d-cbc9-4265-b626-861ffd552df0
102-
103-
# Any tag - disabled
104-
- source_type: Tag
105-
source_name: "/.*/"
106-
tag: "{sourceref}"
107-
autobuild: false
108-
nocache: true
109-
dockerfile: /
110-
uuid: e958e00e-88c1-41e2-ac37-2cab6a75ee33
111-
~~~
112-
11375
### Implementation
11476

11577
Here's the code that does the actual work. It's generic for any set of build rules, simply using the "image" property defined above to identify the image, and the `UNAME` and `UPASS` environment variables to authenticated with.
@@ -132,6 +94,8 @@ This will output your existing settings in JSON to use as a starting point for y
13294
Here's the actual runtime code:
13395

13496
```shell
97+
image() { IMAGE=$1; }
98+
13599
hub() { curl -s "${@:2}" https://hub.docker.com"$1"; }
136100
json() { "$@" -H "Content-Type: application/json" -d @-; }
137101
post() { "$@" -X POST; }
@@ -148,7 +112,6 @@ login() {
148112
}
149113

150114
find-image() {
151-
[[ $IMAGE ]] || IMAGE=$(RUN_JQ -r .image)
152115
[[ $SOURCE ]] || SOURCE=$(raw .objects[].resource_uri hub "/api/build/v1/source/?image=$IMAGE")
153116
}
154117

@@ -158,17 +121,22 @@ find-image() {
158121
} >&2
159122

160123
JQ_OPTS -n # generating, not filtering
124+
build-rules
125+
126+
[[ $IMAGE ]] || {
127+
echo '`image` must be defined in build-rules' >&2; exit 64
128+
}
161129

162130
case ${1-} in
163-
push) RUN_JQ 'del(.image)' | patch json auth config | jq . ;;
131+
push) RUN_JQ . | patch json auth config | jq . ;;
164132
dump) RUN_JQ . ;; # dump current settings as JSON
165133
fetch)
166134
# fetch existing settings and dump them to the console
167135
login; find-image; CLEAR_FILTERS; JQ_OPTS -n; JSON "$(auth config)"
168136
builds=$(RUN_JQ -r .build_settings[])
169137

170138
# Remove build_settings and things you can't change via PATCH
171-
FILTER 'del(.build_settings, .deploykey, .provider, .resource_uri, .state, .uuid)'
139+
FILTER 'del(.build_settings, .deploykey, .image, .provider, .resource_uri, .state, .uuid)'
172140
for setting in $builds; do
173141
JSON '{build_settings:[('"
174142
$(auth hub "$setting")

‎hooks/build

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
IMAGE_NAME=${IMAGE_NAME-dirtsimple/php-server:${DOCKER_TAG%%,*}}
44

55
case $DOCKER_TAG in
6-
7.1.*|7.2.26|7.3.13)
6+
7.1.*|7.2.26-*|7.3.13-*)
77
PHP_VER=${DOCKER_TAG%%-*}; OS_VER=3.9;;
88
7.*)
99
PHP_VER=${DOCKER_TAG%%-*}; OS_VER=3.10;;

0 commit comments

Comments
 (0)
Please sign in to comment.