-
Notifications
You must be signed in to change notification settings - Fork 8
/
dockerfile-go
39 lines (29 loc) · 885 Bytes
/
dockerfile-go
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
ARG APP
ARG TZ=Asia/Shanghai
FROM golang:1.23-alpine AS builder
ARG APP
ARG TZ
RUN apk add --no-cache make tzdata
RUN cp /usr/share/zoneinfo/$TZ /etc/localtime && \
adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "100001" \
"appuser"
COPY . /go/workspace/
WORKDIR /go/workspace/$APP
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod go mod tidy && go build -ldflags '-s -w' -o dist/app
FROM alpine:latest
ARG APP
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /etc/localtime /etc/localtime
COPY --from=builder /go/workspace/$APP/dist/app /usr/local/bin/app
RUN mkdir -p /var/log/app && chown appuser /var/log/app
USER appuser
VOLUME /var/log/app
EXPOSE 8080
ENTRYPOINT ["app"]