-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
165 lines (142 loc) · 4.79 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
# -------------------------------------------------------------------------------------------------
# VARIABLES AND CONFIGURATION
# -------------------------------------------------------------------------------------------------
DOCKERFILES = .
IMAGE = devilbox/varnish
# -------------------------------------------------------------------------------------------------
# DEFAULT TARGET
# -------------------------------------------------------------------------------------------------
## Show this help
help:
@printf "Available targets:\n\n"
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " %-20s %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
# -------------------------------------------------------------------------------------------------
# BUILD TARGETS
# -------------------------------------------------------------------------------------------------
## Build all
build: build-4 build-5 build-6
## Rebuild all (without cache)
rebuild: rebuild-4 rebuild-5 rebuild-6
## Build Varnish 4
build-4:
docker build -t $(IMAGE):4 -f $(DOCKERFILES)/Dockerfile-4 $(DOCKERFILES)
## Build Varnish 5
build-5:
docker build -t $(IMAGE):5 -f $(DOCKERFILES)/Dockerfile-5 $(DOCKERFILES)
## Build Varnish 6
build-6:
docker build -t $(IMAGE):6 -f $(DOCKERFILES)/Dockerfile-6 $(DOCKERFILES)
## Rebuild Varnish 4 (without cache)
rebuild-4:
docker build --no-cache -t $(IMAGE):4 -f $(DOCKERFILES)/Dockerfile-4 $(DOCKERFILES)
## Rebuild Varnish 5 (without cache)
rebuild-5:
docker build --no-cache -t $(IMAGE):5 -f $(DOCKERFILES)/Dockerfile-5 $(DOCKERFILES)
## Rebuild Varnish 6 (without cache)
rebuild-6:
docker build --no-cache -t $(IMAGE):6 -f $(DOCKERFILES)/Dockerfile-6 $(DOCKERFILES)
# -------------------------------------------------------------------------------------------------
# TEST TARGETS
# -------------------------------------------------------------------------------------------------
## Test Varnish 4
test-4:
@$(MAKE) _clean
@$(MAKE) _start-test VERSION=4
if ! curl -IsS localhost:8080 | grep 'X-Server' | grep 'Varnish 4'; then \
curl -IsS localhost:8080 || true; \
curl -sS localhost:8080 || true; \
@$(MAKE) _clean; \
exit 1; \
fi
if ! curl -IsS localhost:8080 | grep 'X-Powered-By' | grep Devilbox; then \
curl -IsS localhost:8080 || true; \
curl -sS localhost:8080 || true; \
@$(MAKE) _clean; \
exit 1; \
fi
@$(MAKE) _clean
## Test Varnish 5
test-5:
@$(MAKE) _clean
@$(MAKE) _start-test VERSION=5
if ! curl -IsS localhost:8080 | grep 'X-Server' | grep 'Varnish 5'; then \
curl -IsS localhost:8080 || true; \
curl -sS localhost:8080 || true; \
@$(MAKE) _clean; \
exit 1; \
fi
if ! curl -IsS localhost:8080 | grep 'X-Powered-By' | grep Devilbox; then \
curl -IsS localhost:8080 || true; \
curl -sS localhost:8080 || true; \
@$(MAKE) _clean; \
exit 1; \
fi
@$(MAKE) _clean
## Test Varnish 6
test-6:
@$(MAKE) _clean
@$(MAKE) _start-test VERSION=6
if ! curl -IsS localhost:8080 | grep 'X-Server' | grep 'Varnish 6'; then \
curl -IsS localhost:8080 || true; \
curl -sS localhost:8080 || true; \
@$(MAKE) _clean; \
exit 1; \
fi
if ! curl -IsS localhost:8080 | grep 'X-Powered-By' | grep Devilbox; then \
curl -IsS localhost:8080 || true; \
curl -sS localhost:8080 || true; \
@$(MAKE) _clean; \
exit 1; \
fi
@$(MAKE) _clean
# -------------------------------------------------------------------------------------------------
# PUSH TARGETS
# -------------------------------------------------------------------------------------------------
## Push Varnish 4 to Dockerhub
push-4:
ifndef TAG
docker push $(IMAGE):4
else
docker tag $(IMAGE):4 $(IMAGE):$(TAG)
docker push $(IMAGE):$(TAG)
endif
## Push Varnish 5 to Dockerhub
push-5:
ifndef TAG
docker push $(IMAGE):5
else
docker tag $(IMAGE):5 $(IMAGE):$(TAG)
docker push $(IMAGE):$(TAG)
endif
## Push Varnish 6 to Dockerhub
push-6:
ifndef TAG
docker push $(IMAGE):6
@# If no custom tag is specified, Varnish 6 will also push Varnish latest
docker tag $(IMAGE):6 $(IMAGE):latest
docker push $(IMAGE):latest
else
docker tag $(IMAGE):6 $(IMAGE):$(TAG)
docker push $(IMAGE):$(TAG)
endif
# -------------------------------------------------------------------------------------------------
# INTERNAL HELPER TARGETS
# -------------------------------------------------------------------------------------------------
_clean:
@cd tests/ && docker-compose stop || true
@cd tests/ && docker-compose kill || true
@cd tests/ && docker-compose rm -f || true
@rm -f tests/.env || true
_start-test:
while ! docker pull nginx; do sleep 1; done;
echo "VARNISH_SERVER=$(VERSION)" > tests/.env
cd tests/ && docker-compose up -d
sleep 5;