forked from HariSekhon/Dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.in
122 lines (105 loc) · 2.84 KB
/
Makefile.in
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
#
# Author: Hari Sekhon
# Date: 2016-01-16 12:21:15 +0000 (Sat, 16 Jan 2016)
#
# vim:ts=4:sts=4:sw=4:noet
#
# https://github.com/harisekhon/Dockerfiles
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help improve or steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
ifeq "$(TAG)" ""
TAG := $(shell perl -n -e '/^\s*ARG\s+.+_VERSION\s*=\s*"?(\d+\.\d+|latest)"?/ && &{ print $$1; exit }' Dockerfile)
endif
# cassandra-dev -> cassandra
# consul-dev -> consul
# solrcloud-dev -> solrcloud
# rabbitmq-cluster -> rabbitmq
# solrloud -> solr
# presto-cli -> presto
BRANCH = $(shell echo "$(REPO)" | sed 's,.*/,,; s/-dev$$//; s/-cli$$//; s/-cluster$$//; s/cloud$$//')
ifndef MAP_PORTS
MAP_PORTS := ""
endif
ifdef LATEST
TAG=latest
endif
ifneq "$(TAG)" ""
REPO_TAG := "$(REPO):$(TAG)"
else
REPO_TAG := "$(REPO)"
endif
.PHONY: build
build:
docker build -t $(REPO_TAG) .
.PHONY: nocache
nocache:
docker build -t $(REPO_TAG) --no-cache .
.PHONY: build-versions
build-versions:
@echo "Building all versions from branches with base '$(BRANCH)'"
for x in $$(git branch -a | grep $(BRANCH) | sed 's,remotes/origin/,,' | sort -u); do \
git checkout "$$x" && \
$(MAKE) build && \
echo || \
exit 1; \
done; \
git checkout master
.PHONY: build-push-versions
build-push-versions: build-versions push-versions
:
.PHONY: push
push:
docker push $(REPO_TAG)
[ -f hooks/post_build ] && hooks/post_build || :
# use 'make push' rather than just 'docker push' to trigger hooks/post_build
.PHONY: push-versions
push-versions:
for x in $$(git branch -a | grep $(BRANCH) | sed 's,remotes/origin/,,' | sort -u); do \
git checkout "$$x" && \
$(MAKE) push && \
echo || \
exit 1; \
done; \
git checkout master
.PHONY: up
up: build test push
:
.PHONY: run
run:
@if [ -n "$(MAP_PORTS)" ]; then \
ports=$$(for port in $(MAP_PORTS); do echo "-p $$port:$$port "; done); \
echo docker run -ti $$ports $(REPO_TAG); \
docker run -ti $$ports $(REPO_TAG); \
elif [ -n "$(NOPORTS)" ]; then \
echo docker run -ti $(REPO_TAG); \
docker run -ti $(REPO_TAG); \
else \
echo "docker run -ti $(REPO_TAG) bash"; \
docker run -ti $(REPO_TAG) bash; \
fi
.PHONY: run-foreground
run-foreground:
@if [ -n "$(MAP_PORTS)" ]; then \
ports=$$(for port in $(MAP_PORTS); do echo "-p $$port:$$port "; done); \
echo docker run -ti $$ports $(REPO_TAG); \
docker run $$ports $(REPO_TAG); \
elif [ -n "$(NOPORTS)" ]; then \
echo docker run $(REPO_TAG); \
docker run $(REPO_TAG); \
else \
echo "docker run $(REPO_TAG)"; \
docker run $(REPO_TAG); \
fi
.PHONY: run-fg
run-fg: run-foreground
:
.PHONY: sh
sh:
make -e MAP_PORTS="" run
.PHONY: test
test:
#docker run -ti $(REPO) sh -c 'if test -f tests/all.sh; then tests/all.sh; fi;'
docker run -ti $(REPO) tests/all.sh