-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
155 lines (134 loc) · 6.45 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
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
# -------------------------------------------------------------------------------------------------
# Default configuration
# -------------------------------------------------------------------------------------------------
# Own vars
TAG = latest
# Makefile.docker overwrites
NAME = Apache
VERSION = 2.4
IMAGE = devilbox/apache-$(VERSION)
FLAVOUR = latest
DIR = Dockerfiles
FILE = Dockerfile.$(FLAVOUR)
ifeq ($(strip $(FLAVOUR)),latest)
DOCKER_TAG = $(TAG)
else
ifeq ($(strip $(TAG)),latest)
DOCKER_TAG = $(FLAVOUR)
else
DOCKER_TAG = $(FLAVOUR)-$(TAG)
endif
endif
ARCH = linux/amd64
# -------------------------------------------------------------------------------------------------
# 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 ARCH=$(ARCH)
build: docker-arch-build
.PHONY: rebuild
rebuild: ARGS=--build-arg ARCH=$(ARCH)
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:
./tests/start-ci.sh $(IMAGE) $(DOCKER_TAG) $(ARCH)
# -------------------------------------------------------------------------------------------------
# Internal Repository Targets
# -------------------------------------------------------------------------------------------------
.PHONY: _repo_fix
_repo_fix: __repo_fix_examples
_repo_fix: __repo_fix_doc
_repo_fix: __repo_fix_readme
###
### In case I've copied the examples/ from any repo, ensure to replace images with current
###
.PHONY: __repo_fix_examples
__repo_fix_examples:
find examples/ -type f -print0 | xargs -0 -n1 sh -c \
'if grep "nginx-stable" "$${1}">/dev/null; then sed -i"" "s|devilbox/nginx-stable|$(IMAGE)|g" "$${1}";fi' --
find examples/ -type f -print0 | xargs -0 -n1 sh -c \
'if grep "nginx-mainline" "$${1}">/dev/null; then sed -i"" "s|devilbox/nginx-mainline|$(IMAGE)|g" "$${1}";fi' --
find examples/ -type f -print0 | xargs -0 -n1 sh -c \
'if grep "apache-2.2" "$${1}">/dev/null; then sed -i"" "s|devilbox/apache-2.2|$(IMAGE)|g" "$${1}";fi' --
find examples/ -type f -print0 | xargs -0 -n1 sh -c \
'if grep "apache-2.4" "$${1}">/dev/null; then sed -i"" "s|devilbox/apache-2.4|$(IMAGE)|g" "$${1}";fi' --
###
### In case I've copied the doc/ from any repo, ensure to replace images with current
###
.PHONY: __repo_fix_doc
__repo_fix_doc:
find doc/ -name '*.md' -type f -print0 | xargs -0 -n1 sh -c \
'if grep "nginx-stable" "$${1}">/dev/null; then sed -i"" "s|devilbox/nginx-stable|$(IMAGE)|g" "$${1}";fi' --
find doc/ -name '*.md' -type f -print0 | xargs -0 -n1 sh -c \
'if grep "nginx-mainline" "$${1}">/dev/null; then sed -i"" "s|devilbox/nginx-mainline|$(IMAGE)|g" "$${1}";fi' --
find doc/ -name '*.md' -type f -print0 | xargs -0 -n1 sh -c \
'if grep "apache-2.2" "$${1}">/dev/null; then sed -i"" "s|devilbox/apache-2.2|$(IMAGE)|g" "$${1}";fi' --
find doc/ -name '*.md' -type f -print0 | xargs -0 -n1 sh -c \
'if grep "apache-2.4" "$${1}">/dev/null; then sed -i"" "s|devilbox/apache-2.4|$(IMAGE)|g" "$${1}";fi' --
###
### In case I've copied the doc/ from any repo, ensure to replace images with current
###
.PHONY: __repo_fix_readme
__repo_fix_readme:
sed -i'' "s/^# Nginx stable$$/# $(NAME) $(VERSION)/g" README.md
sed -i'' "s/^# Nginx mainline$$/# $(NAME) $(VERSION)/g" README.md
sed -i'' "s/^# Apache 2.2$$/# $(NAME) $(VERSION)/g" README.md
sed -i'' "s/^# Apache 2.4$$/# $(NAME) $(VERSION)/g" README.md
@#
sed -i'' "s|docker--nginx--stable|$$( echo "docker/$(IMAGE)" | awk -F'/' '{print $$1"-"$$3}' | awk -F'-' '{print $$1"--"$$2"--"$$3}' )|g" README.md
sed -i'' "s|docker--nginx--mainline|$$( echo "docker/$(IMAGE)" | awk -F'/' '{print $$1"-"$$3}' | awk -F'-' '{print $$1"--"$$2"--"$$3}' )|g" README.md
sed -i'' "s|docker--apache--2.2|$$( echo "docker/$(IMAGE)" | awk -F'/' '{print $$1"-"$$3}' | awk -F'-' '{print $$1"--"$$2"--"$$3}' )|g" README.md
sed -i'' "s|docker--apache--2.4|$$( echo "docker/$(IMAGE)" | awk -F'/' '{print $$1"-"$$3}' | awk -F'-' '{print $$1"--"$$2"--"$$3}' )|g" README.md
@#
sed -i'' "s|docker-nginx-stable|$$( echo "docker-/$(IMAGE)" | awk -F'/' '{print $$1$$3}')|g" README.md
sed -i'' "s|docker-nginx-mainline|$$( echo "docker-/$(IMAGE)" | awk -F'/' '{print $$1$$3}')|g" README.md
sed -i'' "s|docker-apache-2.2|$$( echo "docker-/$(IMAGE)" | awk -F'/' '{print $$1$$3}')|g" README.md
sed -i'' "s|docker-apache-2.4|$$( echo "docker-/$(IMAGE)" | awk -F'/' '{print $$1$$3}')|g" README.md
@#
sed -i'' 's|devilbox/nginx-stable|$(IMAGE)|g' README.md
sed -i'' 's|devilbox/nginx-mainline|$(IMAGE)|g' README.md
sed -i'' 's|devilbox/apache-2.2|$(IMAGE)|g' README.md
sed -i'' 's|devilbox/apache-2.4|$(IMAGE)|g' README.md