Skip to content

Commit 959e7bd

Browse files
committed
✨ Build and publish Kubernetes envtest tools as packages
Signed-off-by: Vince Prignano <vincepri@redhat.com>
1 parent ede27ff commit 959e7bd

File tree

4 files changed

+253
-0
lines changed

4 files changed

+253
-0
lines changed

.github/workflows/tools-releases.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Kubernetes Tools Releases for controller-runtime envtest
2+
3+
on:
4+
push:
5+
branches:
6+
- tools-releases
7+
8+
env:
9+
KUBERNETES_VERSION: 1.28.0
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: true
16+
matrix:
17+
os: [ linux darwin windows ]
18+
arch: [ amd64 arm64 ]
19+
include:
20+
- arch: ppc64le
21+
os: linux
22+
- arch: s390x
23+
os: linux
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
- name: Set up Docker
28+
uses: docker/setup-buildx-action@v3
29+
- name: Build and push Docker images
30+
uses: docker/build-push-action@v5
31+
with:
32+
context: .
33+
file: ./hack/tools/{{ matrix.os }}/Dockerfile
34+
build-args: |
35+
KUBERNETES_VERSION=v${KUBERNETES_VERSION}
36+
OS={{ matrix.os }}
37+
ARCH={{ matrix.arch }}
38+
push: true
39+
tags: |
40+
ghcr.io/kubernetes-sigs/controller-tools/kubernetes-${{ matrix.os }}-${{ matrix.arch }}:${{ env.KUBERNETES_VERSION }}

hack/tools/envtest/darwin/Dockerfile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2018 The Kubernetes Authors.
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+
# Build or fetch the following binaries for darwin and then host them in a tar.gz file in an alpine image
16+
# - kube-apiserver (build)
17+
# - kubectl (fetch)
18+
# - etcd (fetch)
19+
20+
FROM golang:1.21 as builder
21+
22+
# Version and platform args.
23+
ARG KUBERNETES_VERSION
24+
ARG ETCD_VERSION=v3.5.13
25+
ARG OS=darwin
26+
ARG ARCH
27+
28+
# Tools path.
29+
ENV DEST=/usr/local/kubebuilder/bin/
30+
31+
# Install dependencies.
32+
RUN apt update && \
33+
apt install unzip rsync -y && \
34+
mkdir -p $DEST
35+
36+
# kube-apiserver
37+
WORKDIR /kubernetes
38+
RUN git clone https://github.com/kubernetes/kubernetes . --depth=1 -b ${KUBERNETES_VERSION}
39+
ENV CGO_ENABLED=0
40+
ENV KUBE_BUILD_PLATFORMS=${OS}/${ARCH}
41+
RUN make WHAT=cmd/kube-apiserver && \
42+
cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kube-apiserver $DEST
43+
44+
# kubectl
45+
RUN /bin/bash -x -c ' \
46+
{ curl -sLO https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kubectl && \
47+
chmod +x kubectl && \
48+
cp kubectl $DEST; } || \
49+
{ make WHAT=cmd/kubectl && \
50+
cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kubectl $DEST; }'
51+
52+
# etcd
53+
WORKDIR /etcd
54+
ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH}
55+
RUN /bin/bash -x -c ' \
56+
{ curl -sLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD_BASE_NAME}.zip && \
57+
unzip -o ${ETCD_BASE_NAME}.zip && \
58+
cp ${ETCD_BASE_NAME}/etcd $DEST; } || \
59+
{ rm -fr * && \
60+
git clone https://github.com/etcd-io/etcd . --depth=1 -b ${ETCD_VERSION} && \
61+
GOOS=${OS} GOARCH=${ARCH} ./build.sh && \
62+
cp ./bin/etcd $DEST; }'
63+
64+
# Package into tarball.
65+
WORKDIR /usr/local
66+
RUN tar -czvf /kubebuilder_${OS}_${ARCH}.tar.gz kubebuilder/
67+
68+
# Copy tarball to final image.
69+
FROM alpine:3.19
70+
71+
# Platform args.
72+
ARG OS=darwin
73+
ARG ARCH
74+
75+
COPY --from=builder /kubebuilder_${OS}_${ARCH}.tar.gz /

