feat: Dockerfile
This commit is contained in:
parent
f2638b32b5
commit
325ea8d78c
26
Dockerfile
26
Dockerfile
|
|
@ -1,3 +1,25 @@
|
|||
## 使用官方Go镜像作为构建环境
|
||||
FROM golang:1.24.0-alpine AS builder
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 使用国内镜像源加速APK包下载
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
|
||||
# 使用国内镜像源加速依赖下载
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
# 复制项目源码
|
||||
COPY . .
|
||||
|
||||
# 复制go模块依赖文件
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# 编译Go应用程序,生成静态链接的二进制文件
|
||||
RUN go build -ldflags="-s -w" -o server ./cmd/server
|
||||
|
||||
# 创建最终镜像,用于运行编译后的Go程序
|
||||
FROM alpine
|
||||
|
||||
|
|
@ -12,10 +34,10 @@ RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \
|
|||
WORKDIR /app
|
||||
|
||||
# 将编译好的二进制文件从构建阶段复制到运行阶段
|
||||
COPY ./ /app
|
||||
COPY --from=builder /app/server ./server
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
# 设置容器启动时运行的命令
|
||||
|
||||
|
||||
CMD ["./bin/server"]
|
||||
CMD ["./server"]
|
||||
|
|
|
|||
14
deploy.sh
14
deploy.sh
|
|
@ -1,9 +1,9 @@
|
|||
export GO111MODULE=on
|
||||
export GOPROXY=https://goproxy.cn,direct
|
||||
export GOPATH=/root/go
|
||||
export GOCACHE=/root/.cache/go-build
|
||||
#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'
|
||||
#export CGO_ENABLED='0'
|
||||
|
||||
|
||||
MODE="$1"
|
||||
|
|
@ -22,8 +22,8 @@ fi
|
|||
git fetch origin
|
||||
git checkout "$BRANCH"
|
||||
git pull origin "$BRANCH"
|
||||
go mod tidy
|
||||
make build
|
||||
#go mod tidy
|
||||
#make build
|
||||
docker build -t ${CONTAINER_NAME} .
|
||||
docker stop ${CONTAINER_NAME}
|
||||
docker rm -f ${CONTAINER_NAME}
|
||||
|
|
|
|||
6
go.mod
6
go.mod
|
|
@ -2,8 +2,6 @@ module ai_scheduler
|
|||
|
||||
go 1.24.0
|
||||
|
||||
toolchain go1.24.7
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/self-tools/l_request v1.0.8
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.12
|
||||
|
|
@ -23,8 +21,6 @@ require (
|
|||
github.com/spf13/viper v1.17.0
|
||||
github.com/tmc/langchaingo v0.1.13
|
||||
google.golang.org/grpc v1.64.0
|
||||
google.golang.org/protobuf v1.34.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
gorm.io/driver/mysql v1.6.0
|
||||
gorm.io/gorm v1.31.0
|
||||
xorm.io/builder v0.3.13
|
||||
|
|
@ -82,5 +78,7 @@ require (
|
|||
golang.org/x/sys v0.31.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
|
||||
google.golang.org/protobuf v1.34.1 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue