-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathDockerfile
More file actions
100 lines (87 loc) · 3.29 KB
/
Dockerfile
File metadata and controls
100 lines (87 loc) · 3.29 KB
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
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# hermetic is a lite copy of the repo resources used in building
# testing in a hermetic, idempotent, and reproducable environment.
FROM google-go.pkg.dev/golang:1.26.1@sha256:56beaa755d2081aff2ce92f18da183130da0db0221b59180e303bf99d84c0c71 AS hermetic
ARG RUNCMD='go fmt ./...'
WORKDIR /workspace
# Separate COPY directives to take advantage of docker's build cache.
# Least-changed dirs should go first. NOTE: When adding new directories
# ensure .dockerignore is updated.
COPY *.md *.md
COPY vendor* vendor
COPY hack hack
COPY ops ops
COPY tools tools
COPY go.mod go.mod
COPY go.sum go.sum
COPY examples examples
COPY manifests manifests
COPY cmd cmd
COPY charts charts
COPY doc doc
COPY pkg pkg
COPY e2e e2e
COPY internal internal
# Init a dummy git repo so we can check if generated code changes via
# git diff.
RUN git config --global user.email "test@test.com" \
&& git init && git add . && git commit -am 'base'
# Hack to get multiline build arg to run properly.
RUN echo ${RUNCMD} | sh && echo 'done'
# sync is used to copy all auto-generated files to a different context.
# Usually this is used to mirror the changes back to the host machine.
FROM scratch AS sync
COPY --from=hermetic /workspace/go.mod go.mod
COPY --from=hermetic /workspace/go.sum go.sum
COPY --from=hermetic /workspace/cmd cmd
COPY --from=hermetic /workspace/doc doc
COPY --from=hermetic /workspace/examples examples
COPY --from=hermetic /workspace/manifests manifests
COPY --from=hermetic /workspace/charts charts
COPY --from=hermetic /workspace/e2e e2e
## kindtest image for running tests against kind cluster in hermetic environment.
FROM google-go.pkg.dev/golang:1.26.1@sha256:56beaa755d2081aff2ce92f18da183130da0db0221b59180e303bf99d84c0c71 AS buildbase
FROM docker:29.3-cli AS docker
FROM debian:stable-slim AS kindtest
WORKDIR /build
# Install go.
COPY --from=buildbase /usr/local/go /usr/local
# Install docker cli.
COPY --from=docker /usr/local/bin/docker /usr/local/bin
# Install curl.
RUN apt update
RUN apt install -y curl
# Install kubectl, jq, kind.
RUN ARCH=$(dpkg --print-architecture) && \
curl -Lo ./kubectl "https://dl.k8s.io/release/v1.32.1/bin/linux/${ARCH}/kubectl" && \
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \
rm kubectl && \
curl -Lo ./jq "https://github.com/jqlang/jq/releases/download/jq-1.7/jq-linux-${ARCH}" && \
install -o root -g root -m 0755 jq /usr/local/bin/jq && \
rm jq && \
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.26.0/kind-linux-${ARCH}" && \
install -o root -g root -m 0755 kind /usr/local/bin/kind && \
rm kind
# Get resources into image.
COPY examples examples
COPY cmd cmd
COPY manifests manifests
COPY charts charts
COPY vendor* vendor
COPY pkg pkg
COPY e2e e2e
COPY hack hack
COPY go.mod go.mod
COPY go.sum go.sum