forked from remsky/Kokoro-FastAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMzkefile
More file actions
executable file
·166 lines (139 loc) · 5.44 KB
/
Copy pathMzkefile
File metadata and controls
executable file
·166 lines (139 loc) · 5.44 KB
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
#!/usr/bin/env mzke -f
APP := kokoro-fastapi
IMAGE := ghcr.io/ziquid/kokoro-fastapi-basicauth
CPU_IMAGE := $(IMAGE)-cpu
GPU_IMAGE := $(IMAGE)-gpu
CPU_DOCKERFILE := docker/cpu/Dockerfile
GPU_DOCKERFILE := docker/gpu/Dockerfile
IS_DRUPAL :=
# Makefile content
ifneq (,$(wildcard ./.env))
include .env
export
DOCKER_RUN_ENV_FILE_SUPPORT := --env-file .env
endif
HOST_OS := $(shell uname)
# $(info HOST_OS is $(HOST_OS))
ifeq ($(HOST_OS),Darwin)
DOCKER_DAEMON := com.[d]ocker.backend
IS_MAC := Y
endif
ifeq ($(HOST_OS),Linux)
DOCKER_DAEMON := [d]ockerd
IS_LINUX := Y
endif
DOCKER_RUNNING := $(shell ps ax | grep -qs $(DOCKER_DAEMON) && echo Y || echo N)
# $(info DOCKER_RUNNING is $(DOCKER_RUNNING))
MAKE_USER_COMMAND ?= $(notdir $(MAKE))
# MAKEVARS = $(shell echo '$(.VARIABLES)' | tr \ \\n | grep -i m.ke)
# $(info $(foreach var,$(MAKEVARS),$(info "$(var) = $($(var))")))
COMPOSER_CMD_EXAMPLE = $(MAKE_USER_COMMAND) \"ARGS=[CMD ...]\" composer\\nex: $(MAKE_USER_COMMAND) \"ARGS=update -W\" composer
DRUSH_CMD_EXAMPLE = \"ARGS=[CMD ...]\" drush\\nex: $(MAKE_USER_COMMAND) \"ARGS=updb -y\" drush
ifeq ($(IS_MZKE),YES)
COMPOSER_CMD_EXAMPLE = $(MAKE_USER_COMMAND) composer [CMD ...]\\nex: $(MAKE_USER_COMMAND) composer update -W
DRUSH_CMD_EXAMPLE = $(MAKE_USER_COMMAND) drush [CMD ...]\\nex: $(MAKE_USER_COMMAND) drush updb -y
endif
# $(info ARGS is $(ARGS), MAKECMDGOALS is $(MAKECMDGOALS))
$(MAKECMDGOALS)_ARGS := $(ARGS)
# $(info MAKECMDGOALS_ARGS is $(MAKECMDGOALS)_ARGS is $($(MAKECMDGOALS)_ARGS))
.PHONY: all run start up
ifdef IS_LINUX
all run start up: ddr ## (Linux) Run the docker containers, if already stopped. Don't restart if running.
docker ps | grep -q -s $(APP) || \
docker run -p 8880:8880 -d --name $(APP) $(DOCKER_RUN_ENV_FILE_SUPPORT) \
$($@_ARGS) $(GPU_IMAGE):latest
else
all run start up: ## (Mac) Run as a local service. Will fail if already running.
. .venv/bin/activate
./start-gpu_mac.sh
endif
ifdef IMAGE
.PHONY: ba
ba: $(CPU_DOCKERFILE) $(GPU_DOCKERFILE) ddr ## Build All custom docker image(s) built by this app
docker buildx use mybuilder
docker buildx build --platform linux/amd64,linux/arm64 -f $(CPU_DOCKERFILE) -t $(CPU_IMAGE):latest .
docker buildx build -f $(GPU_DOCKERFILE) -t $(GPU_IMAGE):latest .
.PHONY: bpa
bpa: $(CPU_DOCKERFILE) $(GPU_DOCKERFILE) ddr ## Build and Push All custom docker image(s) built by this app
docker buildx use mybuilder
docker buildx build --platform linux/amd64,linux/arm64 -f $(CPU_DOCKERFILE) -t $(CPU_IMAGE):latest --push .
docker buildx build -f $(GPU_DOCKERFILE) -t $(GPU_IMAGE):latest --push .
.PHONY: build
build: $(CPU_DOCKERFILE) ddr ## Build custom docker image(s) built by this app
docker buildx use mybuilder
docker buildx build -f $(CPU_DOCKERFILE) -t $(CPU_IMAGE):latest --load .
ifeq ($(HOST_OS),Linux)
docker buildx build -f $(GPU_DOCKERFILE) -t $(GPU_IMAGE):latest --load .
endif
endif
ifdef IS_DRUPAL
.PHONY: composer
composer: run ## Run a composer command (composer-help for help)
docker exec -t -i $(APP)-web-1 /bin/bash -c "composer $($@_ARGS)"
.PHONY: composer-help
composer-help: ## get details about calling composer
$(info Run Composer commands using the following syntax:)
@echo $(COMPOSER_CMD_EXAMPLE)
.PHONY: debug-off
debug-off: run ## Disable PHP debugging in the web container
docker exec -t -i $(APP)-web-1 cp /usr/local/etc/php/php.ini{-production,}
$(warning "TODO: Disable xdebug in php.ini")
docker container restart $(APP)-web-1
.PHONY: debug-on
debug-on: run ## Enable PHP debugging in the web container
docker exec -t -i $(APP)-web-1 cp /usr/local/etc/php/php.ini{-development,}
$(warning "TODO: Enable xdebug in php.ini")
docker container restart $(APP)-web-1
endif # IS_DRUPAL
.PHONY: ddr dds docker-daemon-run
ddr dds docker-daemon-run: ## Run the docker daemon, if not already running
ifeq ($(DOCKER_RUNNING)-$(HOST_OS),N-Darwin)
@open -a Docker --background
sleep 5
else
$(info Docker is running? $(DOCKER_RUNNING))
ifeq ($(DOCKER_RUNNING),N)
$(error Please start Docker and try again)
endif
endif # N-Darwin
ifdef IS_DRUPAL
.PHONY: drush
drush: run ## Run a drush command (drush-help for help)
docker exec -t -i $(APP)-web-1 /bin/bash -c "cd web; drush $($@_ARGS)"
.PHONY: drush-help
drush-help: ## get details about calling drush
$(info Drush help)
@echo $(DRUSH_CMD_EXAMPLE)
endif # IS_DRUPAL
.PHONY: rb rebuild
rb rebuild: docker-compose.yml ## Recreate and restart the docker containers
docker compose up -d --force-recreate
.PHONY: rerun restart rr
rerun restart rr: docker-compose.yml ## (Re)start the docker containers
docker compose restart $($@_ARGS)
ifdef IS_DRUPAL
.PHONY: sqlc
sqlc: run ## Connect to the MySQL container via the mysql CLI
docker exec -t -i $(APP)-db-1 mysql -u root -p
endif
.PHONY: ssh
ssh: run ## SSH into the app (web) container
ifdef IS_DRUPAL
docker exec -t -i $(APP)-web-1 /bin/bash
else
docker exec -t -i $(APP) /bin/sh
endif
ifdef IS_DRUPAL
.PHONY: ssh-db
ssh-db: run ## SSH into the db container
docker exec -t -i $(APP)-db-1 /bin/bash
endif
.PHONY: stop
stop: ## Stop the docker containers
# docker compose stop $($@_ARGS)
docker stop $(APP) $($@_ARGS)
docker rm $(APP)
.PHONY: help
help: ## Show this help message
@echo "$(MAKE_USER_COMMAND) targets:"
@LC_ALL=C $(MAKE_USER_COMMAND) -qp -f $(firstword $(MAKEFILE_LIST)) : 2> /dev/null | awk -v RS= -F: '$$1 ~ /^[^#%. ]+$$/ { print $$1 }' | xargs -I % grep -h -E '^%(:| [a-zA-Z_ -]+:).*?## ' $(MAKEFILE_LIST) | sort -u | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'