Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Build and publish Kubernetes envtest tools as packages #906

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/tools-releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Package controller-runtime envtest

on:
push:
branches:
- main
paths:
- 'hack/envtest/_matrix/*.yaml'

permissions:
contents: read
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
matrix:
os:
- linux
- darwin
arch:
- amd64
- arm64
include:
- arch: ppc64le
os: linux
- arch: s390x
os: linux
- arch: amd64
os: windows
steps:
- name: Checkout code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # tag=v4.1.2
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@2d756ea4c53f7f6b397767d8723b3a10a9f35bf2 # tag=v44.0.0
with:
files: |
hack/envtest/_matrix/*.yaml
- name: Setup package release version
id: release-version
run: |
if [[ ${{ steps.changed-files.outputs.all_changed_files_count }} != 1 ]]; then
echo "One Kubernetes patch version files should be changed to create a package, found ${{ steps.changed-files.outputs.all_changed_files_count }}"
exit 1
fi
for changed_file in ${{ steps.changed-files.outputs.all_changed_files }}; do
export KUBERNETES_VERSION=$(echo "${changed_file}" | grep -oP '(?<=/)[^/]+(?=\.yaml)')
echo "KUBERNETES_VERSION=$KUBERNETES_VERSION" >> $GITHUB_ENV

GO_VERSION=$(yq eval '.go' $changed_file)
echo "GO_VERSION=$GO_VERSION" >> $GITHUB_ENV

ETCD_VERSION=$(yq eval '.etcd' $changed_file)
echo "ETCD_VERSION=$ETCD_VERSION" >> $GITHUB_ENV
done
- name: Set up Docker
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # tag=v3.2.0
- name: Log in to the Container registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # tag=v3.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker images
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # tag=v5.3.0
with:
context: .
file: ./hack/envtest/${{matrix.os}}/Dockerfile
build-args: |
GO_VERSION=${{env.GO_VERSION}}
KUBERNETES_VERSION=${{env.KUBERNETES_VERSION}}
ETCD_VERSION=${{env.ETCD_VERSION}}
OS=${{matrix.os}}
ARCH=${{matrix.arch}}
push: true
tags: |
ghcr.io/kubernetes-sigs/controller-tools/envtest:${{env.KUBERNETES_VERSION}}-${{matrix.os}}-${{matrix.arch}}
2 changes: 2 additions & 0 deletions hack/envtest/_matrix/v1.28.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go: 1.21
etcd: v3.5.9
2 changes: 2 additions & 0 deletions hack/envtest/_matrix/v1.29.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go: 1.21
etcd: v3.5.12
56 changes: 56 additions & 0 deletions hack/envtest/darwin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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.

ARG GO_VERSION
FROM golang:${GO_VERSION} as builder

# Version and platform args.
ARG KUBERNETES_VERSION
ARG ETCD_VERSION
ARG OS=darwin
ARG ARCH

# Tools path.
ENV DEST=/controller-tools/envtest

# 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 -sfLO 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
ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH}
RUN curl -sfLO 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

# Build the final image with the binaries.
FROM scratch
COPY --from=builder /controller-tools/envtest /controller-tools/envtest
50 changes: 50 additions & 0 deletions hack/envtest/linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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.

ARG GO_VERSION
FROM golang:${GO_VERSION} as builder

# Version and platform args.
ARG KUBERNETES_VERSION
ARG ETCD_VERSION
ARG OS=linux
ARG ARCH

# Tools path.
ENV DEST=/controller-tools/envtest

# Install dependencies.
RUN apt update && \
apt install unzip rsync -y && \
mkdir -p $DEST

# kube-apiserver
RUN curl -sfLO https://dl.k8s.io/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kube-apiserver && \
chmod +x kube-apiserver && \
cp kube-apiserver $DEST

# kubectl
RUN curl -sfLO 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 -sfLO 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

# Build the final image with the binaries.
FROM scratch
COPY --from=builder /controller-tools/envtest /controller-tools/envtest
56 changes: 56 additions & 0 deletions hack/envtest/windows/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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.

ARG GO_VERSION
FROM golang:${GO_VERSION} as builder

# Version and platform args.
ARG KUBERNETES_VERSION
ARG ETCD_VERSION
ARG OS=windows
ARG ARCH

# Tools path.
ENV DEST=/controller-tools/envtest

# 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 -sfLO 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
ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH}
RUN curl -sfLO 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

# Build the final image with the binaries.
FROM scratch
COPY --from=builder /controller-tools/envtest /controller-tools/envtest