forked from hashicorp/hcp-terraform-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
96 lines (68 loc) · 1.9 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
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
# This Dockerfile contains multiple targets.
# Use 'docker build --target=<name> .' to build one.
#
# Every target has a BIN_NAME argument that must be provided via --build-arg=BIN_NAME=<name>
# when building.
ARG GO_VERSION=1.20
# ===================================
#
# Non-release images.
#
# ===================================
# dev-builder compiles the binary
# -----------------------------------
FROM golang:$GO_VERSION as dev-builder
ARG BIN_NAME
ARG TARGETOS
ARG TARGETARCH
ENV BIN_NAME=$BIN_NAME
WORKDIR /build
COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY internal/ internal/
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -trimpath -o $BIN_NAME main.go
# dev runs the binary from devbuild
# -----------------------------------
FROM gcr.io/distroless/static:nonroot as dev
ARG BIN_NAME
ARG PRODUCT_VERSION
ENV BIN_NAME=$BIN_NAME
LABEL version=$PRODUCT_VERSION
WORKDIR /
COPY --from=dev-builder /build/$BIN_NAME .
USER 65532:65532
ENTRYPOINT ["/bin/sh", "-c", "/$BIN_NAME"]
# ===================================
#
# Release images.
#
# ===================================
# default release image
# -----------------------------------
FROM gcr.io/distroless/static:nonroot AS release-default
ARG BIN_NAME
ARG PRODUCT_VERSION
ARG PRODUCT_REVISION
ARG TARGETOS
ARG TARGETARCH
ENV BIN_NAME=$BIN_NAME
LABEL maintainer="Terraform Ecosystem - Hybrid Cloud Team <tfc-operator@hashicorp.com>"
LABEL version=$PRODUCT_VERSION
LABEL revision=$PRODUCT_REVISION
WORKDIR /
COPY LICENSE /licenses/copyright.txt
COPY dist/$TARGETOS/$TARGETARCH/$BIN_NAME .
USER 65532:65532
ENTRYPOINT ["/bin/sh", "-c", "/$BIN_NAME"]
# ===================================
#
# Set default target to 'dev'.
#
# ===================================
FROM dev