-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Build and publish Kubernetes envtest tools as packages
Signed-off-by: Vince Prignano <[email protected]>
- Loading branch information
Showing
4 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Kubernetes Tools Releases for controller-runtime envtest | ||
|
||
on: | ||
push: | ||
branches: | ||
- tools-releases | ||
|
||
env: | ||
KUBERNETES_VERSION: 1.28.0 | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
os: | ||
- linux | ||
- darwin | ||
- windows | ||
arch: | ||
- amd64 | ||
- arm64 | ||
include: | ||
- arch: ppc64le | ||
os: linux | ||
- arch: s390x | ||
os: linux | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Set up Docker | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Build and push Docker images | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./hack/tools/envtest/${{matrix.os}}/Dockerfile | ||
build-args: | | ||
KUBERNETES_VERSION=v${KUBERNETES_VERSION} | ||
OS=${{matrix.os}} | ||
ARCH=${{matrix.arch}} | ||
push: true | ||
github_token: ${{secrets.GITHUB_TOKEN}} | ||
tags: | | ||
ghcr.io/kubernetes-sigs/controller-tools/x-kubernetes-${{matrix.os}}-${{matrix.arch}}:${{env.KUBERNETES_VERSION}}-experimental |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright 2018 The Kubernetes Authors. | ||
# | ||
# 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. | ||
|
||
# Build or fetch the following binaries for darwin and then host them in a tar.gz file in an alpine image | ||
# - kube-apiserver (build) | ||
# - kubectl (fetch) | ||
# - etcd (fetch) | ||
|
||
FROM golang:1.21 as builder | ||
|
||
# Version and platform args. | ||
ARG KUBERNETES_VERSION | ||
ARG ETCD_VERSION=v3.5.13 | ||
ARG OS=darwin | ||
ARG ARCH | ||
|
||
# Tools path. | ||
ENV DEST=/usr/local/kubebuilder/bin/ | ||
|
||
# Install dependencies. | ||
RUN apt update && \ | ||
apt install unzip rsync -y && \ | ||
mkdir -p $DEST | ||
|
||
# kube-apiserver | ||
WORKDIR /kubernetes | ||
RUN git clone https://github.com/kubernetes/kubernetes . --depth=1 -b ${KUBERNETES_VERSION} | ||
ENV CGO_ENABLED=0 | ||
ENV KUBE_BUILD_PLATFORMS=${OS}/${ARCH} | ||
RUN make WHAT=cmd/kube-apiserver && \ | ||
cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kube-apiserver $DEST | ||
|
||
# kubectl | ||
RUN /bin/bash -x -c ' \ | ||
{ curl -sLO https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kubectl && \ | ||
chmod +x kubectl && \ | ||
cp kubectl $DEST; } || \ | ||
{ make WHAT=cmd/kubectl && \ | ||
cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kubectl $DEST; }' | ||
|
||
# etcd | ||
WORKDIR /etcd | ||
ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH} | ||
RUN /bin/bash -x -c ' \ | ||
{ curl -sLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD_BASE_NAME}.zip && \ | ||
unzip -o ${ETCD_BASE_NAME}.zip && \ | ||
cp ${ETCD_BASE_NAME}/etcd $DEST; } || \ | ||
{ rm -fr * && \ | ||
git clone https://github.com/etcd-io/etcd . --depth=1 -b ${ETCD_VERSION} && \ | ||
GOOS=${OS} GOARCH=${ARCH} ./build.sh && \ | ||
cp ./bin/etcd $DEST; }' | ||
|
||
# Package into tarball. | ||
WORKDIR /usr/local | ||
RUN tar -czvf /kubebuilder_${OS}_${ARCH}.tar.gz kubebuilder/ | ||
|
||
# Copy tarball to final image. | ||
FROM alpine:3.19 | ||
|
||
# Platform args. | ||
ARG OS=darwin | ||
ARG ARCH | ||
|
||
COPY --from=builder /kubebuilder_${OS}_${ARCH}.tar.gz / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright 2018 The Kubernetes Authors. | ||
# | ||
# 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. | ||
|
||
# Fetch the following into binaries for linux and then host them in a tar.gz file in an alpine image | ||
# - kube-apiserver (fetch) | ||
# - kubectl (fetch) | ||
# - etcd (fetch) | ||
|
||
# no need for anything fancy | ||
FROM alpine:3.19 as builder | ||
|
||
# Version and platform args. | ||
ARG KUBERNETES_VERSION | ||
ARG ETCD_VERSION=v3.5.13 | ||
ARG OS=linux | ||
ARG ARCH | ||
|
||
# Tools path. | ||
ENV DEST=/usr/local/kubebuilder/bin/ | ||
|
||
# Install dependencies. | ||
RUN apk add --no-cache curl && \ | ||
mkdir -p $DEST | ||
|
||
# kube-apiserver | ||
RUN curl -sLO https://dl.k8s.io/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kube-apiserver && \ | ||
chmod +x kube-apiserver && \ | ||
cp kube-apiserver $DEST | ||
|
||
# kubectl | ||
RUN curl -sLO https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kubectl && \ | ||
chmod +x kubectl && \ | ||
cp kubectl $DEST | ||
|
||
# etcd | ||
ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH} | ||
RUN curl -sLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD_BASE_NAME}.tar.gz && \ | ||
tar xzf ${ETCD_BASE_NAME}.tar.gz && \ | ||
cp ${ETCD_BASE_NAME}/etcd $DEST | ||
|
||
# Package into tarball. | ||
WORKDIR /usr/local | ||
RUN tar -czvf /kubebuilder_${OS}_${ARCH}.tar.gz kubebuilder/ | ||
|
||
# Copy tarball to final image. | ||
FROM alpine:3.19 | ||
|
||
# Platform args. | ||
ARG OS=linux | ||
ARG ARCH | ||
|
||
COPY --from=builder /kubebuilder_${OS}_${ARCH}.tar.gz / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright 2018 The Kubernetes Authors. | ||
# | ||
# 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. | ||
|
||
# Build or fetch the following binaries for windows and then host them in a tar.gz file in an alpine image | ||
# - kube-apiserver (build) | ||
# - kubectl (fetch) | ||
# - etcd (fetch) | ||
|
||
FROM golang:1.21 as builder | ||
|
||
# Version and platform args. | ||
ARG KUBERNETES_VERSION | ||
ARG ETCD_VERSION=v3.5.13 | ||
ARG OS=windows | ||
ARG ARCH | ||
|
||
# Tools path. | ||
ENV DEST=/usr/local/kubebuilder/bin/ | ||
|
||
# Install dependencies. | ||
RUN apt update && \ | ||
apt install unzip rsync -y && \ | ||
mkdir -p $DEST | ||
|
||
# kube-apiserver | ||
WORKDIR /kubernetes | ||
RUN git clone https://github.com/kubernetes/kubernetes . --depth=1 -b ${KUBERNETES_VERSION} | ||
ENV CGO_ENABLED=0 | ||
ENV KUBE_BUILD_PLATFORMS=${OS}/${ARCH} | ||
RUN make WHAT=cmd/kube-apiserver && \ | ||
cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kube-apiserver.exe $DEST | ||
|
||
# kubectl | ||
RUN /bin/bash -x -c ' \ | ||
{ curl -sLO https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kubectl.exe && \ | ||
chmod +x kubectl.exe && \ | ||
cp kubectl.exe $DEST; } || \ | ||
{ make WHAT=cmd/kubectl && \ | ||
cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kubectl.exe $DEST; }' | ||
|
||
# etcd | ||
WORKDIR /etcd | ||
ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH} | ||
RUN /bin/bash -x -c ' \ | ||
{ curl -sLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD_BASE_NAME}.zip && \ | ||
unzip -o ${ETCD_BASE_NAME}.zip && \ | ||
cp ${ETCD_BASE_NAME}/etcd.exe $DEST; } || \ | ||
{ rm -fr * && \ | ||
git clone https://github.com/etcd-io/etcd . --depth=1 -b ${ETCD_VERSION} && \ | ||
GOOS=${OS} GOARCH=${ARCH} ./build.sh && \ | ||
cp ./bin/etcd.exe $DEST; }' | ||
|
||
# Package into tarball. | ||
WORKDIR /usr/local | ||
RUN tar -czvf /kubebuilder_${OS}_${ARCH}.tar.gz kubebuilder/ | ||
|
||
# Copy tarball to final image. | ||
FROM alpine:3.19 | ||
|
||
# Platform args. | ||
ARG OS=windows | ||
ARG ARCH | ||
|
||
COPY --from=builder /kubebuilder_${OS}_${ARCH}.tar.gz / |