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