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

✨ Add github action to package envtest binaries in releases #908

Merged
merged 1 commit into from
Apr 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 25 additions & 44 deletions .github/workflows/tools-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,12 @@ on:
- 'hack/envtest/_matrix/*.yaml'

permissions:
contents: read
packages: write
contents: write
pull-requests: 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
Expand All @@ -42,38 +27,34 @@ jobs:
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 }}"
echo "One Kubernetes patch version files should be changed for a release, 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@d70bba72b1f3fd22344832f00baa16ece964efeb # tag=v3.3.0
- name: Log in to the Container registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # tag=v3.1.0
- name: Build packages
run: |
make release-envtest KUBERNETES_VERSION=${{ env.KUBERNETES_VERSION }}
- name: Release
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # tag=v2.0.4
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
name: envtest-${{ env.KUBERNETES_VERSION }}
vincepri marked this conversation as resolved.
Show resolved Hide resolved
draft: true
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
make_latest: false
files: |
out/envtest-*.tar.gz
out/envtest-*.tar.gz.sha512
fail_on_unmatched_files: true
- name: Create Pull Request
uses: peter-evans/create-pull-request@9153d834b60caba6d51c9b9510b087acf9f33f83 # tag=v6.0.4
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}}
commit-message: Promote envtest release for Kubernetes ${{ env.KUBERNETES_VERSION }}
title: ":seedling: Promotion of envtest release for Kubernetes ${{ env.KUBERNETES_VERSION }}"
body: |
This PR promotes the envtest release for Kubernetes ${{ env.KUBERNETES_VERSION }}.
branch: promote-envtest-${{ env.KUBERNETES_VERSION }}
add-paths: |
envtest-releases.yaml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*~

# Tools binaries.
out
hack/tools/bin

junit-report.xml
Expand Down
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export GOPROXY
export GO111MODULE=on

# Tools.
ENVTEST_DIR := hack/envtest
ENVTEST_MATRIX_DIR := $(ENVTEST_DIR)/_matrix
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint)
Expand Down Expand Up @@ -92,3 +94,44 @@ clean: ## Cleanup.
.PHONY: clean-bin
clean-bin: ## Remove all generated binaries.
rm -rf hack/tools/bin

.PHONE: clean-release
clean-release: ## Remove all generated release binaries.
rm -rf $(RELEASE_DIR)

## --------------------------------------
## Envtest Build
## --------------------------------------

RELEASE_DIR := out

.PHONY: $(RELEASE_DIR)
$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)/

.PHONY: release-envtest
release-envtest: clean-release ## Build the envtest binaries by operating system.
OS=linux ARCH=amd64 $(MAKE) release-envtest-docker-build
OS=linux ARCH=arm64 $(MAKE) release-envtest-docker-build
OS=linux ARCH=ppc64le $(MAKE) release-envtest-docker-build
OS=linux ARCH=s390x $(MAKE) release-envtest-docker-build
OS=darwin ARCH=amd64 $(MAKE) release-envtest-docker-build
OS=darwin ARCH=arm64 $(MAKE) release-envtest-docker-build
OS=windows ARCH=amd64 $(MAKE) release-envtest-docker-build
./hack/envtest/update-releases.sh

.PHONY: release-envtest-docker-build
release-envtest-docker-build: $(RELEASE_DIR) ## Build the envtest binaries.
@: $(if $(KUBERNETES_VERSION),,$(error KUBERNETES_VERSION is not set))
@: $(if $(OS),,$(error OS is not set))
@: $(if $(ARCH),,$(error ARCH is not set))
docker buildx build \
--file ./hack/envtest/$(OS)/Dockerfile \
--build-arg KUBERNETES_VERSION=$(KUBERNETES_VERSION) \
--build-arg GO_VERSION=$(shell yq eval '.go' $(ENVTEST_MATRIX_DIR)/$(KUBERNETES_VERSION).yaml) \
--build-arg ETCD_VERSION=$(shell yq eval '.etcd' $(ENVTEST_MATRIX_DIR)/$(KUBERNETES_VERSION).yaml) \
--build-arg OS=$(OS) \
--build-arg ARCH=$(ARCH) \
--tag sigs.k8s.io/controller-tools/envtest:$(KUBERNETES_VERSION)-$(OS)-$(ARCH) \
--output type=local,dest=$(RELEASE_DIR) \
.
1 change: 1 addition & 0 deletions envtest-releases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
releases:
1 change: 1 addition & 0 deletions hack/envtest/_matrix/v1.28.0.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
go: 1.21
etcd: v3.5.9

10 changes: 9 additions & 1 deletion hack/envtest/darwin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ RUN curl -sfLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/
unzip -o ${ETCD_BASE_NAME}.zip && \
cp ${ETCD_BASE_NAME}/etcd $DEST

# Package into tarball.
RUN tar -czvf /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz $DEST
RUN sha512sum /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz > /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512

# Build the final image with the binaries.
FROM scratch
COPY --from=builder /controller-tools/envtest /controller-tools/envtest
ARG OS
ARG ARCH
ARG KUBERNETES_VERSION
COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz /
COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512 /
10 changes: 9 additions & 1 deletion hack/envtest/linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ RUN curl -sfLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/
tar xzf ${ETCD_BASE_NAME}.tar.gz && \
cp ${ETCD_BASE_NAME}/etcd $DEST

# Package into tarball.
RUN tar -czvf /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz $DEST
RUN sha512sum /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz > /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512

# Build the final image with the binaries.
FROM scratch
COPY --from=builder /controller-tools/envtest /controller-tools/envtest
ARG OS
ARG ARCH
ARG KUBERNETES_VERSION
COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz /
COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512 /
44 changes: 44 additions & 0 deletions hack/envtest/update-releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# Copyright 2024 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.

set -o errexit
set -o nounset
set -o pipefail
set -x

ROOT=$(dirname "${BASH_SOURCE[0]}")/../..

if [ -z "${KUBERNETES_VERSION}" ]; then
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
echo "Missing KUBERNETES_VERSION environment variable"
exit 1
fi

# Create the releases.yaml file in hack/envtest if it does not exist
if [ ! -f "${ROOT}"/envtest-releases.yaml ]; then
echo "releases:" > "${ROOT}"/envtest-releases.yaml
fi

# Add the newly built Kubernetes version to the releases.yaml file with yq as an object key under releases
yq eval ".releases += {\"${KUBERNETES_VERSION}\": {}}" -i "${ROOT}"/envtest-releases.yaml

for file in "${ROOT}"/out/*.tar.gz; do
file_name=$(basename "${file}")
file_hash=$(awk '{ print $1 }' < "${file}.sha512")
self_link=https://github.com/kubernetes-sigs/controller-tools/releases/download/envtest-${KUBERNETES_VERSION}/${file_name}

yq eval \
".releases[\"${KUBERNETES_VERSION}\"] += {\"${file_name}\": {\"hash\": \"${file_hash}\", \"self_link\": \"${self_link}\"}}" \
-i "${ROOT}"/envtest-releases.yaml
done
10 changes: 9 additions & 1 deletion hack/envtest/windows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ RUN curl -sfLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/
unzip -o ${ETCD_BASE_NAME}.zip && \
cp ${ETCD_BASE_NAME}/etcd.exe $DEST

# Package into tarball.
RUN tar -czvf /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz $DEST
RUN sha512sum /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz > /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512

# Build the final image with the binaries.
FROM scratch
COPY --from=builder /controller-tools/envtest /controller-tools/envtest
ARG OS
ARG ARCH
ARG KUBERNETES_VERSION
COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz /
COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512 /