Kubernetes #165
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Kubernetes | |
on: | |
push: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'The version of Kubernetes to build an image for e.g. v1.28.3' | |
required: true | |
type: string | |
permissions: | |
packages: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Get Kubernetes version | |
id: collect | |
run: |- | |
# Get latest Kubernetes version | |
KUBERNETES_VERSION=${{inputs.version}} | |
if [ -z "$KUBERNETES_VERSION" ]; then | |
KUBERNETES_VERSION=$(curl -s https://registry.hub.docker.com/v2/repositories/rancher/k3s/tags\?name\=k3s1\&page_size\=50 | \ | |
jq -r '.results[].name | select(contains("-rc") | not) | select(endswith("k3s1")) | sub("(?<version>[0-9]+\\.[0-9]+\\.[0-9]+).*";.version)' | \ | |
sort -r | \ | |
head -n 1) | |
CURRENT_VERSION=$(curl --silent --fail -L \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"https://api.github.com/orgs/jumppad-labs/packages/container/kubernetes/versions" | \ | |
jq -r '.[].metadata.container.tags[] | select( . != null )' | \ | |
sort -r | \ | |
head -n 1) | |
fi | |
echo "version=$KUBERNETES_VERSION" >> "$GITHUB_OUTPUT" | |
echo "current=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | |
echo $KUBERNETES_VERSION | |
echo $CURRENT_VERSION | |
- name: Login to GitHub Container Registry | |
if: steps.collect.outputs.version != steps.collect.outputs.current | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up QEMU | |
if: steps.collect.outputs.version != steps.collect.outputs.current | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
if: steps.collect.outputs.version != steps.collect.outputs.current | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push Docker image | |
if: steps.collect.outputs.version != steps.collect.outputs.current | |
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | |
with: | |
context: kubernetes | |
platforms: linux/amd64,linux/arm64 | |
build-args: | | |
KUBERNETES_VERSION=${{steps.collect.outputs.version}} | |
push: true | |
tags: ghcr.io/jumppad-labs/kubernetes:${{steps.collect.outputs.version}} | |
- name: Test built image | |
if: steps.collect.outputs.version != steps.collect.outputs.current | |
run: |- | |
# Install Jumppad | |
curl https://jumppad.dev/install | bash | |
# Test the image | |
jumppad test --tags @Single --var version=${{steps.collect.outputs.version}} ./kubernetes/tests |