-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xinwei Xiong(cubxxw-openim) <[email protected]>
- Loading branch information
Showing
3 changed files
with
106 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
FROM golang:1.20-alpine | ||
# docker build -t exporter:1.0 -f ./Dockerfile.exporter . | ||
# 构建阶段1:构建二进制文件 | ||
FROM golang:1.20 as builder | ||
|
||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
COPY . . | ||
# 复制项目文件到容器中 | ||
COPY cmd/exporter/main.go go.mod go.sum /app/ | ||
|
||
RUN apk update && apk add make | ||
# 构建二进制文件 | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o exporter main.go | ||
|
||
RUN make exporter | ||
|
||
# 构建阶段2:生成最终镜像 | ||
FROM alpine:latest | ||
|
||
COPY --from=0 /app/_output/bin/platforms/linux/amd64/exporter /app/exporter | ||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
# 从构建阶段1中复制二进制文件到容器中 | ||
COPY --from=builder /app/exporter /app/exporter | ||
|
||
ENTRYPOINT ["/app/exporter"] | ||
# 运行二进制文件 | ||
CMD ["/app/exporter --help"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
FROM golang:1.20-alpine | ||
# docker build -t syncer:1.0 -f ./Dockerfile.syncer . | ||
WORKDIR /app | ||
# 构建阶段1:构建二进制文件 | ||
FROM golang:1.20 as builder | ||
|
||
COPY . . | ||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
RUN apk update && apk add make | ||
# 复制项目文件到容器中 | ||
COPY cmd/exporter/main.go go.mod go.sum /app/ | ||
|
||
RUN make syncer | ||
# 构建二进制文件 | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o exporter main.go | ||
|
||
# 构建阶段2:生成最终镜像 | ||
FROM alpine:latest | ||
|
||
COPY --from=0 /app/_output/bin/platforms/linux/amd64/syncer /app/syncer | ||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
# 从构建阶段1中复制二进制文件到容器中 | ||
COPY --from=builder /app/syncer /app/syncer | ||
|
||
ENTRYPOINT ["/app/syncer"] | ||
# 运行二进制文件 | ||
CMD ["/app/syncer --help"] |