This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Dockerfile
113 lines (89 loc) · 2.74 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
FROM golang:1.19.9-alpine as go-discover
RUN CGO_ENABLED=0 go install github.com/hashicorp/go-discover/cmd/discover@49f60c093101c9c5f6b04d5b1c80164251a761a6
# ===================================
#
# Non-release images.
#
# ===================================
# devdeps installs deps so we don't need to do it each time
FROM golang:latest as devdeps
ARG BIN_NAME
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
# devbuild compiles the binary
# -----------------------------------
FROM devdeps AS devbuild
ARG BIN_NAME
# Escape the GOPATH
WORKDIR /build
COPY . ./
ENV CGO_ENABLED 0
RUN go build -o $BIN_NAME
# dev runs the binary from devbuild
# -----------------------------------
FROM alpine:latest AS dev
ARG BIN_NAME
# Export BIN_NAME for the CMD below, it can't see ARGs directly.
ENV BIN_NAME=$BIN_NAME
COPY --from=devbuild /build/$BIN_NAME /bin/
COPY --from=go-discover /go/bin/discover /bin/
ENTRYPOINT /bin/$BIN_NAME
CMD ["version"]
# ===================================
#
# Release images.
#
# ===================================
# default release image
# -----------------------------------
FROM alpine:latest AS default
ARG BIN_NAME
# Export BIN_NAME for the CMD below, it can't see ARGs directly.
ENV BIN_NAME=$BIN_NAME
ARG PRODUCT_VERSION
ARG PRODUCT_REVISION
ARG PRODUCT_NAME=$BIN_NAME
# TARGETARCH and TARGETOS are set automatically when --platform is provided.
ARG TARGETOS TARGETARCH
LABEL maintainer="Team RelEng <[email protected]>"
LABEL version=$PRODUCT_VERSION
LABEL revision=$PRODUCT_REVISION
# Create a non-root user to run the software.
RUN addgroup $PRODUCT_NAME && \
adduser -S -G $PRODUCT_NAME 100
COPY dist/$TARGETOS/$TARGETARCH/$BIN_NAME /bin/
COPY --from=go-discover /go/bin/discover /bin/
USER 100
ENTRYPOINT /bin/$BIN_NAME
CMD ["version"]
# debian release image (just for the sake of example)
# -----------------------------------
FROM debian:latest AS debian
ARG BIN_NAME
# Export BIN_NAME for the CMD below, it can't see ARGs directly.
ENV BIN_NAME=$BIN_NAME
ARG PRODUCT_VERSION
ARG PRODUCT_REVISION
ARG PRODUCT_NAME=$BIN_NAME
# TARGETARCH and TARGETOS are set automatically when --platform is provided.
ARG TARGETOS TARGETARCH
LABEL maintainer="Team RelEng <[email protected]>"
LABEL version=$PRODUCT_VERSION
LABEL revision=$PRODUCT_REVISION
# Create a non-root user to run the software.
RUN addgroup $PRODUCT_NAME && \
adduser --system --uid 101 --group $PRODUCT_NAME
COPY dist/$TARGETOS/$TARGETARCH/$BIN_NAME /bin/
COPY --from=go-discover /go/bin/discover /bin/
USER 101
ENTRYPOINT /bin/$BIN_NAME
CMD ["version"]
# ===================================
#
# Set default target to 'dev'.
#
# ===================================
FROM dev