generated from dopos/dcape-app-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (109 loc) · 3.69 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
## dcape-app-template Makefile
## This file extends Makefile.app from dcape
#:
SHELL = /bin/bash
CFG ?= .env
CFG_BAK ?= $(CFG).bak
#- App name
APP_NAME ?= ut
#- Site GRPC host
GRPC_SITE ?= $(APP_NAME)g.$(DCAPE_DOMAIN)
#- OT collector host
OTC_SITE ?= $(APP_NAME)otc.$(DCAPE_DOMAIN)
#- OT collector GRPC host
OTC_GRPC_SITE ?= $(APP_NAME)otcg.$(DCAPE_DOMAIN)
#- MailPit host
MAIL_SITE ?= $(APP_NAME)mail.$(DCAPE_DOMAIN)
#- Grafana host
GRAF_SITE ?= $(APP_NAME)graf.$(DCAPE_DOMAIN)
#- Docker image name
IMAGE ?= uptrace/uptrace
#- Docker image tag
IMAGE_VER ?= 1.7.7
#- Uptrace project 1 key
UPTRACE_PROJECT_KEY1 ?= $(shell openssl rand -hex 16; echo)
#- Uptrace project 2 key
UPTRACE_PROJECT_KEY2 ?= $(shell openssl rand -hex 16; echo)
#- Uptrace cookie key
UPTRACE_SECRET_KEY ?= $(shell openssl rand -hex 16; echo)
#- Grafana docker image name
GF_IMAGE ?= grafana/grafana
#- Grafana docker image tag
GF_IMAGE_VER ?= 11.3.1
#- Grafana plugins
GF_INSTALL_PLUGINS ?=
#- ClickHouse docker image tag
CLIHO_VER ?= 24.9.3
#- Opentelemetry collector docker image tag
OTELCOL_VER ?= 0.114.0
# If you need database, uncomment this var
USE_DB = yes
# If you need user name and password, uncomment this var
ADD_USER = yes
# create extension for word_similarity func
DB_INIT_SQL = pg_init.sql
CERT_DAYS ?= 3650
CERT_HOST ?= mailpit
CERT_DIR ?= var/ssl
CERT_CA = $(CERT_DIR)/ca.crt.pem
CERT_CA_KEY = $(CERT_DIR)/ca.pk.pem
CERT ?= $(CERT_CA)
# ------------------------------------------------------------------------------
# if exists - load old values
-include $(CFG_BAK)
export
-include $(CFG)
export
# ------------------------------------------------------------------------------
# Find and include DCAPE_ROOT/Makefile
DCAPE_COMPOSE ?= dcape-compose
DCAPE_ROOT ?= $(shell docker inspect -f "{{.Config.Labels.dcape_root}}" $(DCAPE_COMPOSE))
ifeq ($(shell test -e $(DCAPE_ROOT)/Makefile.app && echo -n yes),yes)
include $(DCAPE_ROOT)/Makefile.app
else
include /opt/dcape/Makefile.app
endif
# ------------------------------------------------------------------------------
## Template support code, used once
use-template:
.default-deploy: prep
## Setup app configs
prep: var certs var/grafana
cert-show:
openssl x509 -noout -text -in $(CERT)
## Create cert bundle
certs: $(CERT_DIR)
$(MAKE) -s $(CERT_DIR)/mail.crt.pem
var:
@mkdir $@
var/grafana:
@mkdir -m 777 $@
# ------------------------------------------------------------------------------
# Cert utils
CERT_DIR ?= var/ssl
CERT_CA = $(CERT_DIR)/ca.crt.pem
CERT_CA_KEY = $(CERT_DIR)/ca.pk.pem
CERT_DAYS ?= 3650
CERT_HOST ?= app
# Create cert dir
$(CERT_DIR):
mkdir -p $@
# Create CA
$(CERT_CA):
@echo "*** $@ ***" ; \
openssl req -newkey rsa:4096 -keyout "$(CERT_CA_KEY)" -x509 -new -nodes -out $@ \
-subj "/OU=Unknown/O=Unknown/L=Unknown/ST=unknown/C=RU" -days "$(CERT_DAYS)"
# Create Cert Signing Request
$(CERT_DIR)/%.csr.pem: $(CERT_CA)
@echo "*** $@ ***" ; \
x=$@ ; tag=$${x%.csr.pem} ; \
openssl req -new -newkey rsa:4096 -nodes -keyout "$$tag.pk.pem" -out $@ \
-subj "/CN=$(CERT_HOST)/OU=Unknown/O=Unknown/L=Unknown/ST=unknown/C=RU" \
-addext "subjectAltName=DNS:$(CERT_HOST)"
# Sign Cert
$(CERT_DIR)/%.crt.pem: $(CERT_DIR)/%.csr.pem
@tmp_file=$(shell mktemp) ; echo "subjectAltName=DNS:$(CERT_HOST)" > $$tmp_file ; \
openssl x509 -req -in $< -CA "$(CERT_CA)" -CAkey "$(CERT_CA_KEY)" -CAcreateserial -out "$@" \
-days "$(CERT_DAYS)" -extfile $$tmp_file ; \
rm $$tmp_file
openssl x509 -in $@ -text -noout