Skip to content

Commit b9a7094

Browse files
feat: move to matrix strategy
1 parent 78052f7 commit b9a7094

File tree

3 files changed

+156
-74
lines changed

3 files changed

+156
-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_REPO }}:${{ steps.tags.outputs.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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# --- 1. Find all Static Tool Versions and put them into a single JSON object ---
6+
7+
# Collect all versions into bash variables first
8+
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//')
9+
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)
10+
KUSTOMIZE_VERSION=$(basename ${KUSTOMIZE_RELEASE})
11+
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//')
12+
KREW_VERSION=$(curl -s https://api.com/repos/kubernetes-sigs/krew/releases | jq -r '.[].tag_name | select(startswith("v"))' | sort -rV | head -n 1 | sed 's/v//')
13+
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//')
14+
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//')
15+
16+
17+
# Construct a single JSON object with all static tool versions
18+
# This will be output to the GITHUB_OUTPUT variable 'latest_tools'
19+
LATEST_TOOLS_JSON=$(
20+
jq -n \
21+
--arg helm "$HELM_VERSION" \
22+
--arg kustomize "$KUSTOMIZE_VERSION" \
23+
--arg kubeseal "$KUBESEAL_VERSION" \
24+
--arg krew "$KREW_VERSION" \
25+
--arg vals "$VALS_VERSION" \
26+
--arg kubeconform "$KUBECONFORM_VERSION" \
27+
'{
28+
"helm_version": $helm,
29+
"kustomize_version": $kustomize,
30+
"kubeseal_version": $kubeseal,
31+
"krew_version": $krew,
32+
"vals_version": $vals,
33+
"kubeconform_version": $kubeconform
34+
}'
35+
)
36+
37+
echo "latest_tools=$LATEST_TOOLS_JSON" >> $GITHUB_OUTPUT
38+
echo "Found static tools: $LATEST_TOOLS_JSON"
39+
40+
# --- 2. Find the top 4 latest K8s minor versions and output as a JSON Array ---
41+
42+
# Get the list of all releases tags, excludes alpha, beta, rc tags
43+
RELEASES=$(curl -s https://api.github.com/repos/kubernetes/kubernetes/releases | jq -r '.[].tag_name | select(test("alpha|beta|rc") | not)')
44+
45+
# Logic to extract unique minor versions
46+
MINOR_VERSIONS=()
47+
for RELEASE in $RELEASES; do
48+
# Extract v1.30 or v1.29
49+
MINOR_VERSION=$(echo $RELEASE | awk -F'.' '{print $1"."$2}')
50+
if [[ ! " ${MINOR_VERSIONS[@]} " =~ " ${MINOR_VERSION} " ]]; then
51+
MINOR_VERSIONS+=($MINOR_VERSION)
52+
fi
53+
done
54+
55+
# Sort the unique minor versions in reverse order
56+
SORTED_MINOR_VERSIONS=($(echo "${MINOR_VERSIONS[@]}" | tr ' ' '\n' | sort -rV))
57+
58+
# Loop through the first 4 unique minor versions and get the LATEST PATCH for each
59+
K8S_TAGS=()
60+
# Loop for the first 4 latest minors
61+
for i in $(seq 0 3); do
62+
MINOR_VERSION="${SORTED_MINOR_VERSIONS[$i]}"
63+
# Get the single latest patch version for this minor
64+
LATEST_VERSION=$(echo "$RELEASES" | grep "^$MINOR_VERSION\." | sort -rV | head -1 | sed 's/v//')
65+
K8S_TAGS+=("$LATEST_VERSION")
66+
done
67+
68+
# Convert the bash array into a JSON array string
69+
K8S_TAGS_JSON=$(printf '%s\n' "${K8S_TAGS[@]}" | jq -R . | jq -s .)
70+
71+
echo "k8s_versions=$K8S_TAGS_JSON" >> $GITHUB_OUTPUT
72+
echo "Found K8s versions: ${K8S_TAGS[*]}"

0 commit comments

Comments
 (0)