forked from akatrevorjay/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile.docker
138 lines (106 loc) · 3.11 KB
/
Makefile.docker
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
# Do not:
# o use make's built-in rules and variables
# (this increases performance and avoids hard-to-debug behaviour);
# o print "Entering directory ...";
MAKEFLAGS += -rR --no-print-directory --warn-undefined-variables
DOCKER_USER ?= $(USER)
DOCKER_REPO ?= $(subst docker-,,$(notdir $(abspath .)))
REPO ?= ${DOCKER_USER}/${DOCKER_REPO}
# latest == LTS
# rolling == Latest release
# devel == Latest development release
UBUNTU_TAGS := xenial bionic
TAGS ?= $(UBUNTU_TAGS)
BUILD_TAG_PREFIX ?= build-
all: build
##
## Host build deps
##
HOST_BIN ?= host/bin
REPO_${HOST_BIN}/prefixout ?= github.com/akatrevorjay/$(notdir $@)
HOST_GOLANG_DEPS += ${HOST_BIN}/prefixout
HOST_DEPS += ${HOST_GOLANG_DEPS}
HOST_GOLANG_IMAGE = golang:1.8
HOST_GOLANG_BUILD_CMD ?= \
docker create -v /go/bin --name host-golang-build-out-$(notdir $@) busybox:latest /bin/true \
&& ( \
docker run --rm --volumes-from host-golang-build-out-$(notdir $@) ${HOST_GOLANG_IMAGE} go get -u -v $(REPO_$@) \
&& docker cp host-golang-build-out-$(notdir $@):/go/bin/$(notdir $@) $(abspath ${HOST_BIN}) \
); \
docker rm host-golang-build-out-$(notdir $@)
${HOST_GOLANG_DEPS}:
${HOST_GOLANG_BUILD_CMD}
test -e "$@"
##
## If we have project-level deps, we should likely build them I suppose.
##
ifneq ("$(wildcard Makefile.deps)","")
include Makefile.deps
endif
##
## Single
##
RUN_CMDS := bash bash-verbose bash-debug bash-trace
.PHONY: ${RUN_CMDS}
# default tag
TAG ?= $(firstword $(TAGS))
${RUN_CMDS}: TAGS = $(TAG)
${RUN_CMDS}: CMD = bash
${RUN_CMDS}: run
export ENTRYPOINT_DEBUG ENTRYPOINT_VERBOSE ENTRYPOINT_TRACE
bash-debug: ENTRYPOINT_DEBUG=1
bash-verbose: ENTRYPOINT_VERBOSE=1
bash-trace: ENTRYPOINT_TRACE=1
RUN_CMD ?= docker run -it --rm -v ${PWD}:/app
run: build
${RUN_CMD} \
-e ENTRYPOINT_VERBOSE=${ENTRYPOINT_VERBOSE} \
-e ENTRYPOINT_DEBUG=${ENTRYPOINT_DEBUG} \
-e ENTRYPOINT_TRACE=${ENTRYPOINT_TRACE} \
"${REPO}:${BUILD_TAG_PREFIX}${TAG}" \
${CMD}
##
## Lifecycle
##
.PHONY: $(TAGS)
.PHONY: all clean deps build test tag push
clean:
rm -rf $(addprefix Dockerfile.,$(TAGS))
distclean: clean
rm -rf ${HOST_DEPS} ${DEPS}
deps: ${HOST_DEPS} ${DEPS}
BUILD_ARGS ?=
$(TAGS): Dockerfile deps
-echo -- $@: REPO=${REPO} TAG=${TAG} BUILD_TAG=${BUILD_TAG_PREFIX}$@ >&2
"${HOST_BIN}/prefixout" -dtc --prefix "[$@] " -- \
docker build \
${BUILD_ARGS} \
-t "${REPO}:${BUILD_TAG_PREFIX}$@" \
.
build: $(TAGS)
@echo "-- $@: TAGS=${TAGS}" >&2
test: build
for TAG in $(TAGS); do \
BUILD_TAG="${BUILD_TAG_PREFIX}$${TAG}"; \
IMAGE="${REPO}:$${BUILD_TAG}"; \
\
./tests/run-tests "$$IMAGE"; \
done
tag: build
for TAG in $(TAGS) $(EXTRA_TAGS); do \
SRC_TAG="$${TAG#*=}"; \
TAG="$${TAG%=*}"; \
BUILD_TAG="${BUILD_TAG_PREFIX}$${SRC_TAG}"; \
echo "-- $@: [$${SRC_TAG}=$${TAG}] BUILD_TAG=$${BUILD_TAG}" >&2; \
\
docker tag "${REPO}:$${BUILD_TAG}" "${REPO}:$${TAG}"; \
done
push: tag
for TAG in $(TAGS) $(EXTRA_TAGS); do \
SRC_TAG="$${TAG#*=}"; \
TAG="$${TAG%=*}"; \
BUILD_TAG="${BUILD_TAG_PREFIX}$${SRC_TAG}"; \
echo "-- $@: [$${SRC_TAG}=$${TAG}] BUILD_TAG=$${BUILD_TAG}" >&2; \
\
docker push "${REPO}:$${TAG}"; \
done