-
Notifications
You must be signed in to change notification settings - Fork 27
/
Dockerfile
229 lines (211 loc) · 10 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
ARG ARCH=${TARGETARCH}
ARG BCI_IMAGE=registry.suse.com/bci/bci-base
ARG GO_IMAGE=rancher/hardened-build-base:v1.23.2b1
ARG CNI_IMAGE_VERSION=v1.6.0-build20241022
ARG CNI_IMAGE=rancher/hardened-cni-plugins:${CNI_IMAGE_VERSION}
ARG GOEXPERIMENT=boringcrypto
FROM ${BCI_IMAGE} as bci
FROM ${CNI_IMAGE} as cni
FROM ${GO_IMAGE} as builder
# setup required packages
ARG TAG=v3.29.0
RUN set -x && \
apk --no-cache add \
bash \
curl \
file \
gcc \
git \
linux-headers \
make \
patch \
libbpf-dev \
libpcap-dev \
libelf-static \
zstd-static \
zlib-static
RUN git clone --depth=1 https://github.com/projectcalico/calico.git $GOPATH/src/github.com/projectcalico/calico
WORKDIR $GOPATH/src/github.com/projectcalico/calico
RUN git fetch --all --tags --prune
RUN git checkout tags/${TAG} -b ${TAG}
### BEGIN K3S XTABLES ###
FROM builder AS k3s_xtables
ARG ARCH
ARG K3S_ROOT_VERSION=v0.14.1
ADD https://github.com/rancher/k3s-root/releases/download/${K3S_ROOT_VERSION}/k3s-root-xtables-${ARCH}.tar /opt/xtables/k3s-root-xtables.tar
RUN tar xvf /opt/xtables/k3s-root-xtables.tar -C /opt/xtables
### END K3S XTABLES #####
FROM calico/bird:v0.3.3-184-g202a2186-${ARCH} AS calico_bird
### BEGIN CALICOCTL ###
FROM builder AS calico_ctl
ARG ARCH
ARG TAG=v3.29.0
ARG GOEXPERIMENT
WORKDIR $GOPATH/src/github.com/projectcalico/calico/calicoctl
RUN GO_LDFLAGS="-linkmode=external \
-X github.com/projectcalico/calico/calicoctl/calicoctl/commands.VERSION=${TAG} \
-X github.com/projectcalico/calico/calicoctl/calicoctl/commands.GIT_REVISION=$(git rev-parse --short HEAD) \
" go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o bin/calicoctl ./calicoctl/calicoctl.go
RUN go-assert-static.sh bin/*
RUN if [ "${ARCH}" = "amd64" ]; then go-assert-boring.sh bin/*; fi
RUN install -s bin/* /usr/local/bin
RUN calicoctl --version
### END CALICOCTL #####
### BEGIN CALICO CNI ###
FROM builder AS calico_cni
ARG ARCH
ARG TAG=v3.29.0
ARG GOEXPERIMENT
WORKDIR $GOPATH/src/github.com/projectcalico/calico/cni-plugin
COPY dualStack-changes.patch .
# Apply the patch only in versions v3.20 and v3.21. It is already part of v3.22
RUN if [[ "${TAG}" =~ "v3.20" || "${TAG}" =~ "v3.21" ]]; then patch -p1 < dualStack-changes.patch; fi
ENV GO_LDFLAGS="-linkmode=external -X main.VERSION=${TAG}"
RUN go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o bin/calico ./cmd/calico
RUN go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o bin/calico-ipam ./cmd/calico
RUN go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o bin/install ./cmd/install
RUN go-assert-static.sh bin/*
RUN if [ "${ARCH}" = "amd64" ]; then go-assert-boring.sh bin/*; fi
RUN mkdir -vp /opt/cni/bin
RUN install -s bin/* /opt/cni/bin/
### END CALICO CNI #####
### BEGIN CALICO NODE ###
### Can't use go-build-static.sh due to -Wl and --fatal-warnings flags ###
FROM builder AS calico_node
ARG ARCH
ARG TAG=v3.29.0
ARG GOEXPERIMENT
WORKDIR $GOPATH/src/github.com/projectcalico/calico/node
RUN go mod download
ENV CGO_LDFLAGS="-L/go/src/github.com/projectcalico/calico/felix/bpf-gpl/include/libbpf/src -lbpf -lelf -lz -lzstd"
ENV CGO_CFLAGS="-I/go/src/github.com/projectcalico/calico/felix//bpf-gpl/include/libbpf/src -I/go/src/github.com/projectcalico/calico/felix//bpf-gpl"
ENV CGO_ENABLED=1
RUN if [ "${ARCH}" = "amd64" ]; then make -j 16 -C ../felix/bpf-gpl/include/libbpf/src BUILD_STATIC_ONLY=1; fi
RUN if [ "${ARCH}" = "amd64" ]; then \
go build -ldflags "-linkmode=external -X github.com/projectcalico/calico/node/pkg/lifecycle/startup.VERSION=${TAG} \
-X github.com/projectcalico/calico/node/buildinfo.GitRevision=$(git rev-parse HEAD) \
-X github.com/projectcalico/calico/node/buildinfo.GitVersion=$(git describe --tags --always) \
-X github.com/projectcalico/calico/node/buildinfo.BuildDate=$(date -u +%FT%T%z) -extldflags \"-static\"" \
-gcflags=-trimpath=${GOPATH}/src -o bin/calico-node ./cmd/calico-node; \
fi
RUN if [ "${ARCH}" != "amd64" ]; then \
CGO_LDFLAGS="-lelf -lz -lzstd" && CGO_CFLAGS="" && go build -ldflags "-linkmode=external \
-X github.com/projectcalico/calico/node/pkg/lifecycle/startup.VERSION=${TAG} \
-X github.com/projectcalico/calico/node/buildinfo.GitRevision=$(git rev-parse HEAD) \
-X github.com/projectcalico/calico/node/buildinfo.GitVersion=$(git describe --tags --always) \
-X github.com/projectcalico/calico/node/buildinfo.BuildDate=$(date -u +%FT%T%z) -extldflags \"-static\"" \
-gcflags=-trimpath=${GOPATH}/src -o bin/calico-node ./cmd/calico-node; \
fi
RUN go-assert-static.sh bin/calico-node
RUN if [ "${ARCH}" = "amd64" ]; then go-assert-boring.sh bin/calico-node; fi
RUN install -s bin/calico-node /usr/local/bin
### END CALICO NODE #####
### BEGIN CALICO POD2DAEMON ###
FROM builder AS calico_pod2daemon
ARG GOEXPERIMENT
WORKDIR $GOPATH/src/github.com/projectcalico/calico/pod2daemon
ENV GO_LDFLAGS="-linkmode=external"
RUN go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o bin/flexvoldriver ./flexvol
RUN go-assert-static.sh bin/*
RUN install -m 0755 flexvol/docker-image/flexvol.sh /usr/local/bin/
RUN install -D -s bin/flexvoldriver /usr/local/bin/flexvol/flexvoldriver
### END CALICO POD2DAEMON #####
### BEGIN CALICO KUBE-CONTROLLERS ###
FROM builder AS calico_kubecontrollers
ARG TAG=v3.29.0
ARG GOEXPERIMENT
WORKDIR $GOPATH/src/github.com/projectcalico/calico/kube-controllers
RUN GO_LDFLAGS="-linkmode=external \
-X github.com/projectcalico/calico/kube-controllers/main.VERSION=${TAG}" \
go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o bin/kube-controllers ./cmd/kube-controllers/
RUN GO_LDFLAGS="-linkmode=external \
-X github.com/projectcalico/calico/kube-controllers/main.VERSION=${TAG}" \
go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o bin/check-status ./cmd/check-status/
RUN go-assert-static.sh bin/*
RUN install -D -s bin/kube-controllers /usr/local/bin/
RUN install -D -s bin/check-status /usr/local/bin/
### END CALICO KUBE-CONTROLLERS #####
### BEGIN RUNIT ###
# We need to build runit because there aren't any rpms for it in CentOS or BCI repositories.
FROM ${BCI_IMAGE} AS runit
ARG RUNIT_VER=2.1.2
# Install build dependencies and security updates.
# RUN yum install -y rpm-build yum-utils make && \
# yum install -y wget glibc-static gcc && \
# yum -y update-minimal --security --sec-severity=Important --sec-severity=Critical
RUN zypper update -y && \
zypper install -y \
make gcc wget glibc-devel glibc-devel-static
# runit is not available in bci or CentOS repos so build it.
ADD http://smarden.org/runit/runit-${RUNIT_VER}.tar.gz /tmp/runit.tar.gz
WORKDIR /opt/local
RUN tar xzf /tmp/runit.tar.gz --strip-components=2 -C .
RUN ./package/install
### END RUNIT #####
# gather all of the disparate calico bits into a rootfs overlay
FROM scratch AS calico_rootfs_overlay_amd64
COPY --from=calico_node /go/src/github.com/projectcalico/calico/node/filesystem/etc/ /etc/
COPY --from=calico_node /go/src/github.com/projectcalico/calico/licenses/ /licenses/
COPY --from=calico_node /go/src/github.com/projectcalico/calico/node/filesystem/sbin/ /usr/sbin/
COPY --from=calico_node /usr/local/bin/ /usr/bin/
COPY --from=calico_ctl /usr/local/bin/calicoctl /calicoctl
COPY --from=calico_bird /bird* /usr/bin/
COPY --from=calico/bpftool:v5.3-amd64 /bpftool /usr/sbin/
COPY --from=calico_pod2daemon /usr/local/bin/ /usr/local/bin/
COPY --from=calico_kubecontrollers /usr/local/bin/ /usr/bin/
COPY --from=calico_cni /opt/cni/ /opt/cni/
COPY --from=cni /opt/cni/ /opt/cni/
COPY --from=k3s_xtables /opt/xtables/bin/ /usr/sbin/
COPY --from=runit /opt/local/command/ /usr/sbin/
FROM scratch AS calico_rootfs_overlay_arm64
COPY --from=calico_node /go/src/github.com/projectcalico/calico/node/filesystem/etc/ /etc/
COPY --from=calico_node /go/src/github.com/projectcalico/calico/licenses/ /licenses/
COPY --from=calico_node /go/src/github.com/projectcalico/calico/node/filesystem/sbin/ /usr/sbin/
COPY --from=calico_node /usr/local/bin/ /usr/bin/
COPY --from=calico_ctl /usr/local/bin/calicoctl /calicoctl
COPY --from=calico_bird /bird* /usr/bin/
COPY --from=calico/bpftool:v5.3-arm64 /bpftool /usr/sbin/
COPY --from=calico_pod2daemon /usr/local/bin/ /usr/local/bin/
COPY --from=calico_kubecontrollers /usr/local/bin/ /usr/bin/
COPY --from=calico_cni /opt/cni/ /opt/cni/
COPY --from=cni /opt/cni/ /opt/cni/
COPY --from=k3s_xtables /opt/xtables/bin/ /usr/sbin/
COPY --from=runit /opt/local/command/ /usr/sbin/
FROM scratch AS calico_rootfs_overlay_s390x
COPY --from=calico_node /go/src/github.com/projectcalico/calico/node/filesystem/etc/ /etc/
COPY --from=calico_node /go/src/github.com/projectcalico/calico/licenses/ /licenses/
COPY --from=calico_node /go/src/github.com/projectcalico/calico/node/filesystem/sbin/ /usr/sbin/
COPY --from=calico_node /usr/local/bin/ /usr/bin/
COPY --from=calico_ctl /usr/local/bin/calicoctl /calicoctl
COPY --from=calico_bird /bird* /usr/bin/
COPY --from=calico_pod2daemon /usr/local/bin/ /usr/local/bin/
COPY --from=calico_kubecontrollers /usr/local/bin/ /usr/bin/
COPY --from=calico_cni /opt/cni/ /opt/cni/
COPY --from=cni /opt/cni/ /opt/cni/
COPY --from=k3s_xtables /opt/xtables/bin/ /usr/sbin/
COPY --from=runit /opt/local/command/ /usr/sbin/
FROM calico_rootfs_overlay_${ARCH} as calico_rootfs_overlay
FROM bci
RUN zypper update -y && \
zypper install -y \
hostname \
libpcap1 \
libmnl0 \
libnetfilter_conntrack3 \
libnetfilter_cthelper0 \
libnetfilter_cttimeout1 \
libnetfilter_queue1 \
ipset \
kmod \
iputils \
iproute2 \
procps \
net-tools \
conntrack-tools \
which && \
rm -rf /var/cache/zypp/packages
COPY --from=calico_rootfs_overlay / /
ENV PATH=$PATH:/opt/cni/bin
RUN set -x && \
test -e /opt/cni/bin/install && \
ln -vs /opt/cni/bin/install /install-cni