forked from devilbox/docker-php-fpm-5.2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
145 lines (119 loc) · 4.86 KB
/
Makefile
File metadata and controls
145 lines (119 loc) · 4.86 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
ifneq (,)
.error This Makefile requires GNU Make.
endif
# -------------------------------------------------------------------------------------------------
# Docker configuration
# -------------------------------------------------------------------------------------------------
DIR = .
FILE = Dockerfile
IMAGE = devilbox/php-fpm-5.2
TAG = latest
ARCH = linux/amd64
NO_CACHE =
# -------------------------------------------------------------------------------------------------
# Default Target
# -------------------------------------------------------------------------------------------------
.PHONY: help
help:
@echo "lint Lint project files and repository"
@echo
@echo "build Build Docker image"
@echo "rebuild Build Docker image without cache"
@echo
@echo "manifest-create Create multi-arch manifest"
@echo "manifest-push Push multi-arch manifest"
@echo
@echo "test Test built Docker image"
@echo "update-readme Update README.md with PHP modules"
@echo
@echo "tag [TAG=...] Retag Docker image"
@echo "login USER=... PASS=... Login to Docker hub"
@echo "push [TAG=...] Push Docker image to Docker hub"
# -------------------------------------------------------------------------------------------------
# Lint Targets
# -------------------------------------------------------------------------------------------------
.PHONY: lint
lint: lint-workflow
.PHONY: lint-workflow
lint-workflow:
@\
GIT_CURR_MAJOR="$$( git tag | sort -V | tail -1 | sed 's|\.[0-9]*$$||g' )"; \
GIT_CURR_MINOR="$$( git tag | sort -V | tail -1 | sed 's|^[0-9]*\.||g' )"; \
GIT_NEXT_TAG="$${GIT_CURR_MAJOR}.$$(( GIT_CURR_MINOR + 1 ))"; \
grep '^ MATRIX_REFS:' .github/workflows/nightly.yml | grep -Eo '\[.*\]' \
| while read -r i; do \
if ! echo "$${i}" | grep -- "\"$${GIT_NEXT_TAG}\"" >/dev/null; then \
echo "[ERR] New Tag required in .github/workflows/nightly.yml: $${GIT_NEXT_TAG}"; \
exit 1; \
else \
echo "[OK] Git Tag present in .github/workflows/nightly.yml: $${GIT_NEXT_TAG}"; \
fi \
done
# -------------------------------------------------------------------------------------------------
# Build Targets
# -------------------------------------------------------------------------------------------------
.PHONY: build
build:
docker build --platform $(ARCH) $(NO_CACHE) -t $(IMAGE):$(TAG) -f $(DIR)/$(FILE) $(DIR)
.PHONY: rebuild
rebuild: NO_CACHE=--no-cache
rebuild: pull-base-image
rebuild: build
# -------------------------------------------------------------------------------------------------
# Manifest Targets
# -------------------------------------------------------------------------------------------------
.PHONY: manifest-create
manifest-create:
@echo "docker manifest create \
$(IMAGE):$(TAG) \
$$( echo $(ARCH) | sed 's/,/ /g' | sed 's|/|-|g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1}"' -- )" \
| sed 's/\s\s*/ /g' \
| sed 's/--/\\\n --/g'
@echo "docker manifest create \
$(IMAGE):$(TAG) \
$$( echo $(ARCH) | sed 's/,/ /g' | sed 's|/|-|g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1}"' -- )" \
| bash
.PHONY: manifest-push
manifest-push:
docker manifest push $(IMAGE):$(TAG)
# -------------------------------------------------------------------------------------------------
# Test Targets
# -------------------------------------------------------------------------------------------------
.PHONY: test
test: _test-integration
test: update-readme
.PHONY: _test-integration
_test-integration:
./tests/test.sh $(IMAGE) $(ARCH)
.PHONY: update-readme
update-readme:
cat "./README.md" \
| perl -0 -pe "s/<!-- modules -->.*<!-- \/modules -->/<!-- modules -->\n$$(./tests/get-modules.sh $(IMAGE) $(ARCH))\n<!-- \/modules -->/s" \
> "./README.md.tmp"
yes | mv -f "./README.md.tmp" "./README.md"
# -------------------------------------------------------------------------------------------------
# Deploy Targets
# -------------------------------------------------------------------------------------------------
.PHONY: tag
tag:
docker tag $(IMAGE) $(IMAGE):$(TAG)
.PHONY: login
login:
yes | docker login --username $(USER) --password $(PASS)
.PHONY: push
push:
@$(MAKE) tag TAG=$(TAG)
docker push $(IMAGE):$(TAG)
.PHONY: push-arch
push-arch:
$(MAKE) tag TAG=$(TAG)-manifest-$(subst /,-,$(ARCH))
docker push $(IMAGE):$(TAG)-manifest-$(subst /,-,$(ARCH))
# -------------------------------------------------------------------------------------------------
# Helper Targets
# -------------------------------------------------------------------------------------------------
.PHONY: enter
enter:
docker run --rm --platform=$(ARCH) -it --entrypoint=bash $(ARG) $(IMAGE)
.PHONY: pull-base-image
pull-base-image:
@docker pull --platform $(ARCH) $(shell grep FROM Dockerfile | sed 's/^FROM\s*//g';)