Skip to content

Commit 0fb30df

Browse files
feat: move to matrix strategy
1 parent 243ac04 commit 0fb30df

File tree

3 files changed

+151
-74
lines changed

3 files changed

+151
-74
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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_owner }}/eks-toolkit-base
9+
BUILD_CONTEXT: tests/images/toolkit-base/
10+
11+
jobs:
12+
get_versions_job:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
k8s_versions: ${{ steps.determine_versions.outputs.k8s_versions }}
16+
latest_tools: ${{ steps.determine_versions.outputs.latest_tools }}
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
- name: Install jq
22+
run: sudo apt-get update && sudo apt-get install -y jq
23+
24+
- name: Determine K8s Versions and Tool Versions
25+
id: determine_versions
26+
working-directory: ${{ env.BUILD_CONTEXT }}
27+
run: |
28+
chmod +x ./get_versions_matrix.sh # We need a new version of the script
29+
./get_versions_matrix.sh
30+
31+
build_and_push_image:
32+
needs: get_versions_job
33+
runs-on: ubuntu-latest
34+
permissions:
35+
contents: read
36+
packages: write
37+
attestations: write
38+
id-token: write
39+
40+
strategy:
41+
fail-fast: false # Optional: Set to false if you want other builds to finish even if one fails
42+
matrix:
43+
k8s_tag: ${{ fromJson(needs.get_versions_job.outputs.k8s_versions) }}
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
48+
- name: Setup QEMU
49+
uses: docker/setup-qemu-action@v3
50+
51+
- name: Setup docker buildx
52+
uses: docker/setup-buildx-action@v3
53+
54+
- name: Log in to the Container registry
55+
uses: docker/login-action@v3
56+
with:
57+
registry: ${{ env.REGISTRY }}
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Set Image Tag for Matrix Run
62+
id: tags
63+
run: |
64+
# Use the K8s version as the primary tag
65+
echo "tag=${{ matrix.k8s_tag }}" >> $GITHUB_OUTPUT
66+
67+
- name: Build and push Docker image
68+
uses: docker/build-push-action@v6
69+
with:
70+
context: ${{ env.BUILD_CONTEXT }}
71+
platforms: linux/amd64,linux/arm64
72+
push: true
73+
# The tags are set dynamically by the 'Set Image Tag' step
74+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.k8s_tag }}
75+
76+
# Extract the static tool versions from the needs output
77+
build-args: |
78+
KUBECTL_VERSION=${{ matrix.k8s_tag }}
79+
HELM_VERSION=${{ fromJson(needs.get_versions_job.outputs.latest_tools).helm_version }}
80+
KUSTOMIZE_VERSION=${{ fromJson(needs.get_versions_job.outputs.latest_tools).kustomize_version }}
81+
KUBESEAL_VERSION=${{ fromJson(needs.get_versions_job.outputs.latest_tools).kubeseal_version }}
82+
KREW_VERSION=${{ fromJson(needs.get_versions_job.outputs.latest_tools).krew_version }}
83+
VALS_VERSION=${{ fromJson(needs.get_versions_job.outputs.latest_tools).vals_version }}
84+
KUBECONFORM_VERSION=${{ fromJson(needs.get_versions_job.outputs.latest_tools).kubeconform_version }}

.github/workflows/toolkit-base.yaml

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# --- 1. Find all Static Tool Versions (Combined into a single JSON object) ---
6+
7+
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//')
8+
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)
9+
KUSTOMIZE_VERSION=$(basename ${KUSTOMIZE_RELEASE})
10+
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//')
11+
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//')
12+
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//')
13+
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//')
14+
15+
16+
# Construct a single, compacted JSON object without extra spaces
17+
LATEST_TOOLS_JSON=$(
18+
jq -n -c \
19+
--arg helm "$HELM_VERSION" \
20+
--arg kustomize "$KUSTOMIZE_VERSION" \
21+
--arg kubeseal "$KUBESEAL_VERSION" \
22+
--arg krew "$KREW_VERSION" \
23+
--arg vals "$VALS_VERSION" \
24+
--arg kubeconform "$KUBECONFORM_VERSION" \
25+
'{
26+
"helm_version": $helm,
27+
"kustomize_version": $kustomize,
28+
"kubeseal_version": $kubeseal,
29+
"krew_version": $krew,
30+
"vals_version": $vals,
31+
"kubeconform_version": $kubeconform
32+
}'
33+
)
34+
35+
# Use the 'LATEST_TOOLS_JSON' variable directly, ensuring no leading spaces
36+
echo "latest_tools=$LATEST_TOOLS_JSON" >> $GITHUB_OUTPUT
37+
38+
# Optional: Keep the echo for logging, but ONLY to stdout, not GITHUB_OUTPUT
39+
echo "Found static tools: $LATEST_TOOLS_JSON"
40+
41+
42+
# --- 2. Find the top 4 latest K8s minor versions (Output as a JSON Array) ---
43+
44+
RELEASES=$(curl -s https://api.github.com/repos/kubernetes/kubernetes/releases | jq -r '.[].tag_name | select(test("alpha|beta|rc") | not)')
45+
46+
MINOR_VERSIONS=()
47+
for RELEASE in $RELEASES; do
48+
MINOR_VERSION=$(echo $RELEASE | awk -F'.' '{print $1"."$2}')
49+
if [[ ! " ${MINOR_VERSIONS[@]} " =~ " ${MINOR_VERSION} " ]]; then
50+
MINOR_VERSIONS+=($MINOR_VERSION)
51+
fi
52+
done
53+
54+
SORTED_MINOR_VERSIONS=($(echo "${MINOR_VERSIONS[@]}" | tr ' ' '\n' | sort -rV))
55+
56+
K8S_TAGS=()
57+
for i in $(seq 0 3); do
58+
MINOR_VERSION="${SORTED_MINOR_VERSIONS[$i]}"
59+
LATEST_VERSION=$(echo "$RELEASES" | grep "^$MINOR_VERSION\." | sort -rV | head -1 | sed 's/v//')
60+
K8S_TAGS+=("$LATEST_VERSION")
61+
done
62+
63+
# Convert the bash array into a single-line JSON array string (using -c flag for compact output)
64+
K8S_TAGS_JSON=$(printf '%s\n' "${K8S_TAGS[@]}" | jq -R . | jq -s -c .)
65+
66+
echo "k8s_versions=$K8S_TAGS_JSON" >> $GITHUB_OUTPUT
67+
echo "Found K8s versions: ${K8S_TAGS[*]}"

0 commit comments

Comments
 (0)