-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
239 lines (214 loc) · 7.61 KB
/
Makefile
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
ifneq (,)
.error This Makefile requires GNU Make.
endif
# Ensure additional Makefiles are present
MAKEFILES = Makefile.docker Makefile.lint
$(MAKEFILES): URL=https://raw.githubusercontent.com/devilbox/makefiles/master/$(@)
$(MAKEFILES):
@if ! (curl --fail -sS -o $(@) $(URL) || wget -O $(@) $(URL)); then \
echo "Error, curl or wget required."; \
echo "Exiting."; \
false; \
fi
include $(MAKEFILES)
# Set default Target
.DEFAULT_GOAL := help
DOCKER_PULL_VARIABLES = PHP_IMG_TAG=$(PHP_IMG_TAG)
# -------------------------------------------------------------------------------------------------
# Default configuration
# -------------------------------------------------------------------------------------------------
# Own vars
TAG = latest
# Makefile.docker overwrites
NAME = pcf
VERSION = latest
IMAGE = cytopia/php-cs-fixer
FLAVOUR = latest
FILE = Dockerfile.${FLAVOUR}
DIR = Dockerfiles
# Extract PHP- and PCF- version from VERSION string
PHP_IMG_TAG = "cli-alpine"
ifeq ($(strip $(VERSION)),latest)
PHP_VERSION = latest
PCF_VERSION = latest
PHP_IMG_TAG = "cli-alpine"
else
PHP_VERSION = $(subst PHP-,,$(shell echo "$(VERSION)" | grep -Eo 'PHP-([.0-9]+|latest)'))
PCF_VERSION = $(subst PCF-,,$(shell echo "$(VERSION)" | grep -Eo 'PCF-([.0-9]+|latest)'))
PHP_IMG_TAG = $(PHP_VERSION)-cli-alpine
endif
# Extract Image version
ifeq ($(strip $(PHP_VERSION)),latest)
PHP_IMG_TAG = "cli-alpine"
endif
# Building from master branch: Tag == 'latest'
ifeq ($(strip $(TAG)),latest)
ifeq ($(strip $(VERSION)),latest)
DOCKER_TAG = $(FLAVOUR)
else
ifeq ($(strip $(FLAVOUR)),latest)
ifeq ($(strip $(PHP_VERSION)),latest)
DOCKER_TAG = $(PCF_VERSION)
else
DOCKER_TAG = $(PCF_VERSION)-php$(PHP_VERSION)
endif
else
ifeq ($(strip $(PHP_VERSION)),latest)
DOCKER_TAG = $(FLAVOUR)-$(PCF_VERSION)
else
DOCKER_TAG = $(FLAVOUR)-$(PCF_VERSION)-php$(PHP_VERSION)
endif
endif
endif
# Building from any other branch or tag: Tag == '<REF>'
else
ifeq ($(strip $(VERSION)),latest)
ifeq ($(strip $(FLAVOUR)),latest)
DOCKER_TAG = latest-$(TAG)
else
DOCKER_TAG = $(FLAVOUR)-latest-$(TAG)
endif
else
ifeq ($(strip $(FLAVOUR)),latest)
ifeq ($(strip $(PHP_VERSION)),latest)
DOCKER_TAG = $(PCF_VERSION)-$(TAG)
else
DOCKER_TAG = $(PCF_VERSION)-php$(PHP_VERSION)-$(TAG)
endif
else
ifeq ($(strip $(PHP_VERSION)),latest)
DOCKER_TAG = $(FLAVOUR)-$(PCF_VERSION)-$(TAG)
else
DOCKER_TAG = $(FLAVOUR)-$(PCF_VERSION)-php$(PHP_VERSION)-$(TAG)
endif
endif
endif
endif
# Makefile.lint overwrites
FL_IGNORES = .git/,.github/,tests/
SC_IGNORES = .git/,.github/,tests/
JL_IGNORES = .git/,.github/,./tests/
# -------------------------------------------------------------------------------------------------
# Default Target
# -------------------------------------------------------------------------------------------------
.PHONY: help
help:
@echo "lint Lint project files and repository"
@echo
@echo "build [ARCH=...] [TAG=...] Build Docker image"
@echo "rebuild [ARCH=...] [TAG=...] Build Docker image without cache"
@echo "push [ARCH=...] [TAG=...] Push Docker image to Docker hub"
@echo
@echo "manifest-create [ARCHES=...] [TAG=...] Create multi-arch manifest"
@echo "manifest-push [TAG=...] Push multi-arch manifest"
@echo
@echo "test [ARCH=...] Test built Docker image"
@echo
# -------------------------------------------------------------------------------------------------
# Docker Targets
# -------------------------------------------------------------------------------------------------
.PHONY: build
build: ARGS+=--build-arg PCF_VERSION=$(PCF_VERSION)
build: ARGS+=--build-arg PHP_IMG_TAG=$(PHP_IMG_TAG)
build: docker-arch-build
.PHONY: rebuild
rebuild: ARGS+=--build-arg PCF_VERSION=$(PCF_VERSION)
rebuild: ARGS+=--build-arg PHP_IMG_TAG=$(PHP_IMG_TAG)
rebuild: docker-arch-rebuild
.PHONY: push
push: docker-arch-push
# -------------------------------------------------------------------------------------------------
# Manifest Targets
# -------------------------------------------------------------------------------------------------
.PHONY: manifest-create
manifest-create: docker-manifest-create
.PHONY: manifest-push
manifest-push: docker-manifest-push
# -------------------------------------------------------------------------------------------------
# Test Targets
# -------------------------------------------------------------------------------------------------
.PHONY: test
test:
test: _test-php-cs-fixer-version
test: _test-php-version
test: _test-run
.PHONY: _test-php-cs-fixer-version
_test-php-cs-fixer-version:
@echo "------------------------------------------------------------"
@echo "- Testing correct phpcsf version"
@echo "------------------------------------------------------------"
@echo "Fetching latest version from GitHub"; \
if [ "$(PCF_VERSION)" = "latest" ]; then \
LATEST="$$( \
curl -L -sS https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases \
| tac | tac \
| grep -Eo 'tag/v?[.0-9]+?\.[.0-9]+"' \
| grep -Eo '[.0-9]+' \
| sort -V \
| tail -1 \
)"; \
echo "Testing for latest: $${LATEST}"; \
if ! docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) --version | grep -E "^PHP CS Fixer (version)?$${LATEST}"; then \
echo "Failed"; \
exit 1; \
fi; \
else \
echo "Testing for tag: $(PCF_VERSION).x.x"; \
if ! docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) --version | grep -E "^PHP CS Fixer (version[[:space:]])?$(PCF_VERSION)\.[.0-9]+"; then \
echo "Failed"; \
exit 1; \
fi; \
fi; \
echo "Success"; \
.PHONY: _test-php-version
_test-php-version: _get-php-version
@echo "------------------------------------------------------------"
@echo "- Testing correct PHP version"
@echo "------------------------------------------------------------"
@if [ "$(PCF_VERSION)" = "1" ] && [ "$(PHP_VERSION)" = "latest" ]; then \
echo "Testing for tag: 7.1.x"; \
if ! docker run --rm --platform $(ARCH) --entrypoint=php $(IMAGE):$(DOCKER_TAG) --version | head -1 | grep -E "^PHP[[:space:]]+7\.1\.[.0-9]+[[:space:]]"; then \
echo "Failed"; \
exit 1; \
fi; \
else \
echo "Testing for tag: $(CURRENT_PHP_VERSION)"; \
if ! docker run --rm --platform $(ARCH) --entrypoint=php $(IMAGE):$(DOCKER_TAG) --version | head -1 | grep -E "^PHP[[:space:]]+$(CURRENT_PHP_VERSION)([.0-9]+)?"; then \
echo "Failed"; \
exit 1; \
fi; \
fi; \
echo "Success"; \
.PHONY: _test-run
_test-run:
@echo "------------------------------------------------------------"
@echo "- Testing phpcsf (success)"
@echo "------------------------------------------------------------"
@if ! docker run --rm --platform $(ARCH) -v $(CURRENT_DIR)/tests/ok:/data $(IMAGE):$(DOCKER_TAG) fix --dry-run --diff .; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";
@echo "------------------------------------------------------------"
@echo "- Testing phpcsf (failure)"
@echo "------------------------------------------------------------"
@if docker run --rm --platform $(ARCH) -v $(CURRENT_DIR)/tests/fail:/data $(IMAGE):$(DOCKER_TAG) fix --dry-run --diff .; then \
echo "Failed"; \
exit 1; \
fi; \
echo "Success";
# Fetch latest available PHP version for cli-alpine
.PHONY: _get-php-version
_get-php-version:
$(eval CURRENT_PHP_VERSION = $(shell \
if [ "$(PHP_VERSION)" = "latest" ]; then \
curl -L -sS https://hub.docker.com/api/content/v1/products/images/php \
| tac | tac \
| grep -Eo '`[.0-9]+-cli-alpine' \
| grep -Eo '[.0-9]+' \
| sort -u \
| tail -1; \
else \
echo $(PHP_VERSION); \
fi; \
))