diff --git a/.github/workflows/tools-releases.yml b/.github/workflows/tools-releases.yml new file mode 100644 index 000000000..8d0875e8f --- /dev/null +++ b/.github/workflows/tools-releases.yml @@ -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}} diff --git a/hack/envtest/_matrix/v1.28.0.yaml b/hack/envtest/_matrix/v1.28.0.yaml new file mode 100644 index 000000000..83bf3ddd8 --- /dev/null +++ b/hack/envtest/_matrix/v1.28.0.yaml @@ -0,0 +1,2 @@ +go: 1.21 +etcd: v3.5.9 diff --git a/hack/envtest/_matrix/v1.29.3.yaml b/hack/envtest/_matrix/v1.29.3.yaml new file mode 100644 index 000000000..d35406399 --- /dev/null +++ b/hack/envtest/_matrix/v1.29.3.yaml @@ -0,0 +1,2 @@ +go: 1.21 +etcd: v3.5.12 diff --git a/hack/envtest/darwin/Dockerfile b/hack/envtest/darwin/Dockerfile new file mode 100644 index 000000000..8adf45ace --- /dev/null +++ b/hack/envtest/darwin/Dockerfile @@ -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 diff --git a/hack/envtest/linux/Dockerfile b/hack/envtest/linux/Dockerfile new file mode 100644 index 000000000..d68072ec5 --- /dev/null +++ b/hack/envtest/linux/Dockerfile @@ -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 diff --git a/hack/envtest/windows/Dockerfile b/hack/envtest/windows/Dockerfile new file mode 100644 index 000000000..a74a73c0d --- /dev/null +++ b/hack/envtest/windows/Dockerfile @@ -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