-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
209 lines (161 loc) · 5.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
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
## dcape Makefile.
## Application environment commands
#:
SHELL = /bin/bash
CFG = .dcape.env
CFG_BAK ?= .env.bak
#- ******************************************************************************
#- DCAPE: general config
#- dcape containers hostname domain
DCAPE_DOMAIN ?= dev.test
#- dcape root directory
DCAPE_ROOT ?= $(PWD)
#- container name prefix
DCAPE_TAG ?= dcape
#- CICD & Gitea admin user name
DCAPE_ADMIN_USER ?= dcapeadmin
#- VCS OAuth app owner group
#- user group with access to auth protected resources
DCAPE_ADMIN_ORG ?= dcape
#- dcape apps
#- calculated by install
#- used in make only
APPS ?=
# internal makefile var
DCAPE_STACK = yes
#- ------------------------------------------------------------------------------
#- DCAPE: internal config
#- dcape services frontend hostname
DCAPE_HOST ?= $(DCAPE_DOMAIN)
#- docker network name
DCAPE_NET ?= $(DCAPE_TAG)
#- docker internal network name
DCAPE_NET_INTRA ?= $(DCAPE_TAG)_intra
#- create db cluster with this timezone
#- (also used by containers)
TZ ?= $(shell cat /etc/timezone)
#- docker network subnet
DCAPE_SUBNET ?= 100.127.0.0/24
#- docker intra network subnet
DCAPE_SUBNET_INTRA ?= 100.127.255.0/24
#- Deployment persistent storage, relative
DCAPE_VAR ?= $(DCAPE_ROOT)/var
#- Powerdns API key for DNS-01 ACME challenges
#- set in pdns, used in traefik
DCAPE_PDNS_API_KEY ?= $(shell openssl rand -hex 16; echo)
#- (auto) http(s)
DCAPE_SCHEME ?=
#- gitea url
AUTH_URL ?= $(AUTH_SERVER)
#- db container
DB_CONTAINER ?= $(DCAPE_TAG)-db-1
#- network DCAPE_NET already exists
DCAPE_NET_EXISTS ?= false
#- gitea allowed webhook host
CICD_HOST ?= cicd.$(DCAPE_DOMAIN)
ENFIST_URL ?= http://enfist:8080/rpc
# helpers, use: make echo-dcape-version
DCAPE_VERSION ?= $(shell git describe --tags --always)
DCAPE_RELEASE ?= $(shell git describe --tags --abbrev=0 --always)
#- ------------------------------------------------------------------------------
-include $(CFG_BAK)
-include $(CFG)
export
all: help
ifneq ($(findstring $(MAKECMDGOALS),install oauth-again config-upgrade after-upgrade .setup-app),)
include Makefile.install
endif
APPS_DIRS = $(addprefix apps/_,$(APPS))
# make a list $APP -> -f apps/$APP/docker-compose.inc.yml
DC_SOURCES = $(addsuffix /docker-compose.inc.yml,$(APPS_DIRS))
DC_SRC_ARG = $(addprefix -f ,$(DC_SOURCES))
# make a list $APP -> --env-file apps/$APP/.env
DC_ENV_SOURCES = .dcape.env $(addsuffix /.env,$(APPS_DIRS))
DC_ENV_ARG = $(addprefix --env-file ,$(DC_ENV_SOURCES))
DC_INC = docker-compose.inc.yml
include Makefile.dcape
.PHONY: $(CFG)
# build .env file from app templates
.env: $(DC_ENV_SOURCES)
@echo "*** $@ ***"
@echo "# WARNING! This file was generated by make. DO NOT EDIT" > $@
@echo "# file generated from: $(DC_ENV_SOURCES)" >> $@
@for f in $^ ; do cat $$f >> $@ ; done
# build docker-compose.yml file from app templates
docker-compose.yml: $(DC_INC) $(DC_SOURCES)
@echo "*** $@ ***"
@echo "# WARNING! This file was generated by make. DO NOT EDIT" > $@
@for f in $^ ; do cat $$f >> $@ ; done
# ------------------------------------------------------------------------------
## Git commands
#:
## run git for every app.
## Sample: make git-status-s
git-%:
@echo "*** $@ ***" ; \
x=$@ ; cmdd=$${x#git-} ; cmd=$${cmdd/-/ -} ; \
for app in $${APPS:?Must be set} ; do \
echo "Run '$$cmd' in $$app..."; \
pushd apps/_$$app > /dev/null ; \
git $$cmd ; \
popd > /dev/null ; \
echo "---" ; \
done
# ------------------------------------------------------------------------------
## Docker-compose commands
#:
## create docker-compose image
build-compose:
docker build -t $(DCAPE_TAG)-compose --build-arg DCAPE_HOST_ROOT=$(PWD) .
dc: $(CFG) docker-compose.yml
@>&2 echo "Running dc command: $(CMD)"
@>&2 echo "Dcape URL: $(DCAPE_SCHEME)://$(DCAPE_HOST)"
@>&2 echo "------------------------------------------"
@docker compose -p $$DCAPE_TAG --project-directory $(DCAPE_ROOT) $(CMD)
## show stack containers
ps: CMD=ps
ps: dc
## (re)start container(s)
up: CMD=up -d $(APPS)
up: dc
## start container
up-%:
@echo "*** $@ ***" ; \
x=$@ ; \
$(MAKE) -s up APPS=$${x#up-}
## restart container
reup-%:
@echo "*** $@ ***" ; \
x=$@ ; \
$(MAKE) -s reup APPS=$${x#reup-}
## restart container(s)
reup: CMD=up --force-recreate -d $(APPS)
reup: dc
## stop (and remove) container(s)
down: CMD=down
down: dc
# ------------------------------------------------------------------------------
## Database commands
#:
## exec psql inside db container
psql:
@docker compose exec db psql -U postgres
# ------------------------------------------------------------------------------
APPS_NEW = db
APPS_ALWAYS ?= auth config cicd manager
ifneq ($(findstring ns,$(APPS)),)
APPS_NEW += ns
endif
APPS_NEW += router
ifneq ($(findstring gitea,$(APPS)),)
APPS_NEW += vcs
endif
APPS_NEW += $(APPS_ALWAYS)
config-upgrade: APPS=$(APPS_NEW)
config-upgrade: config upgrade-v3
config-upgrade:
@find . -name "*.env" -exec sed -i "s|/opt/dcape3|/opt/dcape|g" {} +
after-upgrade:
@$(MAKE) -s .setup-app APPS=cicd
iperf3:
@docker run --name=iperf3 -d --restart=unless-stopped -p 5201:5201/tcp -p 5201:5201/udp mlabbe/iperf3