-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.mk
More file actions
executable file
·83 lines (71 loc) · 2.61 KB
/
deploy.mk
File metadata and controls
executable file
·83 lines (71 loc) · 2.61 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
#!/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
do : ## Deploy services, that is, assert ./.env file, setup machine, pull images, and (re)create and (re)start services
$(MAKE) --file="${SELF}" symlink
$(MAKE) --file="${SELF}" dotenv
$(MAKE) --file="${SELF}" setup
$(MAKE) --file="${SELF}" services
.PHONY : do
dotenv : ## Assert that all variables in `./.env.${ENVIRONMENT}.sample` are available in `./.env`
${dotenv_linter} diff /mnt/.env "/mnt/.env.${ENVIRONMENT}.sample"
.PHONY : dotenv
htpasswd : ## Create file ./nginx/.htpasswd if it does not exist
if [ ! -f ./nginx/.htpasswd ] ; then \
sudo touch ./nginx/.htpasswd && \
sudo chmod 644 ./nginx/.htpasswd ; \
fi
.PHONY : htpasswd
user : htpasswd ## Add user `${NAME}` (he/she will have access to restricted areas like staging and the Monit web interface with the correct password), for example, `./docker.mk user NAME=jdoe`
sudo htpasswd ./nginx/.htpasswd "${NAME}"
.PHONY : user
setup : OPTIONS =
setup : htpasswd ## Setup machine by running `ansible-playbook` with options `${OPTIONS}`, for example, `./docker.mk setup` or `./docker.mk OPTIONS="--start-at-task 'Install Monit'" setup`
./ansible-playbook.sh \
./setup.yaml \
${OPTIONS}
.PHONY : setup
services : ## (Re)create and (re)start services
docker compose up \
--no-build \
--no-deps \
--pull "always" \
--force-recreate \
--renew-anon-volumes \
--remove-orphans \
--wait ${SERVICE}
.PHONY : services
symlink : ## Confirm 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