-
Notifications
You must be signed in to change notification settings - Fork 32
/
Dockerfile
126 lines (90 loc) · 2.83 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
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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.23.3
# ===================================
#
# 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 api/ api/
COPY cmd/main.go cmd/main.go
COPY internal/ internal/
COPY version/ version/
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -trimpath -o $BIN_NAME cmd/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 <[email protected]>"
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"]
# Red Hat UBI release image
# -----------------------------------
FROM registry.access.redhat.com/ubi9/ubi-micro:9.4-15 AS release-ubi
ARG BIN_NAME
ARG PRODUCT_VERSION
ARG PRODUCT_REVISION
ARG TARGETOS
ARG TARGETARCH
ENV BIN_NAME=$BIN_NAME
LABEL name="HCP Terraform Operator"
LABEL vendor="HashiCorp"
LABEL release=$PRODUCT_REVISION
LABEL summary="HCP Terraform Operator for Kubernetes allows managing HCP Terraform / Terraform Enterprise resources via Kubernetes Custom Resources"
LABEL description="HCP Terraform Operator for Kubernetes allows managing HCP Terraform / Terraform Enterprise resources via Kubernetes Custom Resources"
LABEL maintainer="Terraform Ecosystem - Hybrid Cloud Team <[email protected]>"
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