-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile.dcape
86 lines (73 loc) · 3.3 KB
/
Makefile.dcape
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
# dcape application Makefile
# included by dcape app inside dcapr
SHELL = /bin/bash
DCAPE_ROOT ?= $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
-include $(DCAPE_ROOT)/.dcape.env
include $(DCAPE_ROOT)/Makefile.common
# ------------------------------------------------------------------------------
## create database and user
db-create: docker-wait
@echo "*** $@ ***" \
&& varname=$${NAME:?Must be set}_DB_PASS && pass=$${!varname} \
&& varname=$(NAME)_DB_TAG && dbname=$${!varname} \
&& echo "Create db $$dbname..." ; \
$(MAKE) -s .lib-db-create PGUSER=$$dbname PGDATABASE=$$dbname PGPASSWORD=$$pass
## drop database and user
db-drop:
@echo "*** $@ ***" \
&& varname=$${NAME:?Must be set}_DB_TAG && dbname=$${!varname} \
&& echo "Drop db ($$NAME) $$dbname..." ; \
$(MAKE) -s .lib-db-drop PGUSER=$$dbname PGDATABASE=$$dbname
## exec psql inside db container from apps.
## Example: make psql-docker DCAPE_STACK=yes
psql-docker:
@varname=$${NAME}_DB_TAG && dbname=$${!varname} ; \
[[ $$dbname ]] || dbname=postgres ; \
echo "psql for $$dbname" ; \
docker exec -it $${DB_CONTAINER:?Must be set} psql -d $$dbname -U $$dbname
## run local psql from apps.
## Example: make psql-local DCAPE_STACK=yes PGPORT=5433
psql-local:
@varname=$${NAME:?Must be set}_DB_PASS && pass=$${!varname} \
&& varname=$${NAME}_DB_TAG && dbname=$${!varname} ; \
echo "*** $@:$$dbname ***" ; \
$(MAKE) -s .lib-db-psql PGUSER=$$dbname PGDATABASE=$$dbname PGPASSWORD=$$pass
# called in app Makefile to run dcape stack commands
compose:
@docker compose -p $(DCAPE_TAG) --project-directory $(DCAPE_ROOT) $(CMD)
DCAPE_VERSION_DOMAIN ?= dockerpoll.dcape.ru
DCAPE_VERSION_OPTS ?= -t txt +short
## update local app versions from upstream
ver-upd: VER_UPDATE=yes
ver-upd: ver-cmp
## compare local and upstream app versions
## and update if VER_UPDATE=yes
ver-cmp:
@echo "Local and Dcape upstream app docker images and versions" ; \
printf "%-8s %-18s %-30s %-15s %-30s %-15s\n" "Role" "App" "Dcape image" "Dcape version" "Image" "Version" ; \
printf "%-8s %-18s %-30s %-15s %-30s %-15s\n" "----" "---" "-----------" "-------------" "-----" "-------" ; \
updated=0 ; \
for app in $(APPS); do \
x=$$(grep -E '^[^#].+_IMAGE=' apps/_$$app/.env) ; img=$${x#*=} ; \
tag=$${img##*/} ; \
if [[ $$app == config ]] ; then img=ghcr.io/apisite/app-enfist ; tag=enfist ; \
elif [[ $$app == router ]] ; then img=traefik ; tag=$$img ; \
elif [[ $$tag == woodpecker-server ]] ; then tag=woodpecker ; \
elif [[ $$tag == powerdns-alpine ]] ; then tag=powerdns ; \
elif [[ $$tag == portainer-ce ]] ; then tag=portainer ; \
fi ; \
x=$$(grep -E '^[^#].+_VER=' apps/_$$app/.env) ; ver=$${x#*=} ; \
read i v < <(dig $(DCAPE_VERSION_OPTS) $${tag}.$(DCAPE_VERSION_DOMAIN) | tr -d \") ; \
[[ $$img == $$i ]] && img="="; \
[[ $$ver == $$v ]] && ver="="; \
if [[ "$(VER_UPDATE)" == "yes" ]] && [[ "$$img" == "=" ]] && [[ "$$ver" != "=" ]] ; then \
ver="$$ver (updated)" ; ((updated+=1)) ; \
sed -E -i 's/^([^#].+_VER=)(.+)/\1'$$v'/' apps/_$$app/.env ; \
fi ; \
printf "%-8s %-18s %-30s %-15s %-30s %-30s\n" $$app $$tag $$i $$v $$img "$$ver"; \
done ; \
[[ "$$updated" == 0 ]] || $(MAKE) -s .env up
# may be used in app Makefile, called before app up
.setup-before-up:
# may be used in app Makefile, called after app up
.setup-after-up: