-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (40 loc) · 1.25 KB
/
Dockerfile
File metadata and controls
56 lines (40 loc) · 1.25 KB
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
52
53
54
55
56
FROM golang:1.24.4-alpine AS builder
WORKDIR /app
ENV GOPROXY=https://goproxy.cn,direct
ENV GOSUMDB=off
ENV GOPRIVATE=*
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
RUN apk add --no-cache git ca-certificates tzdata openssl && \
git config --global http.sslverify false && \
git config --global http.postBuffer 1048576000
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
GOPROXY=https://goproxy.cn,direct \
GOSUMDB=off \
go mod download
COPY . .
ARG SERVICE_NAME
ARG SERVICE_PATH
ARG SERVICE_PORT
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go build \
-ldflags="-w -s" \
-o /app/bin/service \
./app/${SERVICE_PATH}
RUN mkdir -p /app/config && \
if [ -d "./app/${SERVICE_PATH}/etc" ]; then \
cp -r ./app/${SERVICE_PATH}/etc/${SERVICE_NAME}.yaml /app/config/config.yaml 2>/dev/null || true; \
fi
FROM alpine:latest
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
ARG SERVICE_NAME
ARG SERVICE_PORT
ARG SERVICE_DEV_PORT
COPY --from=builder /app/bin/service /service
COPY --from=builder /app/config /etc/
EXPOSE ${SERVICE_PORT}
EXPOSE ${SERVICE_DEV_PORT}
CMD ["/service", "-f", "/etc/config.yaml"]