-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·102 lines (80 loc) · 3.2 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
# PiArmy: Webserver
# 2017.06.01
# Matt J. Wiater <matt@brightpixel.com>
# To see all available targets, just type: make
# To build, type: make build
# The build target also runs dependencies in this order: clean -> stop -> build
# To run, type: make service
# Edit only the first value
# A Docker hub account is not required, but we'll be using it in the tutorials.
# This can be whatever you want if you'll just be developing locally.
DOCKER_USERNAME = mattwiater
# Port mapping
DOCKER_HOST_PORT_MAPPING = 80
DOCKER_CONTAINER_PORT_MAPPING = 80
# Host Port mapping
DOCKER_TASKNAME = piarmy-webserver
# Host Port mapping
DOCKER_NETWORK_NAME = piarmy
# Don't edit below this line
DOCKER_IMAGE_NAME = $(DOCKER_USERNAME)/$(DOCKER_TASKNAME)
# Get Image ID and Service ID if they are already running. This will allow us to stop/remove these in subsequent runs
IMAGE_ID = $(shell docker ps | awk -v pattern=$(DOCKER_TASKNAME) '$$0 ~ pattern{ print $$1 }')
IMAGE_SERVICE_ID = $(shell docker service ls | awk -v pattern=$(DOCKER_TASKNAME) '$$0 ~ pattern{ print $$1 }')
# Running make by itself will build the project
default: list
build: stop
@echo "Building image: $(DOCKER_IMAGE_NAME)"
@echo "--------------------"
@docker build -t $(DOCKER_IMAGE_NAME) .
@echo "--------------------"
@echo ""
stop: clean
ifeq ($(strip $(IMAGE_SERVICE_ID)),)
@echo "No matching services found for $(DOCKER_TASKNAME), nothing to do..."
@echo ""
else
@echo "Shutting down service: $(DOCKER_TASKNAME)"
@docker service rm $(DOCKER_TASKNAME) > /dev/null 2>&1
@echo ""
endif
ifeq ($(IMAGE_ID),)
@echo "No matching images found for $(DOCKER_TASKNAME), nothing to do..."
@echo ""
else
@echo "Removing image: $(IMAGE_ID)"
@docker rm --force $(IMAGE_ID) > /dev/null 2>&1
@echo ""
endif
clean:
clear
@echo "Removing DS Store files..."
@echo ""
$(shell find . -name ".DS_Store" -print0 | xargs -0 rm -rf)
$(shell find . -name "._*" -print0 | xargs -0 rm -rf)
shell: stop
@echo "Starting: $(DOCKER_IMAGE_NAME)"
@echo "Interactive mode: /bin/bash"
@echo ""
@docker run -it --rm --network=$(DOCKER_NETWORK_NAME) -p $(DOCKER_HOST_PORT_MAPPING):$(DOCKER_CONTAINER_PORT_MAPPING) --name=$(DOCKER_TASKNAME) $(DOCKER_IMAGE_NAME) /bin/bash
run: stop
@docker run -d --rm -v /home/pi/images/piarmy-webserver/containerFiles:/www --network=$(DOCKER_NETWORK_NAME) -p $(DOCKER_HOST_PORT_MAPPING):$(DOCKER_CONTAINER_PORT_MAPPING) --name=$(DOCKER_TASKNAME) $(DOCKER_IMAGE_NAME)
service: stop
docker service create \
--name=$(DOCKER_TASKNAME) \
--network=$(DOCKER_NETWORK_NAME) \
--replicas=4 \
-p $(DOCKER_HOST_PORT_MAPPING):$(DOCKER_CONTAINER_PORT_MAPPING) \
$(DOCKER_IMAGE_NAME):latest
enter:
@docker exec -it $$(docker ps | grep $(DOCKER_TASKNAME) | awk '{print $$1}') /bin/ash
commit:
docker commit $(IMAGE_ID) $(DOCKER_IMAGE_NAME)
push: build run commit
docker push $(DOCKER_IMAGE_NAME)
@echo "Pushed: $(DOCKER_IMAGE_NAME)"
@echo ""
@$(MAKE) stop
.PHONY: list
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs