forked from kuhufu/go-mysql-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
45 lines (30 loc) · 914 Bytes
/
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
ARG GO_VERSION=1.21
FROM golang:${GO_VERSION}-alpine as base
# 配置go代理
ENV GOPROXY=https://goproxy.cn
WORKDIR /src
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download -x
FROM base AS build
ARG TARGETOS
ARG TARGETARCH
COPY . .
# 编译go程序
RUN --mount=type=cache,target=/go/pkg/mod \
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -v -o /bin/go-mysql-elasticsearch ./cmd/go-mysql-elasticsearch
FROM scratch as binary
COPY --from=build /bin/go-mysql-elasticsearch .
FROM ubuntu:22.04 as prod
# 安装mysql客户端
RUN apt update && \
apt install -y mysql-client=8.0.* && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# 挂载配置目录
VOLUME /app/
# 从build阶段拷贝go程序
COPY --from=build /bin/go-mysql-elasticsearch /bin
# 从build阶段拷贝配置
COPY --from=build /src/etc/river.toml ./etc/
ENTRYPOINT ["/bin/go-mysql-elasticsearch"]