-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
138 lines (108 loc) · 3.14 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
## dopos.github.io
## Static site powered by hugo
#:
SHELL = /bin/sh
CFG ?= .env
CFGSAMPLE ?= $(CFG).sample
DOT := .
DASH := -
APP_SITE ?= dopos.dev.lan
APP_TAG ?= $(subst $(DOT),$(DASH),$(APP_SITE))
USE_TLS ?= false
APP_ROOT ?= $(PWD)
DCAPE_TAG ?= dcape
DCAPE_NET ?= dcape
IMAGE ?= klakegg/hugo
IMAGE_VER ?= :0.79.0-pandoc-ci
DC_IMAGE ?= docker/compose
DC_VER ?= latest
define CONFIG_DEF
# ------------------------------------------------------------------------------
# dopos.github.io settings
# website host
APP_SITE=$(APP_SITE)
# Unique traefik router name
# Container name prefix
# Value is optional, derived from APP_SITE if empty
# APP_TAG=$(APP_TAG)
# Enable tls in traefik
# Values: [false]|true
USE_TLS=$(USE_TLS)
# hugo image name
IMAGE=$(IMAGE)
# hugo image version
IMAGE_VER=$(IMAGE_VER)
endef
export CONFIG_DEF
-include $(CFG)
export
.PHONY: all cfg start start-hook stop update up reup down dc help
all: help
# ------------------------------------------------------------------------------
## docker commands
#:
## start containers
up:
up: CMD=up -d www
up: dc
## restart and recreate containers
reup:
reup: CMD=up --force-recreate -d www
reup: dc
## stop & remove container(s)
down:
down: CMD=rm -f -s
down: dc
# $$PWD usage allows host directory mounts in child containers
# Thish works if path is the same for host, docker, docker-compose and child container
## run $(CMD) via docker-compose
dc: docker-compose.yml
@docker compose -p $$APP_TAG $(CMD)
dc-old:
@docker run --rm -i \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $$PWD:$$PWD -w $$PWD \
-e DCAPE_TAG -e DCAPE_NET -e APP_ROOT -e APP_TAG \
$(DC_IMAGE):$$DC_VER \
-p $(APP_TAG) --env-file $(CFG) \
$(CMD)
# ------------------------------------------------------------------------------
## hugo commands
#:
## init new hugo site
init: CMD=run app hugo new site .
init: dc
## generate site
gen: CMD=run app
gen: dc
## run hugo server
run: CMD=up -d dev
run: dc
run: log-and-down
# see https://stackoverflow.com/a/32788564
log-and-down:
@bash -c "trap 'trap - SIGINT SIGTERM ERR; $(MAKE) -s down' SIGINT SIGTERM ERR; docker logs -f $(APP_TAG)-dev-1"
# ------------------------------------------------------------------------------
## Application setup
#:
## generate config file
## (if not exists)
#init:
# @[ -f $(CFG) ] && { echo "$(CFG) already exists. Skipping" ; exit 0 ; } || true
# @echo "$$CONFIG_DEF" > $(CFG)
## generate config sample
## (if .env exists, its values will be used)
config: $(CFGSAMPLE)
$(CFGSAMPLE):
@echo "$$CONFIG_DEF" > $(CFGSAMPLE)
# ------------------------------------------------------------------------------
## Other
#:
# This code handles group header and target comment with one or two lines only
## list Makefile targets
## (this is default target)
help:
@grep -A 1 -h "^## " $(MAKEFILE_LIST) \
| sed -E 's/^--$$// ; /./{H;$$!d} ; x ; s/^\n## ([^\n]+)\n(## (.+)\n)*(.+):(.*)$$/" " "\4" "\1" "\3"/' \
| sed -E 's/^" " "#" "(.+)" "(.*)"$$/"" "" "" ""\n"\1 \2" "" "" ""/' \
| xargs printf "%s\033[36m%-15s\033[0m %s %s\n"