-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
275 lines (224 loc) · 7.46 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!make
SYSTEM ?= ubuntu/22.04
ENV_FILE = ./.env
DOMAIN ?= localhost
NAMESPACE ?= chevereto
NAMESPACE_FILE = ./namespace/${NAMESPACE}
NAMESPACE_FILE_EXISTS = false
CHEVERETO_LICENSE_KEY ?= ""
ifneq ("$(wildcard ${NAMESPACE_FILE})","")
NAMESPACE_FILE_EXISTS = true
include ${NAMESPACE_FILE}
export $(shell sed 's/=.*//' ${NAMESPACE_FILE})
endif
ifneq ("$(wildcard ${ENV_FILE})","")
include ${ENV_FILE}
export $(shell sed 's/=.*//' ${ENV_FILE})
endif
SOURCE ?= ~/git/chevereto/v4
TARGET ?= default# default|dev
VERSION ?= 4.2
PHP ?= 8.2
EDITION ?= $(shell [ "${CHEVERETO_LICENSE_KEY}" = "" ] && echo free || echo pro)
DOCKER_USER ?= www-data
HOSTNAME ?= localhost
HOSTNAME_PATH ?= /
PROTOCOL ?= https
SERVICE ?= php
ENCRYPTION_KEY ?=
EMAIL_HTTPS ?= mail@yourdomain.tld
DB_PORT ?= 8836
HTTP_PORT ?= 80
HTTPS_PORT ?= 443
PORT = $(shell [ "${PROTOCOL}" = "http" ] && echo \${HTTP_PORT} || echo \${HTTPS_PORT})
HTTPS = $(shell [ "${PROTOCOL}" = "http" ] && echo 0 || echo 1)
HTTPS_CERT = https/$(shell [ -f "https/cert.pem" ] && echo || echo dummy/)cert.pem
HTTPS_KEY = https/$(shell [ -f "https/key.pem" ] && echo || echo dummy/)key.pem
URL_BARE = ${PROTOCOL}://${HOSTNAME}${HOSTNAME_PATH}
URL_PORT = ${PROTOCOL}://${HOSTNAME}:${PORT}${HOSTNAME_PATH}
URL = $(shell [ "${PORT}" = 80 -o "${PORT}" = 443 ] && echo ${URL_BARE} || echo ${URL_PORT})
PROJECT = ${NAMESPACE}_chevereto$(shell [ ! "${TARGET}" = "default" ] && echo -\${TARGET})
CONTAINER_BASENAME = ${PROJECT}-${VERSION}
IMAGE_EDITION_FREE_BASE = ghcr.io/chevereto/chevereto
IMAGE_NAME = chevereto$(shell [ ! "${TARGET}" = "default" ] && echo -\${TARGET})
IMAGE ?= $(shell [ "${EDITION}" = "free" ] && echo \${IMAGE_EDITION_FREE_BASE} || echo \${IMAGE_NAME}):${VERSION}
COMPOSE ?= docker-compose
COMPOSE_TARGET = ${COMPOSE}.yml
COMPOSE_SAMPLE = $(shell [ "${TARGET}" = "default" ] && echo default || echo dev).yml
COMPOSE_FILE = $(shell [ -f \${COMPOSE_TARGET} ] && echo \${COMPOSE_TARGET} || echo \${COMPOSE_SAMPLE})
FEEDBACK = $(shell echo 👉 \${TARGET} \${CONTAINER_BASENAME} @\${NAMESPACE_FILE} V\${VERSION} \(\${DOCKER_USER}\))
FEEDBACK_SHORT = $(shell echo 👉 \${TARGET} V\${VERSION} \(\${DOCKER_USER}\))
CHEVERETO_LICENSE ?= $(shell stty -echo; read -p "Chevereto V4 License key (for paid edition): 🔑" license; stty echo; echo $$license)
DOCKER_COMPOSE = $(shell echo @CONTAINER_BASENAME=\${CONTAINER_BASENAME} \
SOURCE=\${SOURCE} \
DB_PORT=\${DB_PORT} \
HTTP_PORT=\${HTTP_PORT} \
HTTPS_PORT=\${HTTPS_PORT} \
HTTPS_CERT=\${HTTPS_CERT} \
HTTPS_KEY=\${HTTPS_KEY} \
HTTPS=\${HTTPS} \
IMAGE=\${IMAGE} \
VERSION=\${VERSION} \
HOSTNAME=\${HOSTNAME} \
HOSTNAME_PATH=\${HOSTNAME_PATH} \
URL=\${URL} \
docker compose -p \${PROJECT} -f \${COMPOSE_FILE})
# Informational
feedback:
@./scripts/chevereto/logo.sh
@echo "${FEEDBACK}"
feedback--short:
@echo "${FEEDBACK_SHORT}"
feedback--compose: feedback--image
@echo "🐋 ${COMPOSE_FILE}"
feedback--url:
@echo "Protocol ${PROTOCOL} (:${PORT})"
@echo "@URL ${URL}"
feedback--image:
@echo "📦 ${IMAGE} (BASE ${IMAGE_NAME})"
feedback--volumes:
@echo "${PROJECT}_database"
@echo "${PROJECT}_storage"
feedback--namespace:
@echo "$(shell [ "${NAMESPACE_FILE_EXISTS}" = "true" ] && echo "✅" || echo "❌") ${NAMESPACE_FILE}"
@echo "🔑 ${ENCRYPTION_KEY}"
@echo "🌎 ${HOSTNAME}"
# Repo
sync:
@./scripts/chevereto/logo.sh
@echo "🔄 Syncing with remote repository (rebase+autostash)"
@git remote -v
@git fetch --tags -f && git pull --rebase --autostash
@echo "Listing available branches..."
@git --no-pager branch --sort=-committerdate
@echo '[OK] Run `git switch <branch>` to change branch if needed'
# Docker
image: feedback--image feedback--short
@CHEVERETO_LICENSE_KEY=${CHEVERETO_LICENSE_KEY} \
VERSION=${VERSION} \
IMAGE_NAME=${IMAGE_NAME} \
./scripts/system/chevereto.sh \
docker build . \
--cache-from ${IMAGE_EDITION_FREE_BASE}:${VERSION} \
--network host \
-f Dockerfile
image-custom: feedback--image feedback--short
@mkdir -p chevereto
echo "* Building custom image ${IMAGE}"
@docker build . \
--network host \
--build-arg PHP=${PHP} \
-f Dockerfile \
-t ${IMAGE}
volume-cp:
@docker run --rm -it -v ${VOLUME_FROM}:/from -v ${VOLUME_TO}:/to alpine ash -c "cd /from ; cp -av . /to"
volume-rm:
@docker volume rm ${VOLUME}
# Logs
log: feedback
@docker logs -f ${CONTAINER_BASENAME}_${SERVICE}
log-access: feedback
@docker logs ${CONTAINER_BASENAME}_${SERVICE} -f 2>/dev/null
log-error: feedback
@docker logs ${CONTAINER_BASENAME}_${SERVICE} -f 1>/dev/null
# Tools
bash: feedback
@docker exec -it --user ${DOCKER_USER} \
${CONTAINER_BASENAME}_${SERVICE} \
bash
exec: feedback
@docker exec -it --user ${DOCKER_USER} \
${CONTAINER_BASENAME}_${SERVICE} \
${COMMAND}
run: feedback
@docker exec -it \
${CONTAINER_BASENAME}_${SERVICE} \
bash /var/scripts/${SCRIPT}.sh
cron:
@./scripts/system/cron.sh
cron--run:
@./scripts/system/cron--run.sh
cloudflare:
@./scripts/system/cloudflare.sh
cloudflare--create:
@NAMESPACE_FILE=${NAMESPACE_FILE} ./scripts/system/cloudflare--create.sh
cloudflare--delete:
@./scripts/system/cloudflare--delete.sh
encryption-key:
@openssl rand -base64 32
install-docker:
@SYSTEM=${SYSTEM} \
./scripts/os/${SYSTEM}/install-docker.sh
.PHONY: namespace
namespace:
@chmod +x ./scripts/system/namespace.sh
@NAMESPACE=${NAMESPACE} \
NAMESPACE_EXISTS=${NAMESPACE_EXISTS} \
NAMESPACE_FILE=${NAMESPACE_FILE} \
HOSTNAME=${HOSTNAME} \
ENCRYPTION_KEY=${ENCRYPTION_KEY} \
./scripts/system/namespace.sh
.PHONY: env
env:
@chmod +x ./scripts/system/env.sh
@ENV_FILE=${ENV_FILE} ./scripts/system/env.sh
setup: cron proxy
# Docker compose
up: feedback--compose feedback--url
${DOCKER_COMPOSE} up
up-d: feedback--compose feedback--url
${DOCKER_COMPOSE} up -d
stop: feedback--compose
${DOCKER_COMPOSE} stop
start: feedback--compose
${DOCKER_COMPOSE} start
restart: feedback--compose
${DOCKER_COMPOSE} restart
down: feedback--compose
${DOCKER_COMPOSE} down
down--volumes: feedback--compose
${DOCKER_COMPOSE} down --volumes
# Instances
.PHONY: deploy
deploy:
@./scripts/system/deploy.sh
update: feedback--compose feedback--url
@./scripts/system/update.sh
destroy: feedback--compose cloudflare--delete
${DOCKER_COMPOSE} down --volumes
@rm namespace/${NAMESPACE}
install: feedback--short
docker exec -it --user ${DOCKER_USER} \
${CONTAINER_BASENAME}_${SERVICE} \
app/bin/legacy -C install -u "${ADMIN_USER}" -e "${ADMIN_EMAIL}" -x "${ADMIN_PASSWORD}"
# nginx-proxy
proxy:
@docker network create nginx-proxy || true
@docker run \
--detach \
--name nginx-proxy \
--net nginx-proxy \
--publish 80:80 \
--publish 443:443 \
--restart=always \
--volume certs:/etc/nginx/certs \
--volume vhost:/etc/nginx/vhost.d \
--volume html:/usr/share/nginx/html \
--mount type=bind,source=/var/run/docker.sock,target=/tmp/docker.sock,readonly \
--mount type=bind,source=${PWD}/nginx/chevereto.conf,target=/etc/nginx/conf.d/chevereto.conf,readonly \
--mount type=bind,source=${PWD}/nginx/cloudflare.conf,target=/etc/nginx/conf.d/cloudflare.conf,readonly \
nginxproxy/nginx-proxy
@docker run \
--detach \
--name nginx-proxy-acme \
--restart=always \
--volumes-from nginx-proxy \
--volume acme:/etc/acme.sh \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock,readonly \
--env "DEFAULT_EMAIL=${EMAIL_HTTPS}" \
nginxproxy/acme-companion
proxy--view:
@docker exec nginx-proxy cat /etc/nginx/conf.d/default.conf
proxy--remove:
@docker container rm -f nginx-proxy nginx-proxy-acme || true
@docker network rm nginx-proxy || true