Skip to content

Commit ec5fa58

Browse files
committed
feat: add CI workflow and Dockerfile for kubectl image
Introduce a GitHub Actions workflow to build and publish a Docker image containing kubectl. The workflow supports multi-architecture builds and caches Docker layers for efficiency. Add a Dockerfile that downloads the specified kubectl release, verifies its checksum, and sets up a minimal runtime environment with a non-root user.
1 parent efe7e72 commit ec5fa58

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: ci
2+
on: [push, pull_request]
3+
jobs:
4+
image:
5+
name: "Publish kubectl image on Docker Hub"
6+
runs-on: ubuntu-latest
7+
strategy:
8+
fail-fast: true
9+
matrix:
10+
kubectl:
11+
- v1.34.0
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: docker/setup-qemu-action@v2
16+
- uses: docker/setup-buildx-action@v2
17+
- uses: actions/cache@v3
18+
with:
19+
path: /tmp/.buildx-cache
20+
key: ${{ runner.os }}-buildx-${{ github.sha }}
21+
restore-keys: |
22+
${{ runner.os }}-buildx-
23+
- name: Set Docker tags
24+
run: |
25+
if [[ "${{ github.ref }}" == "refs/heads/main" ]] || [[ "${{ github.ref }}" == refs/tags/* ]]; then
26+
echo DOCKER_TAGS=tsuru/kubectl:${{ matrix.kubectl }},tsuru/kubectl:${{ matrix.kubectl }}-${GITHUB_REF##*/} >> $GITHUB_ENV
27+
else
28+
echo DOCKER_TAGS=tsuru/kubectl:${{ matrix.kubectl }}-${GITHUB_REF##*/} >> $GITHUB_ENV
29+
fi
30+
- uses: docker/login-action@v3
31+
if: github.event_name != 'pull_request'
32+
with:
33+
username: ${{ secrets.DOCKERHUB_USERNAME }}
34+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
35+
- uses: docker/build-push-action@v5
36+
if: github.event_name != 'pull_request'
37+
with:
38+
push: true
39+
tags: ${{ env.DOCKER_TAGS }}
40+
cache-from: type=local,src=/tmp/.buildx-cache
41+
cache-to: type=local,dest=/tmp/.buildx-cache
42+
platforms: linux/amd64,linux/arm64
43+
build-args: |
44+
KUBECTL_RELEASE=${{ matrix.kubectl }}

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM docker.io/debian:bookworm AS build
2+
3+
ARG KUBECTL_RELEASE
4+
ARG TARGETPLATFORM
5+
6+
RUN apt-get update \
7+
&& apt-get install -y apt-transport-https ca-certificates curl gnupg
8+
9+
WORKDIR /bin
10+
11+
RUN set -x \
12+
&& curl -fsSLO "https://dl.k8s.io/release/${KUBECTL_RELEASE}/bin/${TARGETPLATFORM}/kubectl" \
13+
&& curl -LO "https://dl.k8s.io/release/${KUBECTL_RELEASE}/bin/${TARGETPLATFORM}/kubectl.sha256" \
14+
&& echo "$(cat kubectl.sha256) kubectl" | sha256sum --check \
15+
&& chmod +x kubectl
16+
17+
RUN useradd -u 1000 -U -m kubectl
18+
19+
USER kubectl
20+
ENTRYPOINT ["/bin/kubectl"]
21+
CMD ["help"]

0 commit comments

Comments
 (0)