hack/tools/envtest/linux/Dockerfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2018 The Kubernetes Authors.
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+
# Fetch the following into binaries for linux and then host them in a tar.gz file in an alpine image
16+
# - kube-apiserver (fetch)
17+
# - kubectl (fetch)
18+
# - etcd (fetch)
19+
20+
# no need for anything fancy
21+
FROM alpine:3.19 as builder
22+
23+
# Version and platform args.
24+
ARG KUBERNETES_VERSION
25+
ARG ETCD_VERSION=v3.5.13
26+
ARG OS=linux
27+
ARG ARCH
28+
29+
# Tools path.
30+
ENV DEST=/usr/local/kubebuilder/bin/
31+
32+
# Install dependencies.
33+
RUN apk add --no-cache curl && \
34+
mkdir -p $DEST
35+
36+
# kube-apiserver
37+
RUN curl -sLO https://dl.k8s.io/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kube-apiserver && \
38+
chmod +x kube-apiserver && \
39+
cp kube-apiserver $DEST
40+
41+
# kubectl
42+
RUN curl -sLO https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kubectl && \
43+
chmod +x kubectl && \
44+
cp kubectl $DEST
45+
46+
# etcd
47+
ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH}
48+
RUN curl -sLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD_BASE_NAME}.tar.gz && \
49+
tar xzf ${ETCD_BASE_NAME}.tar.gz && \
50+
cp ${ETCD_BASE_NAME}/etcd $DEST
51+
52+
# Package into tarball.
53+
WORKDIR /usr/local
54+
RUN tar -czvf /kubebuilder_${OS}_${ARCH}.tar.gz kubebuilder/
55+
56+
# Copy tarball to final image.
57+
FROM alpine:3.19
58+
59+
# Platform args.
60+
ARG OS=linux
61+
ARG ARCH
62+
63+
COPY --from=builder /kubebuilder_${OS}_${ARCH}.tar.gz /

hack/tools/envtest/windows/Dockerfile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2018 The Kubernetes Authors.
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+
# Build or fetch the following binaries for windows and then host them in a tar.gz file in an alpine image
16+
# - kube-apiserver (build)
17+
# - kubectl (fetch)
18+
# - etcd (fetch)
19+
20+
FROM golang:1.21 as builder
21+
22+
# Version and platform args.
23+
ARG KUBERNETES_VERSION
24+
ARG ETCD_VERSION=v3.5.13
25+
ARG OS=windows
26+
ARG ARCH
27+
28+
# Tools path.
29+
ENV DEST=/usr/local/kubebuilder/bin/
30+
31+
# Install dependencies.
32+
RUN apt update && \
33+
apt install unzip rsync -y && \
34+
mkdir -p $DEST
35+
36+
# kube-apiserver
37+
WORKDIR /kubernetes
38+
RUN git clone https://github.com/kubernetes/kubernetes . --depth=1 -b ${KUBERNETES_VERSION}
39+
ENV CGO_ENABLED=0
40+
ENV KUBE_BUILD_PLATFORMS=${OS}/${ARCH}
41+
RUN make WHAT=cmd/kube-apiserver && \
42+
cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kube-apiserver.exe $DEST
43+
44+
# kubectl
45+
RUN /bin/bash -x -c ' \
46+
{ curl -sLO https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kubectl.exe && \
47+
chmod +x kubectl.exe && \
48+
cp kubectl.exe $DEST; } || \
49+
{ make WHAT=cmd/kubectl && \
50+
cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kubectl.exe $DEST; }'
51+
52+
# etcd
53+
WORKDIR /etcd
54+
ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH}
55+
RUN /bin/bash -x -c ' \
56+
{ curl -sLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD_BASE_NAME}.zip && \
57+
unzip -o ${ETCD_BASE_NAME}.zip && \
58+
cp ${ETCD_BASE_NAME}/etcd.exe $DEST; } || \
59+
{ rm -fr * && \
60+
git clone https://github.com/etcd-io/etcd . --depth=1 -b ${ETCD_VERSION} && \
61+
GOOS=${OS} GOARCH=${ARCH} ./build.sh && \
62+
cp ./bin/etcd.exe $DEST; }'
63+
64+
# Package into tarball.
65+
WORKDIR /usr/local
66+
RUN tar -czvf /kubebuilder_${OS}_${ARCH}.tar.gz kubebuilder/
67+
68+
# Copy tarball to final image.
69+
FROM alpine:3.19
70+
71+
# Platform args.
72+
ARG OS=windows
73+
ARG ARCH
74+
75+
COPY --from=builder /kubebuilder_${OS}_${ARCH}.tar.gz /

0 commit comments

Comments
 (0)