forked from HariSekhon/Dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.in
170 lines (141 loc) · 3.91 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
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
#
# 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
#
ifneq ("$(wildcard bash-tools)", "")
BASH_TOOLS := bash-tools
else ifneq ("$(wildcard ../bash-tools)", "")
BASH_TOOLS := ../bash-tools
else
BASH_TOOLS := .
endif
ifndef TAG
TAG := $(shell perl -n -e '/^\s*ARG\s+.+_VERSION\s*=\s*"?(\d+\.\d+|latest)"?/ && &{ print $$1; exit }' Dockerfile)
endif
ifndef REPO
REPO :=
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
ifndef NOPORTS
NOPORTS :=
endif
ifndef RUN_ARGS
RUN_ARGS := bash
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: runcmd
runcmd:
@if [ -n "$(MAP_PORTS)" ]; then \
ports=$$(for port in $(MAP_PORTS); do echo "-p $$port:$$port "; done); \
echo docker run --rm $$ports $(REPO_TAG); \
elif [ -n "$(NOPORTS)" ]; then \
echo docker run --rm $(REPO_TAG); \
else \
echo docker run -ti --rm $(REPO_TAG) $(RUN_ARGS); \
fi
.PHONY: runcmd-fg
runcmd-fg:
@if [ -n "$(MAP_PORTS)" ]; then \
ports=$$(for port in $(MAP_PORTS); do echo "-p $$port:$$port "; done); \
echo docker run -ti --rm $$ports $(REPO_TAG); \
elif [ -n "$(NOPORTS)" ]; then \
echo docker run --rm $(REPO_TAG); \
else \
echo "docker run --rm $(REPO_TAG)"; \
fi
.PHONY: run
run:
@#$(MAKE) run | tee /dev/stderr | sh
@cmd=`$(MAKE) runcmd`; echo "$$cmd"; $$cmd
.PHONY: run-fg
run-fg:
@cmd=`$(MAKE) runcmd-fg`; echo "$$cmd"; $$cmd
.PHONY: sh
sh:
#make -e MAP_PORTS="" run
docker run -ti --rm -v $$PWD:/code $(REPO_TAG) sh
.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
.PHONY: interactive
interactive:
docker run -ti --rm -v $$PWD:/code `awk '/^FROM /{print $$2; exit}' Dockerfile` sh
.PHONY: browse
browse:
@source $(BASH_TOOLS)/.bash.d/network.sh; browser "https://github.com/harisekhon/dockerfiles"
.PHONY: github
github: browse
@:
.PHONY: github-url
github-url:
@source $(BASH_TOOLS)/.bash.d/functions.sh; echo "https://github.com/harisekhon/dockerfiles" | tee /dev/stderr | tr -d '\n' | paste_clipboard
.PHONY: dockerhub
dockerhub:
@source $(BASH_TOOLS)/.bash.d/network.sh; browser "https://hub.docker.com/r/$(REPO)"
.PHONY: dockerhub-url
dockerhub-url:
@source $(BASH_TOOLS)/.bash.d/functions.sh; echo "https://hub.docker.com/r/$(REPO)" | tee /dev/stderr | tr -d '\n' | paste_clipboard
.PHONY: dockerhub-status
dockerhub-status:
check_dockerhub_repo_build_status.py -r $(REPO)