From f9e32e30231861fb6c37b46efec429e4f0dc9372 Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Wed, 24 Sep 2025 14:30:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 21 +++++++++++++++++++++ Makefile | 7 +++++++ deploy.sh | 18 ++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 Dockerfile create mode 100644 deploy.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4b5b1ec --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# 创建最终镜像,用于运行编译后的Go程序 +FROM alpine + +RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \ +&& echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \ +&& apk update && apk add tzdata \ +&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ +&& echo "Asia/Shanghai" > /etc/timezone + + +# 设置工作目录 +WORKDIR /app + +# 将编译好的二进制文件从构建阶段复制到运行阶段 +COPY ./ /app + +ENV TZ=Asia/Shanghai +# 设置容器启动时运行的命令 + + +CMD ["./bin/server"] diff --git a/Makefile b/Makefile index d5b50ee..3df7a74 100644 --- a/Makefile +++ b/Makefile @@ -21,3 +21,10 @@ endif # generate wire wire: cd ./cmd/server && wire + +.PHONY: build +# build +build: +# make config; + make wire; + mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./... \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..e130fee --- /dev/null +++ b/deploy.sh @@ -0,0 +1,18 @@ +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,direct +export GOPATH=/root/go +export GOCACHE=/root/.cache/go-build +export CONTAINER_NAME=ai_scheduler +export CGO_ENABLED='0' + +go mod tidy +make build +docker build -t ${CONTAINER_NAME} . +docker stop ${CONTAINER_NAME} +docker rm -f ${CONTAINER_NAME} +docker run -itd \ + --name "${CONTAINER_NAME}" \ + --restart=always \ + -e "OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://host.docker.internal:11434}" \ + -p 8090:8090 \ + "${CONTAINER_NAME}" \ No newline at end of file