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

Enhancement: Add kubectl 1.32.0 variants #182

Merged
merged 1 commit into from
Dec 12, 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
191 changes: 190 additions & 1 deletion .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,193 @@ jobs:
run: |
git diff --exit-code

build-1-32-0:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Display system info (linux)
run: |
set -e
hostname
whoami
cat /etc/*release
lscpu
free
df -h
pwd
docker info
docker version

# See: https://github.com/docker/build-push-action/blob/v2.6.1/docs/advanced/cache.md#github-cache
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-1.32.0-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-1.32.0-
${{ runner.os }}-buildx-

- name: Login to Docker Hub registry
# Run on master and tags
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
password: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }}

# This step generates the docker tags
- name: Prepare
id: prep-1-32-0
run: |
set -e

# Get ref, i.e. <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. 'master' or 'v0.0.0'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )

# Get short commit hash E.g. 'abc0123'
SHA=$( echo "${GITHUB_SHA}" | cut -c1-7 )

# Generate docker image tags
# E.g. 'v0.0.0-<variant>' and 'v0.0.0-abc0123-<variant>'
# E.g. 'master-<variant>' and 'master-abc0123-<variant>'
VARIANT="1.32.0"
REF_VARIANT="${REF}-${VARIANT}"
REF_SHA_VARIANT="${REF}-${SHA}-${VARIANT}"

# Pass variables to next step
echo "VARIANT_BUILD_DIR=$VARIANT_BUILD_DIR" >> $GITHUB_OUTPUT
echo "VARIANT=$VARIANT" >> $GITHUB_OUTPUT
echo "REF_VARIANT=$REF_VARIANT" >> $GITHUB_OUTPUT
echo "REF_SHA_VARIANT=$REF_SHA_VARIANT" >> $GITHUB_OUTPUT

- name: 1.32.0 - Build (PRs)
# Run only on pull requests
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v5
with:
context: variants/1.32.0
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: false
tags: |
${{ github.repository }}:${{ steps.prep-1-32-0.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-1-32-0.outputs.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: 1.32.0 - Build and push (master)
# Run only on master
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v5
with:
context: variants/1.32.0
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ steps.prep-1-32-0.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-1-32-0.outputs.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: 1.32.0 - Build and push (release)
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v5
with:
context: variants/1.32.0
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ steps.prep-1-32-0.outputs.VARIANT }}
${{ github.repository }}:${{ steps.prep-1-32-0.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-1-32-0.outputs.REF_SHA_VARIANT }}
${{ github.repository }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

# This step generates the docker tags
- name: Prepare
id: prep-1-32-0-envsubst-git-jq-kustomize-sops-ssh-yq
run: |
set -e

# Get ref, i.e. <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. 'master' or 'v0.0.0'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )

# Get short commit hash E.g. 'abc0123'
SHA=$( echo "${GITHUB_SHA}" | cut -c1-7 )

# Generate docker image tags
# E.g. 'v0.0.0-<variant>' and 'v0.0.0-abc0123-<variant>'
# E.g. 'master-<variant>' and 'master-abc0123-<variant>'
VARIANT="1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq"
REF_VARIANT="${REF}-${VARIANT}"
REF_SHA_VARIANT="${REF}-${SHA}-${VARIANT}"

# Pass variables to next step
echo "VARIANT_BUILD_DIR=$VARIANT_BUILD_DIR" >> $GITHUB_OUTPUT
echo "VARIANT=$VARIANT" >> $GITHUB_OUTPUT
echo "REF_VARIANT=$REF_VARIANT" >> $GITHUB_OUTPUT
echo "REF_SHA_VARIANT=$REF_SHA_VARIANT" >> $GITHUB_OUTPUT

- name: 1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq - Build (PRs)
# Run only on pull requests
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v5
with:
context: variants/1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: false
tags: |
${{ github.repository }}:${{ steps.prep-1-32-0-envsubst-git-jq-kustomize-sops-ssh-yq.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-1-32-0-envsubst-git-jq-kustomize-sops-ssh-yq.outputs.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: 1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq - Build and push (master)
# Run only on master
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v5
with:
context: variants/1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ steps.prep-1-32-0-envsubst-git-jq-kustomize-sops-ssh-yq.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-1-32-0-envsubst-git-jq-kustomize-sops-ssh-yq.outputs.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: 1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq - Build and push (release)
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v5
with:
context: variants/1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ steps.prep-1-32-0-envsubst-git-jq-kustomize-sops-ssh-yq.outputs.VARIANT }}
${{ github.repository }}:${{ steps.prep-1-32-0-envsubst-git-jq-kustomize-sops-ssh-yq.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-1-32-0-envsubst-git-jq-kustomize-sops-ssh-yq.outputs.REF_SHA_VARIANT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

build-1-31-4:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -141,7 +328,6 @@ jobs:
${{ github.repository }}:${{ steps.prep-1-31-4.outputs.VARIANT }}
${{ github.repository }}:${{ steps.prep-1-31-4.outputs.REF_VARIANT }}
${{ github.repository }}:${{ steps.prep-1-31-4.outputs.REF_SHA_VARIANT }}
${{ github.repository }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

Expand Down Expand Up @@ -3384,6 +3570,7 @@ jobs:

update-draft-release:
needs:
- build-1-32-0
- build-1-31-4
- build-1-30-8
- build-1-29-12
Expand Down Expand Up @@ -3415,6 +3602,7 @@ jobs:

publish-draft-release:
needs:
- build-1-32-0
- build-1-31-4
- build-1-30-8
- build-1-29-12
Expand Down Expand Up @@ -3448,6 +3636,7 @@ jobs:

update-dockerhub-description:
needs:
- build-1-32-0
- build-1-31-4
- build-1-30-8
- build-1-29-12
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Dockerized `kubectl` with useful tools.

| Tag | Dockerfile Build Context |
|:-------:|:---------:|
| `:1.31.4`, `:latest` | [View](variants/1.31.4) |
| `:1.32.0`, `:latest` | [View](variants/1.32.0) |
| `:1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq` | [View](variants/1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq) |
| `:1.31.4` | [View](variants/1.31.4) |
| `:1.31.4-envsubst-git-jq-kustomize-sops-ssh-yq` | [View](variants/1.31.4-envsubst-git-jq-kustomize-sops-ssh-yq) |
| `:1.30.8` | [View](variants/1.30.8) |
| `:1.30.8-envsubst-git-jq-kustomize-sops-ssh-yq` | [View](variants/1.30.8-envsubst-git-jq-kustomize-sops-ssh-yq) |
Expand Down
1 change: 1 addition & 0 deletions generate/definitions/versions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"kubectl": {
"versions": [
"1.32.0",
"1.31.4",
"1.30.8",
"1.29.12",
Expand Down
60 changes: 60 additions & 0 deletions variants/1.32.0-envsubst-git-jq-kustomize-sops-ssh-yq/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM alpine:3.15
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM"

RUN apk add --no-cache ca-certificates

# When $TARGETPLATFORM is linux/arm/v7, strip out the '/v6' or '/v7' from it
RUN set -eux; \
BIN_URL=https://dl.k8s.io/release/v1.32.0/bin/$( echo $TARGETPLATFORM | sed 's@/v[67]$@@' )/kubectl; \
SHA512=$( wget -qO- "$BIN_URL.sha512" ); \
wget -qO- "$BIN_URL" > /usr/local/bin/kubectl; \
chmod +x /usr/local/bin/kubectl; \
sha512sum /usr/local/bin/kubectl | grep "^$SHA512 "; \
kubectl version --client

# From: https://github.com/nginxinc/docker-nginx/blob/1.17.0/stable/alpine/Dockerfile
# Bring in gettext so we can get `envsubst`, then throw
# the rest away. To do this, we need to install `gettext`
# then move `envsubst` out of the way so `gettext` can
# be deleted completely, then move `envsubst` back.
RUN apk add --no-cache --virtual .gettext gettext \
&& mv /usr/bin/envsubst /tmp/ \
\
&& runDeps="$( \
scanelf --needed --nobanner /tmp/envsubst \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --no-cache $runDeps \
&& apk del .gettext \
&& mv /tmp/envsubst /usr/local/bin/

RUN apk add --no-cache git

RUN apk add --no-cache jq

RUN apk add --no-cache curl \
&& curl -L https://github.com/kubernetes-sigs/kustomize/releases/download/v2.0.3/kustomize_2.0.3_linux_amd64 -o /usr/local/bin/kustomize \
&& chmod +x /usr/local/bin/kustomize \
&& apk del curl

RUN set -eux; \
wget -qO- https://github.com/mozilla/sops/releases/download/v3.7.3/sops-v3.7.3.linux > /usr/local/bin/sops; \
chmod +x /usr/local/bin/sops; \
sha256sum /usr/local/bin/sops | grep '^53aec65e45f62a769ff24b7e5384f0c82d62668dd96ed56685f649da114b4dbb '; \
sops --version

RUN apk add --no-cache gnupg

RUN apk add --no-cache openssh-client

RUN apk add --no-cache yq

COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

ENTRYPOINT [ "/docker-entrypoint.sh" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -eu

if [ $# -gt 0 ] && [ "${1#-}" != "$1" ]; then
set -- kubectl "$@"
elif [ $# -gt 0 ] && kubectl "$1" --help > /dev/null 2>&1; then
set -- kubectl "$@"
fi

exec "$@"
20 changes: 20 additions & 0 deletions variants/1.32.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM alpine:3.15
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM"

RUN apk add --no-cache ca-certificates

# When $TARGETPLATFORM is linux/arm/v7, strip out the '/v6' or '/v7' from it
RUN set -eux; \
BIN_URL=https://dl.k8s.io/release/v1.32.0/bin/$( echo $TARGETPLATFORM | sed 's@/v[67]$@@' )/kubectl; \
SHA512=$( wget -qO- "$BIN_URL.sha512" ); \
wget -qO- "$BIN_URL" > /usr/local/bin/kubectl; \
chmod +x /usr/local/bin/kubectl; \
sha512sum /usr/local/bin/kubectl | grep "^$SHA512 "; \
kubectl version --client

COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

ENTRYPOINT [ "/docker-entrypoint.sh" ]
10 changes: 10 additions & 0 deletions variants/1.32.0/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -eu

if [ $# -gt 0 ] && [ "${1#-}" != "$1" ]; then
set -- kubectl "$@"
elif [ $# -gt 0 ] && kubectl "$1" --help > /dev/null 2>&1; then
set -- kubectl "$@"
fi

exec "$@"
Loading