-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDockerfile
55 lines (39 loc) · 1.56 KB
/
Dockerfile
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
FROM golang:1.21-bullseye AS builder
# 设置构建参数的默认值
ARG GIT_TAG="unknown"
ARG GIT_COMMIT_LOG="unknown"
ARG BUILD_TIME="unknown"
ARG BUILD_GO_VERSION="github@action golang:1.21-bullseye"
WORKDIR /go/src/app
COPY . .
# 打印构建参数
RUN echo "GIT_TAG=${GIT_TAG}"
RUN echo "GIT_COMMIT_LOG=${GIT_COMMIT_LOG}"
RUN echo "BUILD_TIME=${BUILD_TIME}"
RUN echo "BUILD_GO_VERSION=${BUILD_GO_VERSION}"
# 设置 LDFlags 变量
ENV LDFLAGS=" \
-X 'main.GitTag=${GIT_TAG}' \
-X 'main.GitCommitLog=${GIT_COMMIT_LOG}' \
-X 'main.BuildTime=${BUILD_TIME}' \
-X 'main.BuildGoVersion=${BUILD_GO_VERSION}' \
"
RUN wget -O gf "https://github.com/gogf/gf/releases/latest/download/gf_$(go env GOOS)_$(go env GOARCH)" && chmod +x gf && ./gf install -y && rm ./gf
RUN gf build -e "-ldflags \"${LDFLAGS}\" "
FROM loads/alpine:3.8
LABEL maintainer="Hamster <[email protected]>"
###############################################################################
# INSTALLATION
###############################################################################
# 设置固定的项目路径
ENV WORKDIR /app/main
COPY --from=builder /go/src/app/temp/release/linux_amd64/service $WORKDIR/service
# 添加应用可执行文件,并设置执行权限
RUN chmod +x $WORKDIR/service
# 增加端口绑定
EXPOSE 10401
###############################################################################
# START
###############################################################################
WORKDIR $WORKDIR
CMD ["./service"]