Skip to content

Commit 2e25f57

Browse files
Merge pull request #1 from dheeraj-coding/toolkit-image
feat: add base toolkit image builder using github actions
2 parents be496f9 + 27503e2 commit 2e25f57

File tree

3 files changed

+230
-0
lines changed

3 files changed

+230
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Create and publish toolkit base image
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
REGISTRY: ghcr.io
8+
IMAGE_NAME: ${{ github.repository }}
9+
BUILD_CONTEXT: ../../tests/images/toolkit-base/
10+
11+
jobs:
12+
build-and-push-image:
13+
runs-on: ubuntu-latest
14+
15+
permissions:
16+
contents: read
17+
packages: write
18+
attestations: write
19+
id-token: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v5
24+
25+
- name: Install jq
26+
run: sudo apt-get update && sudo apt-get install -y jq
27+
28+
- name: Setup QEMU
29+
uses: docker/setup-qemu-action@v3
30+
31+
- name: Setup docker buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to the Container registry
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Extract metadata (tags, labels) for Docker
42+
id: meta
43+
uses: docker/metadata-action@v5
44+
with:
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+
tags: |
47+
type=sha,prefix=,suffix=,enable=true,event=push,length=7
48+
type=raw,value=latest,enable=true
49+
50+
- name: Extract latest tool versions
51+
id: versions
52+
working-directory: ${{ env.BUILD_CONTEXT }}
53+
run: |
54+
chmod +x ./get_versions.sh
55+
./get_versions.sh
56+
57+
- name: Build and push Docker image
58+
uses: docker/build-push-action@v6
59+
with:
60+
context: ${{ env.BUILD_CONTEXT }}
61+
platforms: linux/amd64,linux/arm64
62+
push: true
63+
tags: ${{ steps.meta.outputs.tags }}
64+
labels: ${{ steps.meta.outputs.labels }}
65+
66+
build-args: |
67+
KUBECTL_VERSION=${{ steps.versions.outputs.k8s_tag }}
68+
HELM_VERSION=${{ steps.versions.outputs.helm_version }}
69+
KUSTOMIZE_VERSION=${{ steps.versions.outputs.kustomize_version }}
70+
KUBESEAL_VERSION=${{ steps.versions.outputs.kubeseal_version }}
71+
KREW_VERSION=${{ steps.versions.outputs.krew_version }}
72+
VALS_VERSION=${{ steps.versions.outputs.vals_version }}
73+
KUBECONFORM_VERSION=${{ steps.versions.outputs.kubeconform_version }}
74+
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
FROM alpine
2+
3+
ARG ARCH
4+
5+
# Ignore to update versions here
6+
# docker build --no-cache --build-arg KUBECTL_VERSION=${tag} --build-arg HELM_VERSION=${helm} --build-arg KUSTOMIZE_VERSION=${kustomize_version} -t ${image}:${tag} .
7+
ARG HELM_VERSION=3.2.1
8+
ARG KUBECTL_VERSION=1.17.5
9+
ARG KUSTOMIZE_VERSION=v3.8.1
10+
ARG KUBESEAL_VERSION=0.18.1
11+
ARG KREW_VERSION=v0.4.4
12+
ARG VALS_VERSION=0.28.1
13+
ARG KUBECONFORM_VERSION=0.6.3
14+
15+
# Install helm (latest release)
16+
# ENV BASE_URL="https://storage.googleapis.com/kubernetes-helm"
17+
RUN case `uname -m` in \
18+
x86_64) ARCH=amd64; ;; \
19+
armv7l) ARCH=arm; ;; \
20+
aarch64) ARCH=arm64; ;; \
21+
ppc64le) ARCH=ppc64le; ;; \
22+
s390x) ARCH=s390x; ;; \
23+
*) echo "un-supported arch, exit ..."; exit 1; ;; \
24+
esac && \
25+
echo "export ARCH=$ARCH" > /envfile && \
26+
cat /envfile
27+
28+
RUN . /envfile && echo $ARCH && \
29+
apk add --update --no-cache curl ca-certificates bash git && \
30+
curl -sL https://get.helm.sh/helm-v${HELM_VERSION}-linux-${ARCH}.tar.gz | tar -xvz && \
31+
mv linux-${ARCH}/helm /usr/bin/helm && \
32+
chmod +x /usr/bin/helm && \
33+
rm -rf linux-${ARCH}
34+
35+
# add helm-diff
36+
RUN helm plugin install https://github.com/databus23/helm-diff --verify=false && rm -rf /tmp/helm-* && \
37+
rm -rf ~/.cache/helm/plugins/https-github.com-databus23-helm-diff/.git
38+
39+
# add helm-unittest
40+
RUN helm plugin install https://github.com/helm-unittest/helm-unittest --verify=false && rm -rf /tmp/helm-*
41+
42+
# add helm-push
43+
RUN helm plugin install https://github.com/chartmuseum/helm-push --verify=false && \
44+
rm -rf /tmp/helm-* \
45+
/root/.local/share/helm/plugins/helm-push/testdata \
46+
/root/.cache/helm/plugins/https-github.com-chartmuseum-helm-push/testdata
47+
48+
# Install kubectl
49+
RUN . /envfile && echo $ARCH && \
50+
curl -sLO "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${ARCH}/kubectl" && \
51+
mv kubectl /usr/bin/kubectl && \
52+
chmod +x /usr/bin/kubectl
53+
54+
# Install kustomize (latest release)
55+
RUN . /envfile && echo $ARCH && \
56+
curl -sLO https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_${ARCH}.tar.gz && \
57+
tar xvzf kustomize_${KUSTOMIZE_VERSION}_linux_${ARCH}.tar.gz && \
58+
mv kustomize /usr/bin/kustomize && \
59+
chmod +x /usr/bin/kustomize && \
60+
rm kustomize_${KUSTOMIZE_VERSION}_linux_${ARCH}.tar.gz
61+
62+
# Install eksctl (latest version)
63+
RUN . /envfile && echo $ARCH && \
64+
curl -sL "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_${ARCH}.tar.gz" | tar xz -C /tmp && \
65+
mv /tmp/eksctl /usr/bin && \
66+
chmod +x /usr/bin/eksctl
67+
68+
# Install awscli
69+
# Temp fix to allow system-wide package installation:
70+
# https://stackoverflow.com/a/76540031/3671801
71+
RUN apk add --update --no-cache py3-pip && \
72+
pip3 install --break-system-packages --upgrade pip setuptools && \
73+
pip3 install --break-system-packages awscli && \
74+
pip3 cache purge
75+
76+
# Install jq
77+
RUN apk add --update --no-cache jq yq
78+
79+
# https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html
80+
# Install aws-iam-authenticator (latest version)
81+
RUN . /envfile && echo $ARCH && \
82+
authenticator=$(curl -fs https://api.github.com/repos/kubernetes-sigs/aws-iam-authenticator/releases/latest | jq --raw-output '.name' | sed 's/^v//') && \
83+
curl -fL https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v${authenticator}/aws-iam-authenticator_${authenticator}_linux_${ARCH} -o /usr/bin/aws-iam-authenticator && \
84+
chmod +x /usr/bin/aws-iam-authenticator
85+
86+
# Install for envsubst
87+
RUN apk add --update --no-cache gettext
88+
89+
# Install kubeseal
90+
RUN . /envfile && echo $ARCH && \
91+
curl -L https://github.com/bitnami-labs/sealed-secrets/releases/download/v${KUBESEAL_VERSION}/kubeseal-${KUBESEAL_VERSION}-linux-${ARCH}.tar.gz -o - | tar xz -C /usr/bin/ && \
92+
chmod +x /usr/bin/kubeseal
93+
94+
# Install vals
95+
RUN . /envfile && echo $ARCH && \
96+
curl -L https://github.com/helmfile/vals/releases/download/v${VALS_VERSION}/vals_${VALS_VERSION}_linux_${ARCH}.tar.gz -o -| tar xz -C /usr/bin/ && \
97+
chmod +x /usr/bin/vals
98+
99+
# Install krew (latest release)
100+
RUN . /envfile && echo $ARCH && \
101+
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/download/v${KREW_VERSION}/krew-linux_${ARCH}.tar.gz" && \
102+
tar zxvf krew-linux_${ARCH}.tar.gz && \
103+
./krew-linux_${ARCH} install krew && \
104+
echo 'export PATH=/root/.krew/bin:$PATH' >> ~/.bashrc && \
105+
rm krew-linux_${ARCH}.tar.gz
106+
107+
# Install kubeconform
108+
RUN . /envfile && echo $ARCH && \
109+
curl -L https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-${ARCH}.tar.gz -o - | tar xz -C /usr/bin/ && \
110+
chmod +x /usr/bin/kubeconform
111+
112+
WORKDIR /apps
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Make sure jq is installed for this script to work on the runner
6+
# (The workflow will install it)
7+
8+
# 1. helm latest
9+
HELM_VERSION=$(curl -s https://api.github.com/repos/helm/helm/releases | jq -r '.[].tag_name | select([startswith("v"), (contains("-") | not)] | all)' | sort -rV | head -n 1 | sed 's/v//')
10+
echo "HELM_VERSION=$HELM_VERSION"
11+
echo "helm_version=$HELM_VERSION" >> $GITHUB_OUTPUT
12+
13+
# 2. kustomize latest
14+
KUSTOMIZE_RELEASE=$(curl -s https://api.github.com/repos/kubernetes-sigs/kustomize/releases | jq -r '.[].tag_name | select(contains("kustomize"))' | sort -rV | head -n 1)
15+
KUSTOMIZE_VERSION=$(basename ${KUSTOMIZE_RELEASE})
16+
echo "KUSTOMIZE_VERSION=$KUSTOMIZE_VERSION"
17+
echo "kustomize_version=$KUSTOMIZE_VERSION" >> $GITHUB_OUTPUT
18+
19+
# 3. kubeseal latest
20+
KUBESEAL_VERSION=$(curl -s https://api.github.com/repos/bitnami-labs/sealed-secrets/releases | jq -r '.[].tag_name | select(startswith("v"))' | sort -rV | head -n 1 | sed 's/v//')
21+
echo "KUBESEAL_VERSION=$KUBESEAL_VERSION"
22+
echo "kubeseal_version=$KUBESEAL_VERSION" >> $GITHUB_OUTPUT
23+
24+
# 4. krew latest
25+
KREW_VERSION=$(curl -s https://api.github.com/repos/kubernetes-sigs/krew/releases | jq -r '.[].tag_name | select(startswith("v"))' | sort -rV | head -n 1 | sed 's/v//')
26+
echo "KREW_VERSION=$KREW_VERSION"
27+
echo "krew_version=$KREW_VERSION" >> $GITHUB_OUTPUT
28+
29+
# 5. vals latest
30+
VALS_VERSION=$(curl -s https://api.github.com/repos/helmfile/vals/releases | jq -r '.[].tag_name | select(startswith("v"))' | sort -rV | head -n 1 | sed 's/v//')
31+
echo "VALS_VERSION=$VALS_VERSION"
32+
echo "vals_version=$VALS_VERSION" >> $GITHUB_OUTPUT
33+
34+
# 6. kubeconform latest
35+
KUBECONFORM_VERSION=$(curl -s https://api.github.com/repos/yannh/kubeconform/releases | jq -r '.[].tag_name | select(startswith("v"))' | sort -rV | head -n 1 | sed 's/v//')
36+
echo "KUBECONFORM_VERSION=$KUBECONFORM_VERSION"
37+
echo "kubeconform_version=$KUBECONFORM_VERSION" >> $GITHUB_OUTPUT
38+
39+
# 7. Kubectl/K8s tag determination (your complex logic)
40+
# This will be used as the image tag AND as the KUBECTL_VERSION build-arg
41+
# For simplicity, let's just grab the latest stable K8s version
42+
K8S_TAG=$(curl -s https://api.github.com/repos/kubernetes/kubernetes/releases | jq -r '.[].tag_name | select(test("alpha|beta|rc") | not)' | sort -rV | head -n 1 | sed 's/v//')
43+
echo "K8S_TAG=$K8S_TAG"
44+
echo "k8s_tag=$K8S_TAG" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)