-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
74 lines (64 loc) · 2.3 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
config ?= docker.config.env
include $(config)
export $(shell sed 's/=.*//' $(config))
all:
@echo ==================================================
@echo
@echo TASK LIST:
@echo - "make docker-build"
@echo - "make docker-run"
@echo - "make docker-stop"
@echo
@echo ==================================================
###############
# DOCKER TASKS#
###############
# Build the container
docker-build:
@echo Starting docker build...
docker build -t $(CONTAINER_TAG) ./
@echo ==================================================
@echo
@echo Done! - \"make docker-run\" to run this container
@echo
@echo ==================================================
RUNNING_CONTAINER := $(shell docker ps -f name=$(CONTAINER_NAME) | grep -w $(CONTAINER_NAME))
STOPPED_CONTAINER := $(shell docker ps -a -f name=$(CONTAINER_NAME) | grep -w $(CONTAINER_NAME))
docker-run:
# If there is no running container with same name
ifeq ($(strip $(RUNNING_CONTAINER)),)
# and if there isn no stopped container with same name
ifeq ($(strip $(STOPPED_CONTAINER)),)
@echo ==================================================
@echo
@echo Running the container...
@echo Container ID: `docker run -d --name $(CONTAINER_NAME) -p $(CONTAINER_PORT):80 $(CONTAINER_TAG)`
@echo Container \"$(CONTAINER_NAME)\" is running on \"localhost:8000\"
@echo
@echo ==================================================
else
# If there is no running container but there is a stopped container with same name
@echo ==================================================
@echo
@echo Running the container...
@echo "Container \"`docker start $(CONTAINER_NAME)`\" is running on \"localhost:8000\""
@echo
@echo ==================================================
endif
else
# If there is a running container with the same name
@echo ==================================================
@echo
@echo There is a container running with the same name \"$(CONTAINER_NAME)\"
@echo Try visiting localhost:$(CONTAINER_PORT)
@echo
@echo ==================================================
endif
docker-stop:
@echo ==================================================
@echo
@echo Stopping the container...
@echo Container \"`docker stop $(CONTAINER_NAME)`\" is stopped
@echo
@echo "=================================================="
.PHONY: docker-build docker-start docker-stop