-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (123 loc) · 3.74 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#
# Makefile for managing Docker Compose services.
# This Makefile includes targets for building, starting, stopping, and cleaning Docker services.
# It ensures that necessary dependencies are installed and Docker images are built with specified options.
#
#
# Makefile target names
#
ALL=all
DOWN=down
CLEAN=clean
BUILD_DEPENDS=build-depends
PIA_CREDS=pia-creds
BUILD=build
UP=up
LOGS=logs
HELP=help
RUN=run
#
# Docker Compose options
#
COMPOSE_SERVICE_NAME ?= privateerr
COMPOSE_DOWN_TIMEOUT ?= 30
COMPOSE_DOWN_OPTIONS ?= --timeout $(COMPOSE_DOWN_TIMEOUT) --rmi all --volumes
COMPOSE_BUILD_OPTIONS ?= --pull --no-cache
COMPOSE_UP_OPTIONS ?= --build --force-recreate --pull always
COMPOSE_LOGS_OPTIONS ?= --follow
#
# Build dependencies
#
DEPENDENCIES=docker docker-compose
#
# Path to Dockerfile
#
DOCKERFILE := docker/Dockerfile
#
# Extract base FROM image from Dockerfile
#
FROM_IMAGE=$(shell awk '/^FROM / { print $$2 }' $(DOCKERFILE) | sed 's/:.*//' | head -n 1)
#
# Targets that are not files (i.e. never up-to-date); these will run every
# time the target is called or required.
#
.PHONY: $(ALL) $(DOWN) $(CLEAN) $(BUILD_DEPENDS) $(BUILD) $(UP) $(LOGS) $(HELP) $(RUN)
#
# $(ALL): Default makefile target. Builds and starts the service stack.
#
$(ALL): $(UP)
#
# $(BUILD_DEPENDS): Ensure build dependencies are installed.
#
$(BUILD_DEPENDS):
$(foreach exe,$(DEPENDENCIES), \
$(if $(shell which $(exe) 2> /dev/null),,$(error "No $(exe) in PATH")))
#
# $(PIA_CREDS): Ensures Private Internet Access credentials are set.
#
$(PIA_CREDS):
@if [ -z "${PIA_USER}" ]; then \
echo "Please set PIA_USER"; \
exit 1; \
fi; \
if [ -z "${PIA_PASS}" ]; then \
echo "Please set PIA_PASS"; \
exit 1; \
fi
#
# $(DOWN): Stops containers and removes containers, networks, volumes, and images created by up.
#
$(DOWN): $(BUILD_DEPENDS)
@echo "\nStopping service $(COMPOSE_SERVICE_NAME)"
docker-compose down $(COMPOSE_DOWN_OPTIONS)
@echo "\nRemoving images based on $(FROM_IMAGE)"
@docker images -q "$(FROM_IMAGE)" | xargs -r docker rmi -f || true
#
# $(BUILD): Builds the service stack.
#
# Dependencies: $(BUILD_DEPENDS) - Ensure build dependencies are installed.
# $(PIA_CREDS) - Ensure Private Internet Access credentials are set.
#
$(BUILD): $(BUILD_DEPENDS) $(PIA_CREDS)
@echo "\nBuilding service $(COMPOSE_SERVICE_NAME)"
docker-compose build $(COMPOSE_BUILD_OPTIONS) $(COMPOSE_SERVICE_NAME)
#
# $(UP): Builds, (re)creates, and starts containers for services.
#
# Dependencies: $(BUILD_DEPENDS) - Ensure build dependencies are installed.
# $(PIA_CREDS) - Ensure Private Internet Access credentials are set.
#
$(UP): $(BUILD_DEPENDS) $(PIA_CREDS)
@echo "\nStarting service $(COMPOSE_SERVICE_NAME)"
docker-compose up $(COMPOSE_UP_OPTIONS)
#
# $(LOGS): View output from containers.
#
$(LOGS):
@echo "\nGetting logs for service $(COMPOSE_SERVICE_NAME)"
docker-compose logs $(COMPOSE_LOGS_OPTIONS)
#
# $(HELP): Print help information.
#
$(HELP):
@echo "Usage: make [TARGET]"
@echo ""
@echo "Targets:"
@echo " $(ALL) - Builds and starts the service stack."
@echo " $(BUILD_DEPENDS) - Ensures build dependencies are installed."
@echo " $(PIA_CREDS) - Ensures Private Internet Access credentials are set."
@echo " $(DOWN) - Stops and removes containers, networks, volumes, and images."
@echo " $(CLEAN) - Alias for $(DOWN)."
@echo " $(BUILD) - Builds the service stack."
@echo " $(UP) - Builds, (re)creates, and starts containers for services."
@echo " $(RUN) - Alias for $(UP)."
@echo " $(LOGS) - Shows logs for the service."
@echo " $(HELP) - Displays this help message."
#
# Alias for down
#
$(CLEAN): $(DOWN)
#
# Alias for up
#
$(RUN): $(UP)