...
1# Copyright 2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# This Dockefile builds a thin image containing the manager binary
16
17# Build the manager binary
18FROM golang:1.19 AS builder
19
20# Copy in the Go source code
21WORKDIR /go/src/github.com/GoogleCloudPlatform/k8s-config-connector
22COPY operator/pkg/ operator/pkg/
23COPY operator/cmd/ operator/cmd/
24COPY operator/channels/ operator/channels/
25COPY operator/autopilot-channels/ operator/autopilot-channels/
26COPY mockgcp/ mockgcp/
27COPY pkg/ pkg/
28COPY third_party/ third_party/
29COPY config/servicemappings/ config/servicemappings/
30COPY scripts/resource-autogen/ scripts/resource-autogen/
31COPY scripts/generate-third-party-licenses scripts/generate-third-party-licenses
32COPY go.mod go.mod
33COPY go.sum go.sum
34
35# Build the binary from source
36RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager github.com/GoogleCloudPlatform/k8s-config-connector/operator/cmd/manager
37RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o gke_addon_poststart github.com/GoogleCloudPlatform/k8s-config-connector/operator/cmd/gke_addon_poststart
38
39# Generate licenses
40RUN go mod vendor -o temp-vendor # So we can load license files
41RUN go run scripts/generate-third-party-licenses/main.go
42RUN rm -rf temp-vendor
43
44# Build a specific version of kubectl to be used by the
45# kubebuilder-declarative-pattern library.
46RUN curl -fsSL https://dl.k8s.io/v1.26.2/bin/linux/amd64/kubectl > kubectl
47RUN chmod a+rx kubectl
48
49# Prepare a directory containing the binaries and other artifacts, and
50# configure any required permissions
51FROM alpine:latest AS packager
52WORKDIR /configconnector-operator/
53COPY --from=builder /go/src/github.com/GoogleCloudPlatform/k8s-config-connector/manager .
54COPY --from=builder /go/src/github.com/GoogleCloudPlatform/k8s-config-connector/gke_addon_poststart .
55COPY --from=builder /go/src/github.com/GoogleCloudPlatform/k8s-config-connector/operator/channels/ channels/
56COPY --from=builder /go/src/github.com/GoogleCloudPlatform/k8s-config-connector/operator/autopilot-channels/ autopilot-channels/
57COPY --from=builder /go/src/github.com/GoogleCloudPlatform/k8s-config-connector/kubectl kubectl
58COPY --from=builder /go/src/github.com/GoogleCloudPlatform/k8s-config-connector/THIRD_PARTY_NOTICES/ THIRD_PARTY_NOTICES/
59COPY --from=builder /go/src/github.com/GoogleCloudPlatform/k8s-config-connector/MIRRORED_LIBRARY_SOURCE/ MIRRORED_LIBRARY_SOURCE/
60
61# Set user with UID 1000 as the owner of the directory
62RUN chown 1000 -R /configconnector-operator
63
64# Copy the directory into a thin, distroless image (go/gke-distroless)
65FROM gcr.io/gke-release/gke-distroless/static:gke_distroless_20230307.00_p0 AS final
66WORKDIR /configconnector-operator/
67COPY --from=packager /configconnector-operator /configconnector-operator
68ENV PATH="/configconnector-operator/:${PATH}"
69
70# Set the user to user with UID 1000 for subsequent commands
71USER 1000
72ENTRYPOINT ["./manager"]
View as plain text