-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker.mk
More file actions
executable file
·240 lines (214 loc) · 6.41 KB
/
docker.mk
File metadata and controls
executable file
·240 lines (214 loc) · 6.41 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env -S make --file
SELF := $(lastword $(MAKEFILE_LIST))
include ./.env
SHELL := /usr/bin/env bash
.SHELLFLAGS := -o errexit -o errtrace -o nounset -o pipefail -c
MAKEFLAGS += --warn-undefined-variables
COMPOSE_BAKE=true
SERVICE=
dotenv_linter = \
docker run \
--rm \
--user "$(shell id --user):$(shell id --group)" \
--volume "$(shell pwd):/mnt" \
--quiet \
dotenvlinter/dotenv-linter:4.0.0
# Taken from https://www.client9.com/self-documenting-makefiles/
help : ## Print this help
@awk -F ':|##' '/^[^\t].+?:.*?##/ {\
printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \
}' $(MAKEFILE_LIST)
.PHONY : help
.DEFAULT_GOAL := help
name : ## Print value of variable `NAME`
@echo ${NAME}
.PHONY : name
environment : ## Print value of variable `ENVIRONMENT`
@echo ${ENVIRONMENT}
.PHONY : environment
symlink : ## Confirm that ./Makefile links to ./docker.mk and that ./docker-compose.yaml links to the correct ./docker-compose.*.yaml
if [[ ! -L "./Makefile" ]] || [[ ! "./Makefile" -ef "./docker.mk" ]]; then \
echo "./docker-compose.yaml does not link to $${file}" >&2 ; \
exit 1 ; \
fi
if [[ "${ENVIRONMENT}" == "staging" ]]; then \
file="./docker-compose.production.yaml" ; \
else \
file="./docker-compose.${ENVIRONMENT}.yaml" ; \
fi && \
if [[ ! -L "./docker-compose.yaml" ]] || [[ ! "./docker-compose.yaml" -ef "$${file}" ]]; then \
echo "./docker-compose.yaml does not link to $${file}" >&2 ; \
exit 2 ; \
fi
.PHONY : symlink
dotenv : ## Assert that all variables in `./.env.${ENVIRONMENT}.sample` are available in `./.env`
${dotenv_linter} diff /mnt/.env "/mnt/.env.${ENVIRONMENT}.sample"
${dotenv_linter} diff /mnt/.env.development.sample /mnt/.env.production.sample
${dotenv_linter} diff /mnt/.env.production.buildingenvelopedata.sample /mnt/.env.production.sample
${dotenv_linter} diff /mnt/.env.production.solarbuildingenvelopes.sample /mnt/.env.production.sample
${dotenv_linter} diff /mnt/.env.development.buildingenvelopedata.sample /mnt/.env.development.sample
${dotenv_linter} diff /mnt/.env.development.solarbuildingenvelopes.sample /mnt/.env.development.sample
.PHONY : dotenv
pull : symlink dotenv ## Pull images
docker compose pull ${SERVICE}
.PHONY : pull
up : symlink dotenv ## (Re)create and (re)start services
docker compose up \
--no-build \
--no-deps \
--no-recreate \
--remove-orphans \
--wait ${SERVICE}
.PHONY : up
logs : ## Follow logs of services, for example, `make logs` for all services or `make logs SERVICE=reverse_proxy` or `make logs SERVICE="logs metrics"`
docker compose logs \
--since=1h \
--follow ${SERVICE}
.PHONY : logs
shell : ## Enter shell in the service `${SERVICE}`
docker compose up \
--no-build \
--no-deps \
--no-recreate \
--wait
${SERVICE}
docker compose exec \
${SERVICE} \
bash
.PHONY : shell
machine : ## Enter shell in the `machine` service for debugging and testing, for example by running `./docker.mk setup` or `./tools.mk check` inside entered shell
docker compose pull \
machine
docker compose build \
--pull \
--check \
--build-arg GROUP_ID=$(shell id --group) \
--build-arg USER_ID=$(shell id --user) \
machine
docker compose run \
--rm \
--remove-orphans \
machine \
bash
.PHONY : machine
down : ## Stop containers and remove containers, networks, volumes, and images created by `deploy`
docker compose down \
--remove-orphans ${SERVICE}
docker volume prune \
--force \
--filter "label=com.docker.compose.project=${NAME}"
.PHONY : down
restart : ## Restart services (and await their health), for example, `make restart` to restart all services or `make restart SERVICE=reverse_proxy` or `make restart SERVICE="database backend"`
docker compose restart \
--no-deps ${SERVICE}
docker compose up \
--no-build \
--no-deps \
--no-recreate \
--wait ${SERVICE}
.PHONY : restart
list : ## List all containers with health status
docker compose ps \
--no-trunc \
--all ${SERVICE}
.PHONY : list
list-services : ## List all services specified in the docker-compose file (used by Monit)
docker compose config \
--services
.PHONY : list-services
# See https://docs.docker.com/config/containers/runmetrics/
docker-stats : ## Show Docker run-time metrics
docker stats
.PHONY : docker-stats
reload-daemon : ## Reload Docker daemon
sudo systemctl \
reload docker
.PHONY : reload-daemon
shellcheck = \
docker run \
--rm \
--user $(shell id --user):$(shell id --group) \
--volume "$(shell pwd):/mnt" \
--quiet \
koalaman/shellcheck:v0.11.0 \
--enable=all \
--external-sources
dclint = \
docker run \
--rm \
--tty \
--user $(shell id --user):$(shell id --group) \
--volume "$(shell pwd):/app" \
--quiet \
zavoloklom/dclint:3.1.0 \
--config /app/.dclintrc
hadolint = \
docker run \
--rm \
--interactive \
--user $(shell id --user):$(shell id --group) \
--volume ./.hadolint.yaml:/.config/.hadolint.yaml \
--quiet \
hadolint/hadolint:v2.14.0-debian \
hadolint \
--config /.config/.hadolint.yaml
# docker run \
# --workdir / \
# --volume ./checkmake.ini:/checkmake.ini \
# --volume ./Makefile:/Makefile \
# --volume ./Makefile.development:/Makefile.development \
# quay.io/checkmake/checkmake \
# /Makefile \
# /Makefile.development
lint : ## Lint .env files, shell scripts, Docker Compose files, and Dockerfile
@echo Lint .env Files
${dotenv_linter} \
check \
--recursive \
--ignore-checks UnorderedKey \
.
@echo Lint Shell Scripts
${shellcheck} ./*.sh
@echo Lint Docker Compose Files
${dclint} .
@echo Lint Dockerfiles
${hadolint} - < ./Dockerfile.development
.PHONY : lint
fix : ## Fix .env files and Docker Compose linting violations
@echo Fix .env Files
${dotenv_linter} \
fix \
--no-backup \
--recursive \
--ignore-checks UnorderedKey \
.
@echo Fix Docker Compose Files
${dclint} --fix .
.PHONY : fix
format : ## Format shell scripts and Dockerfile
@echo Format Shell Scripts
docker run \
--rm \
--user $(shell id --user):$(shell id --group) \
--volume "$(shell pwd):/mnt" \
--workdir /mnt \
mvdan/shfmt:v3.13.0 \
--write \
--simplify \
--indent 2 \
--case-indent \
--space-redirects \
$(shell find . -name "*.sh" -printf "/mnt/%h/%f ")
@echo Format Dockerfile
docker run \
--rm \
--user $(shell id --user):$(shell id --group) \
--volume "$(shell pwd):/pwd" \
--pull "always" \
--quiet \
ghcr.io/reteps/dockerfmt:latest \
--indent 2 \
--newline \
--write \
$(shell find . -name "Dockerfile*" -printf "/pwd/%h/%f ")
.PHONY : format