Skip to content

Commit

Permalink
Add github action to package envtest binaries in releases
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri committed Apr 16, 2024
1 parent 69c634f commit 018a41e
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 41 deletions.
55 changes: 17 additions & 38 deletions .github/workflows/tools-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,16 @@ on:
push:
branches:
- main
- tools-releases
paths:
- 'hack/envtest/_matrix/*.yaml'

permissions:
contents: read
packages: write
contents: 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 @@ -45,6 +30,7 @@ jobs:
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
Expand All @@ -55,25 +41,18 @@ jobs:
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
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: Build packages
run: |
make release-package-envtest \
KUBERNETES_VERSION=${{ env.KUBERNETES_VERSION }} \
GO_VERSION=${{ env.GO_VERSION }} \
ETCD_VERSION=${{ env.ETCD_VERSION }}
- name: Release
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # tag=v2.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}}
name: envtest/${{ env.KUBERNETES_VERSION }}
draft: true
prerelease: true
make_latest: false
files: out/*
fail_on_unmatched_files: true
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
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,50 @@ 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:
./hack/envtest/build.sh

.PHONY: release-package-envtest
release-package-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

.PHONY: release-envtest-docker-build
release-envtest-docker-build: $(RELEASE_DIR) ## Build the envtest binaries.
@: $(if $(GO_VERSION),,$(error GO_VERSION is not set))
@: $(if $(KUBERNETES_VERSION),,$(error KUBERNETES_VERSION is not set))
@: $(if $(ETCD_VERSION),,$(error ETCD_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 GO_VERSION=$(GO_VERSION) \
--build-arg KUBERNETES_VERSION=$(KUBERNETES_VERSION) \
--build-arg ETCD_VERSION=$(ETCD_VERSION) \
--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) \
.
20 changes: 20 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See https://cloud.google.com/cloud-build/docs/build-config
# See https://console.cloud.google.com/gcr/images/k8s-staging-test-infra/global/gcb-docker-gcloud
timeout: 2700s
options:
substitution_option: ALLOW_LOOSE
machineType: 'E2_HIGHCPU_8'
steps:
- name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20230522-312425ae46'
entrypoint: make
env:
- DOCKER_CLI_EXPERIMENTAL=enabled
- TAG=$_GIT_TAG
- PULL_BASE_REF=$_PULL_BASE_REF
- DOCKER_BUILDKIT=1
args: ['release-envtest', '-j', '8']
substitutions:
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and
# can be used as a substitution
_GIT_TAG: '12345'
_PULL_BASE_REF: 'dev'
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

8 changes: 7 additions & 1 deletion hack/envtest/darwin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ 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

# 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 /
8 changes: 7 additions & 1 deletion hack/envtest/linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ 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

# 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 /
8 changes: 7 additions & 1 deletion hack/envtest/windows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ 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

# 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 /

0 comments on commit 018a41e

Please sign in to comment.