mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-23 18:58:09 +00:00
Stopping this process takes drain + server + cleanup seconds: eight out of the box, and more for anyone who configures a drain window. Three places decide whether it gets that long, and none of them was written with it in mind. The release workflow stopped the previous container with the default deadline, which docker sets at ten seconds. The compose file - which the Makefile calls the first way to run this - set no stop_grace_period, so it took the same ten. Under either, a drain window over two seconds would have been cut off by SIGKILL part-way through the cleanup callbacks: this project's own deployments could not have run the capability it ships. The third was worse. `make run` removed the previous container with `docker rm -f`, and the force flag kills a running container outright - "uses SIGKILL", in docker's own words - with no grace at all. Restarting locally cut every shutdown short, so the drain window would never once have been reached on a developer's machine. It now stops with a deadline and then removes, which leaves what gets removed unchanged: on a container that has already stopped, stop is a no-op. So: --timeout 30 in the workflow, stop_grace_period: 30s on the compose service, and stop --timeout 30 before the removal in the Makefile. --timeout rather than --time, which docker still honours but has deprecated - it prints a warning on every use, and a deploy log that always carries a warning is one nobody reads. The three remaining `docker rm -f` calls in the workflow are left alone. Two remove containers that have already been stopped and one is the rollback path, and nothing static can tell those apart from a container that is still running - which is also why the check added next does not look at `rm -f` at all: a forced removal has no deadline to compare against. What keeps that path honest is the line above it, not a check. Thirty will drift the first time somebody raises a budget. The next commit is what notices, which is also why these comments name a check that does not exist yet.
82 lines
2.8 KiB
Makefile
82 lines
2.8 KiB
Makefile
PROJECT:=go-admin
|
|
|
|
.PHONY: build
|
|
build:
|
|
CGO_ENABLED=0 go build -ldflags="-w -s" -a -installsuffix "" -o go-admin .
|
|
|
|
# make build-linux
|
|
build-linux:
|
|
@docker build -t go-admin:latest .
|
|
@echo "build successful"
|
|
|
|
build-sqlite:
|
|
go build -tags sqlite3 -ldflags="-w -s" -a -installsuffix -o go-admin .
|
|
|
|
# make run
|
|
run:
|
|
# delete go-admin-api container
|
|
#
|
|
# stop then rm, rather than `rm -f`. The force flag kills a running
|
|
# container with SIGKILL and no grace at all, so restarting locally cut
|
|
# short every shutdown this application does - the drain window was never
|
|
# once reached on a developer's machine. --timeout has to cover
|
|
# extend.shutdown's drain + server + cleanup; checksilent's
|
|
# docker-stop-cuts-shutdown-short check compares it against
|
|
# config/settings.yml. On a container that has already stopped, stop is a
|
|
# no-op and the removal is unchanged.
|
|
@if [ $(shell docker ps -aq --filter name=go-admin --filter publish=8000) ]; then docker stop --timeout 30 go-admin && docker rm go-admin; fi
|
|
|
|
# 启动方法一 run go-admin-api container docker-compose 启动方式
|
|
# 进入到项目根目录 执行 make run 命令
|
|
@docker-compose up -d
|
|
|
|
# 启动方式二 docker run 这里注意-v挂载的宿主机的地址改为部署时的实际绝对路径
|
|
#@docker run --name=go-admin -p 8000:8000 -v /home/code/go/src/go-admin/go-admin/config:/go-admin-api/config -v /home/code/go/src/go-admin/go-admin-api/static:/go-admin/static -v /home/code/go/src/go-admin/go-admin/temp:/go-admin-api/temp -d --restart=always go-admin:latest
|
|
|
|
@echo "go-admin service is running..."
|
|
|
|
# delete Tag=<none> 的镜像
|
|
@docker image prune -f
|
|
@docker ps -a | grep "go-admin"
|
|
|
|
stop:
|
|
# delete go-admin-api container
|
|
@if [ $(shell docker ps -aq --filter name=go-admin --filter publish=8000) ]; then docker-compose down; fi
|
|
#@if [ $(shell docker ps -aq --filter name=go-admin --filter publish=8000) ]; then docker rm -f go-admin; fi
|
|
#@echo "go-admin stop success"
|
|
|
|
|
|
# -race is worth the extra minute here: common/actions reuses model instances
|
|
# across concurrent requests, so a Generate() that returns in place instead of
|
|
# a copy leaks data between them - and that is invisible to a single-threaded
|
|
# test run.
|
|
.PHONY: test
|
|
test:
|
|
go test -race -cover ./...
|
|
|
|
# Reports the failures that do not announce themselves - see
|
|
# tools/checksilent. Exits non-zero on an ERROR; the one WARN-level check
|
|
# prints and does not fail the build.
|
|
#
|
|
# Pass UI_DIR to enable the cross-repository menu-name check, which is skipped
|
|
# without it: make checksilent UI_DIR=../go-admin-ui/src
|
|
.PHONY: checksilent
|
|
checksilent:
|
|
ifdef UI_DIR
|
|
go run ./tools/checksilent -ui-dir $(UI_DIR)
|
|
else
|
|
go run ./tools/checksilent
|
|
endif
|
|
|
|
#.PHONY: docker
|
|
#docker:
|
|
# docker build . -t go-admin:latest
|
|
|
|
# make deploy
|
|
deploy:
|
|
|
|
#@git checkout master
|
|
#@git pull origin master
|
|
make build-linux
|
|
make run
|