This repository was archived by the owner on Oct 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
119 lines (101 loc) · 3.15 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
.SILENT :
.PHONY : help volume mount build clean cleanup start rm debug shell test install uninstall
USERNAME:=ncarlier
APPNAME:=keeper
IMAGE:=$(USERNAME)/$(APPNAME)
env?=dev
define docker_run_flags
--rm \
--link mongodb:mongodb \
--link redis:redis \
--link elasticsearch:elasticsearch \
--env-file="./etc/default/$(env).env" \
--env-file="./etc/default/custom.env" \
-p 3000:3000 \
-i -t
endef
DOCKER=docker
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
DOCKER=sudo docker
endif
all: build cleanup
## This help screen
help:
printf "Available targets:\n\n"
awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf "%-15s %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
## Make the volume image
volume:
echo "Building $(APPNAME) volumes..."
$(DOCKER) run -v $(PWD):/usr/src/$(APPNAME) -v ~/var/$(APPNAME):/var/opt/$(APPNAME) --name $(APPNAME)_volumes busybox true
## Mount volumes
mount:
$(eval docker_run_flags += --volumes-from $(APPNAME)_volumes)
echo "Using volumes from $(APPNAME)_volumes"
## Build the image
build:
echo "Building $(IMAGE) docker image..."
$(DOCKER) build --rm -t $(IMAGE) .
## Remove the image
clean:
echo "Removing $(IMAGE) docker image..."
-$(DOCKER) rmi $(IMAGE)
## Remove dangling images
cleanup:
echo "Removing dangling docker images..."
-$(DOCKER) images -q --filter 'dangling=true' | xargs sudo docker rmi
## Start the container
start:
echo "Starting $(IMAGE) docker image..."
$(DOCKER) run $(docker_run_flags) --name $(APPNAME) $(IMAGE)
## Delete the container
rm:
echo "Deleting container $(APPNAME) ..."
-$(DOCKER) rm $(APPNAME)
## Run the container in debug mode
debug:
echo "Running $(IMAGE) docker image in DEBUG mode..."
$(DOCKER) run $(docker_run_flags) -p 3333:8080 --name $(APPNAME) $(IMAGE) run debug
## Run the container with shell access
shell:
echo "Running $(IMAGE) docker image with shell access..."
$(DOCKER) run $(docker_run_flags) --entrypoint="/bin/bash" $(IMAGE) -c /bin/bash
## Run the container in test mode
test:
echo "Running tests..."
$(DOCKER) run $(docker_run_flags) $(IMAGE) test
## Install as a service (needs root privileges)
install: build
echo "Install as a service..."
cp etc/systemd/system/* /etc/systemd/system/
cp etc/default/$(env).env /etc/default/$(APPNAME)
cp etc/blacklist.txt /var/opt/$(APPNAME)/
systemctl daemon-reload
systemctl enable $(APPNAME)-server
systemctl restart $(APPNAME)-server
systemctl enable $(APPNAME)-downloader
systemctl restart $(APPNAME)-downloader
systemctl enable $(APPNAME)-backup.timer
systemctl restart $(APPNAME)-backup.timer
$(MAKE) cleanup
## Un-install service (needs root privileges)
uninstall:
echo "Un-install service..."
systemctl stop $(APPNAME)-server
systemctl disable $(APPNAME)-server
systemctl stop $(APPNAME)-downloader
systemctl disable $(APPNAME)-downloader
systemctl stop $(APPNAME)-backup.timer
systemctl disable $(APPNAME)-backup.timer
rm /etc/systemd/system/keeper-*
rm /etc/default/$(APPNAME)
systemctl daemon-reload
$(MAKE) rm clean