-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (46 loc) · 1.51 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
# We use "pwd" as this Makefile is usually imported from outside and we want to reference outer Makefile working
# directory
CURRENT_PATH := $(shell pwd)
CURRENT_DIR := $(shell basename ${CURRENT_PATH})
DOCKER_IMAGE := ${CURRENT_DIR}
DOCKER_CONTAINER := ${CURRENT_DIR}
ADDITIONAL_OPTIONS := ""
DOCKER_RUN_CMD = \
if [ $$(docker ps -q -f name=${DOCKER_CONTAINER}) ]; then \
docker kill --signal SIGINT ${DOCKER_CONTAINER}; \
fi; \
if [ $$(docker ps --all -q -f name=${DOCKER_CONTAINER}) ]; then \
docker rm -f ${DOCKER_CONTAINER}; \
fi; \
docker run \
--init \
--name ${DOCKER_CONTAINER} \
-v ${PWD}/data:/app/data \
--user $$(id -u):$$(id -g) \
$${ADDITIONAL_OPTIONS} \
${DOCKER_IMAGE}
.PHONY: list
vars:
echo Docker image: ${DOCKER_IMAGE}
build:
@echo "Building ${DOCKER_CONTAINER} docker image"; \
docker build . -t ${DOCKER_IMAGE}
run-it:
@echo "Running ${DOCKER_CONTAINER} interactively"; \
export ADDITIONAL_OPTIONS="-it --rm"; \
${DOCKER_RUN_CMD}
run-daemon:
@echo "Running ${DOCKER_CONTAINER} as daemon"; \
export ADDITIONAL_OPTIONS="-d --restart=always"; \
${DOCKER_RUN_CMD}
stop:
@if [ $$(docker ps -aq -f name=${DOCKER_CONTAINER}) ]; then \
if [ $$(docker ps -q -f name=${DOCKER_CONTAINER}) ]; then \
echo 'Stopping container ...'; \
docker stop ${DOCKER_CONTAINER} || /bin/true; \
fi; \
echo 'Removing container...'; \
docker rm -f ${DOCKER_CONTAINER}; \
else \
echo "Container ${DOCKER_CONTAINER} does not exist"; \
fi