-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
99 lines (71 loc) · 2.28 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#[=======================================================================[
# Description : Docker image containing the go-match binary
#]=======================================================================]
# Docker image repository to use. Use `docker.io` for public images.
ARG IMAGE_BASE_REGISTRY
ARG ALPINE_VERSION=3.20
ARG GO_VERSION=1.23.2
#### ---- Build ---- ####
FROM ${IMAGE_BASE_REGISTRY}golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build
LABEL maintainer=arash.idelchi
# (can use root throughout the image since it's a staged build)
# hadolint ignore=DL3002
USER root
# Basic good practices
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
# timezone
RUN apk add --no-cache \
tzdata
WORKDIR /work
ARG GOMODCACHE=/home/${USER}/.cache/.go-mod
ARG GOCACHE=/home/${USER}/.cache/.go
COPY go.mod go.sum ./
RUN --mount=type=cache,target=${GOMODCACHE},uid=1001,gid=1001 \
--mount=type=cache,target=${GOCACHE},uid=1001,gid=1001 \
go mod download
COPY . .
ARG GO_MATCH_VERSION="unofficial & built by unknown"
RUN --mount=type=cache,target=${GOMODCACHE},uid=1001,gid=1001 \
--mount=type=cache,target=${GOCACHE},uid=1001,gid=1001 \
CGO_ENABLED=0 go install -ldflags="-s -w -X 'main.version=${GO_MATCH_VERSION}'" ./...
# Create User (Alpine)
ARG USER=user
RUN addgroup -S -g 1001 ${USER} && \
adduser -S -u 1001 -G ${USER} -h /home/${USER} -s /bin/ash ${USER}
# Timezone
ENV TZ=Europe/Zurich
#### ---- Standalone ---- ####
FROM scratch AS standalone
LABEL maintainer=arash.idelchi
ARG USER=user
# Copy artifacts from the build stage
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=build /go/bin/go-match /go-match
USER ${USER}
WORKDIR /home/${USER}
# Clear the base image entrypoint
ENTRYPOINT ["/go-match"]
CMD [""]
# Timezone
ENV TZ=Europe/Zurich
#### ---- App ---- ####
FROM ${IMAGE_BASE_REGISTRY}alpine:${ALPINE_VERSION}
LABEL maintainer=arash.idelchi
USER root
# timezone
RUN apk add --no-cache \
git \
tzdata \
coreutils \
jq
# Copy artifacts from the build stage
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /go/bin/go-match /usr/local/bin/go-match
USER ${USER}
WORKDIR /home/${USER}
# Clear the base image entrypoint
ENTRYPOINT [""]
CMD ["/bin/ash"]
# Timezone
ENV TZ=Europe/Zurich