generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add workflow for kubectl image build (versions 1.26.0 to 1.29.1)
- Loading branch information
Showing
2 changed files
with
159 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,148 @@ | ||
name: Build kubectl image | ||
on: | ||
schedule: | ||
# This will run the job daily at 00:13 UTC | ||
- cron: "13 0 * * *" | ||
workflow_dispatch: | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
REGCTL_VERSION: v0.5.7 | ||
SEMVER_VERSION: 3.4.0 | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
publish-docker: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
k8s_version: | ||
[ | ||
v1.26.0, | ||
v1.26.1, | ||
v1.26.2, | ||
v1.26.3, | ||
v1.26.4, | ||
v1.26.5, | ||
v1.26.6, | ||
v1.26.7, | ||
v1.26.8, | ||
v1.26.9, | ||
v1.26.10, | ||
v1.26.11, | ||
v1.26.12, | ||
v1.26.13, | ||
v1.26.14, | ||
v1.27.0, | ||
v1.27.1, | ||
v1.27.2, | ||
v1.27.3, | ||
v1.27.4, | ||
v1.27.5, | ||
v1.27.6, | ||
v1.27.7, | ||
v1.27.8, | ||
v1.27.9, | ||
v1.27.10, | ||
v1.27.11, | ||
v1.28.0, | ||
v1.28.1, | ||
v1.28.2, | ||
v1.28.3, | ||
v1.28.4, | ||
v1.28.5, | ||
v1.28.6, | ||
v1.28.7, | ||
v1.29.0, | ||
v1.29.1 | ||
] | ||
max-parallel: 1 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup regctl | ||
uses: regclient/actions/regctl-installer@main | ||
with: | ||
release: ${{ env.REGCTL_VERSION }} | ||
install-dir: ${{ runner.temp }}/bin | ||
|
||
- name: Setup semver | ||
uses: sap/cs-actions/setup-semver@main | ||
with: | ||
version: ${{ env.SEMVER_VERSION }} | ||
install-directory: ${{ runner.temp }}/bin | ||
|
||
- name: Prepare repository name | ||
id: prepare-repository-name | ||
run: | | ||
repository=$REGISTRY/${{ github.repository }} | ||
echo "repository=${repository,,}" >> $GITHUB_OUTPUT | ||
- name: Log in to the registry | ||
run: | | ||
regctl registry login $REGISTRY --user ${{ github.actor }} --pass-stdin <<< ${{ github.token }} | ||
# - name: Fetch latest k8s version | ||
# id: latest-k8s-version | ||
# run: | | ||
# echo "version=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)" >> $GITHUB_OUTPUT | ||
# | ||
# - name: Fetch latest docker build version | ||
# id: latest-image-version | ||
# run: | | ||
# echo "version=$(regctl tag list ${{ steps.prepare-repository-name.outputs.repository }} | sort -V | tail -1)" >> $GITHUB_OUTPUT | ||
# | ||
# - name: Print both versions | ||
# run: | | ||
# echo "Latest k8s version: ${{ steps.latest-k8s-version.outputs.version }}" | ||
# echo "Latest image version: ${{ steps.latest-image-version.outputs.version }}" | ||
# | ||
# - name: Compare versions | ||
# id: compare-versions | ||
# run: | | ||
# if [ $(semver compare ${{ steps.latest-k8s-version.outputs.version }} ${{ steps.latest-image-version.outputs.version }}) -lt 0 ] | ||
# then | ||
# echo "Latest k8s version (${{ steps.latest-k8s-version.outputs.version }}) is lower than latest built image version (${{ steps.latest-image-version.outputs.version }}); skipping build ..." | ||
# exit 0 | ||
# elif [ $(semver compare ${{ steps.latest-k8s-version.outputs.version }} ${{ steps.latest-image-version.outputs.version }}) -gt 0 ] | ||
# then | ||
# echo "Latest k8s version (${{ steps.latest-k8s-version.outputs.version }}) is higher than latest built image version (${{ steps.latest-image-version.outputs.version }}); building ..." | ||
# echo "build_image=true" >> $GITHUB_OUTPUT | ||
# fi | ||
|
||
- name: Setup Docker Buildx | ||
# if: steps.compare-versions.outputs.build_image == 'true' | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to the Container registry | ||
# if: steps.compare-versions.outputs.build_image == 'true' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ github.token }} | ||
|
||
- name: Build and push docker image | ||
# if: steps.compare-versions.outputs.build_image == 'true' | ||
uses: docker/build-push-action@v5 | ||
with: | ||
platforms: linux/amd64,linux/arm64 | ||
context: . | ||
file: ./Dockerfile | ||
tags: ${{ steps.prepare-repository-name.outputs.repository }}:${{ matrix.k8s_version }} | ||
# tags: ${{ steps.prepare-repository-name.outputs.repository }}:${{ steps.latest-k8s-version.outputs.version }} | ||
cache-from: | | ||
type=gha,scope=sha-${{ github.sha }} | ||
type=gha,scope=${{ github.ref_name }} | ||
type=gha,scope=${{ github.base_ref || 'main' }} | ||
type=gha,scope=main | ||
cache-to: | | ||
type=gha,scope=sha-${{ github.sha }},mode=max | ||
type=gha,scope=${{ github.ref_name }},mode=max | ||
build-args: "KUBECTL_VERSION=${{ matrix.k8s_version }}" | ||
# build-args: "KUBECTL_VERSION=${{ steps.latest-k8s-version.outputs.version }}" | ||
push: true |
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,11 @@ | ||
FROM alpine:3.19 | ||
|
||
ARG TARGETARCH KUBECTL_VERSION | ||
|
||
ENTRYPOINT ["/usr/local/bin/kubectl"] | ||
|
||
RUN apk add bash openssl curl jq | ||
|
||
RUN curl -sSfL -o /usr/local/bin/kubectl-${KUBECTL_VERSION} https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl \ | ||
&& chmod a+x /usr/local/bin/kubectl-${KUBECTL_VERSION} \ | ||
&& ln -s kubectl-${KUBECTL_VERSION} /usr/local/bin/kubectl |