@@ -2,7 +2,7 @@ ifneq (,)
2
2
.error This Makefile requires GNU Make.
3
3
endif
4
4
5
- .PHONY : build rebuild lint test _test-phpcbf-version _test-php-version _test-run tag pull login push enter
5
+ .PHONY : build rebuild lint test _test-phpcbf-version _test-php-version _test-run _get-php-version tag pull login push enter
6
6
7
7
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
8
8
@@ -69,33 +69,16 @@ _test-phpcbf-version:
69
69
fi ; \
70
70
echo " Success" ; \
71
71
72
- _test-php-version :
72
+ _test-php-version : _get-php-version
73
73
@echo " ------------------------------------------------------------"
74
74
@echo " - Testing correct PHP version"
75
75
@echo " ------------------------------------------------------------"
76
- @if [ " $( PHP) " = " latest" ]; then \
77
- echo " Fetching latest version from GitHub" ; \
78
- LATEST=" $$ ( \
79
- curl -L -sS https://github.com/php/php-src/releases \
80
- | tac | tac \
81
- | grep -Eo ' /php-[.0-9]+?\.[.0-9]+"' \
82
- | grep -Eo ' [.0-9]+' \
83
- | sort -V \
84
- | tail -1 \
85
- )" ; \
86
- echo " Testing for latest: $$ {LATEST}" ; \
87
- if ! docker run --rm --entrypoint=php $( IMAGE) --version | head -1 | grep -E " ^PHP[[:space:]]+$$ {LATEST}[[:space:]]" ; then \
88
- echo " Failed" ; \
89
- exit 1; \
90
- fi ; \
91
- else \
92
- echo " Testing for tag: $( PHP) .x" ; \
93
- if ! docker run --rm --entrypoint=php $( IMAGE) --version | head -1 | grep -E " ^PHP[[:space:]]+$( PHP) \.[.0-9]+[[:space:]]" ; then \
94
- echo " Failed" ; \
95
- exit 1; \
96
- fi ; \
76
+ @echo " Testing for tag: $( CURRENT_PHP_VERSION) "
77
+ @if ! docker run --rm --entrypoint=php $(IMAGE ) --version | head -1 | grep -E " ^PHP[[:space:]]+$( CURRENT_PHP_VERSION) ([.0-9]+)?" ; then \
78
+ echo " Failed" ; \
79
+ exit 1; \
97
80
fi ; \
98
- echo " Success" ; \
81
+ echo " Success" ;
99
82
100
83
_test-run :
101
84
@echo " ------------------------------------------------------------"
@@ -119,9 +102,13 @@ tag:
119
102
docker tag $(IMAGE ) $(IMAGE ) :$(TAG )
120
103
121
104
pull :
105
+ @echo " Pull base image"
122
106
@grep -E ' ^\s*FROM' Dockerfile \
123
107
| sed -e ' s/^FROM//g' -e ' s/[[:space:]]*as[[:space:]]*.*$$//g' \
108
+ | head -1 \
124
109
| xargs -n1 docker pull;
110
+ @echo " Pull target image"
111
+ docker pull php:$(PHP ) -cli-alpine
125
112
126
113
login :
127
114
yes | docker login --username $(USER ) --password $(PASS )
@@ -132,3 +119,18 @@ push:
132
119
133
120
enter :
134
121
docker run --rm --name $(subst /,-,$(IMAGE ) ) -it --entrypoint=/bin/sh $(ARG ) $(IMAGE ) :$(TAG )
122
+
123
+ # Fetch latest available PHP version for cli-alpine
124
+ _get-php-version :
125
+ $(eval CURRENT_PHP_VERSION = $(shell \
126
+ if [ " $( PHP) " = " latest" ]; then \
127
+ curl -L -sS https://hub.docker.com/api/content/v1/products/images/php \
128
+ | tac | tac \
129
+ | grep -Eo ' `[.0-9]+-cli-alpine' \
130
+ | grep -Eo ' [.0-9]+' \
131
+ | sort -u \
132
+ | tail -1; \
133
+ else \
134
+ echo $(PHP ) ; \
135
+ fi ; \
136
+ ))
0 commit comments