-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
80 lines (57 loc) · 1.35 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
#
# Makefile for Docker Dister
#
# Note that this is for development and container image builds.
#
# How to invoke Docker
ifneq ($(shell id -u),0)
SUDO=sudo
DOCKER=$(SUDO) docker
else
SUDO=
DOCKER=docker
endif
default: run
# Protoype data directory for testing
DATA := $(shell pwd)/sample-data
# Where the build happens.
IMAGE := docker-dister
CONTAINER_NAME := docker-dister
BUILT := .built
$(BUILT): Dockerfile Makefile
$(DOCKER) build \
--tag $(IMAGE) \
.
touch $@
TO_CLEAN += $(BUILT)
build image: $(BUILT)
# Temporary container /data directory
TMP_DATA=/tmp/docker-dister-data
$(TMP_DATA):
$(SUDO) rm -rf "$@"
$(SUDO) mkdir -p "$@"
(cd $(DATA) && tar cf - .) | (cd "$@" && $(SUDO) tar xf -)
$(SUDO) chown -R root:root "$@"
TO_CLEAN_ROOT += $(TMP_DATA)
# Run the container and exit
run: $(BUILT) $(REPO) $(LOG) $(TMP_DATA)
$(DOCKER) run \
--rm \
--volume $(TMP_DATA):/data:Z \
--name "$(CONTAINER_NAME)" \
"$(IMAGE)"
# Log into the test container
shell:
$(DOCKER) exec -it "$(CONTAINER_NAME)" /bin/sh
# Stop the test container
halt:
$(DOCKER) exec -it "$(CONTAINER_NAME)" kill 1
# Remove the test container and its image
rm:
$(DOCKER) rm -f "$(CONTAINER_NAME)"
$(DOCKER) image rm -f "$(IMAGE)"
# Remove all build by-products
clean: rm
rm -rf $(TO_CLEAN)
$(SUDO) rm -rf $(TO_CLEAN_ROOT)
find . -name '*~' | xargs rm -f