Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: CI

on:
pull_request:
branches:
- master

permissions:
actions: read
contents: read
packages: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
unit-and-integration:
name: Unit and envtest
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run unit and integration tests
run: make test

- name: Check generated artifacts
run: git diff --exit-code

kind-smoke:
name: Kind smoke
runs-on: ubuntu-latest
needs:
- unit-and-integration
env:
KIND_CLUSTER_NAME: infrakube-ci
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
CONTROLLER_IMAGE: ghcr.io/galleybytes/infrakube:0.0.0-${{ github.event.pull_request.head.sha }}
TASK_IMAGE: ghcr.io/galleybytes/infrakube-task:0.0.0-${{ github.event.pull_request.head.sha }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Wait for controller and task builds
env:
GH_TOKEN: ${{ github.token }}
run: |
wait_for_workflow() {
local workflow_file="$1"
local workflow_name="$2"
local status
for attempt in $(seq 1 60); do
status="$(
gh api "/repos/${GITHUB_REPOSITORY}/actions/workflows/${workflow_file}/runs?event=pull_request&head_sha=${PR_HEAD_SHA}&per_page=1" --jq '.workflow_runs | if length == 0 then "missing" else .[0] | "\(.status):\(.conclusion // "")" end'
)"
echo "${workflow_name}: ${status}"
case "${status}" in
completed:success)
return 0
;;
completed:*)
echo "${workflow_name} did not succeed" >&2
return 1
;;
esac
sleep 10
done
echo "Timed out waiting for ${workflow_name}" >&2
return 1
}

wait_for_workflow infrakube-releaser.yaml "controller build"
wait_for_workflow task-releaser.yaml "task build"

- name: Log in to GitHub Container Registry
run: echo "${{ github.token }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin

- name: Pull built images
run: |
for attempt in $(seq 1 30); do
if docker pull "${CONTROLLER_IMAGE}" && docker pull "${TASK_IMAGE}"; then
exit 0
fi
sleep 10
done
exit 1

- name: Set up kubectl
uses: azure/setup-kubectl@v4

- name: Create kind cluster
uses: helm/kind-action@v1.12.0
with:
cluster_name: ${{ env.KIND_CLUSTER_NAME }}

- name: Load images into kind
run: |
kind load docker-image --name "${KIND_CLUSTER_NAME}" "${CONTROLLER_IMAGE}"
kind load docker-image --name "${KIND_CLUSTER_NAME}" "${TASK_IMAGE}"

- name: Run kind smoke test
run: /bin/bash test/e2e/kind-smoke.sh
77 changes: 62 additions & 15 deletions .github/workflows/infrakube-releaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,91 @@ on:
tags:
- 'infrakube-*'

permissions:
contents: read
packages: write

jobs:
infrakube-image-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Get Release Version
- name: Determine image tags
id: meta
run: |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
CACHE_HASH="$(
{
printf '%s\n' build/Dockerfile main.go go.mod go.sum
find build/scripts cmd pkg -type f | sort
} | while IFS= read -r file; do
shasum -a 256 "$file"
done | shasum -a 256 | awk '{print $1}'
)"
CACHE_TAG="0.0.0-buildcache-${CACHE_HASH}"
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
BUILD_SHA="${{ github.event.pull_request.head.sha }}"
{
echo "tags<<EOF"
echo "ghcr.io/galleybytes/infrakube:${CACHE_TAG}"
echo "ghcr.io/galleybytes/infrakube:0.0.0-${BUILD_SHA}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
else
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#infrakube-}
else
VERSION="0.0.0-$(date +%Y%m%d%H%M%S)"
{
echo "tags<<EOF"
echo "ghcr.io/galleybytes/infrakube:${CACHE_TAG}"
echo "ghcr.io/galleybytes/infrakube:latest"
echo "ghcr.io/galleybytes/infrakube:${VERSION}"
echo "ghcr.io/galleybytes/infrakube:0.0.0-${GITHUB_SHA}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "cache_tag=ghcr.io/galleybytes/infrakube:${CACHE_TAG}" >> "$GITHUB_OUTPUT"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set up GitHub Actions cache runtime
uses: crazy-max/ghaction-github-runtime@v3

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin

- name: Determine tags
id: tags
- name: Check cached controller image
id: cache
run: |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
echo "tags=ghcr.io/galleybytes/infrakube:latest,ghcr.io/galleybytes/infrakube:${{ env.VERSION }}" >> $GITHUB_OUTPUT
if docker buildx imagetools inspect "${{ steps.meta.outputs.cache_tag }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "tags=ghcr.io/galleybytes/infrakube:${{ env.VERSION }}" >> $GITHUB_OUTPUT
echo "exists=false" >> "$GITHUB_OUTPUT"
fi

- name: Build & Push multi-architecture images
- name: Reuse cached controller image
if: steps.cache.outputs.exists == 'true'
run: |
create_args=()
while IFS= read -r tag; do
if [[ "${tag}" != "${{ steps.meta.outputs.cache_tag }}" ]]; then
create_args+=(--tag "${tag}")
fi
done <<< "${{ steps.meta.outputs.tags }}"
docker buildx imagetools create "${create_args[@]}" "${{ steps.meta.outputs.cache_tag }}"

- name: Build and push multi-architecture images
if: steps.cache.outputs.exists != 'true'
uses: docker/build-push-action@v5
with:
context: .
file: build/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.tags.outputs.tags }}

tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha,scope=infrakube
cache-to: type=gha,mode=max,scope=infrakube
34 changes: 21 additions & 13 deletions .github/workflows/task-releaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@ on:
pull_request:
branches:
- master
paths:
- 'task-container-build-tools/**'
push:
tags:
- 'task-*'

permissions:
contents: read
packages: write

jobs:
task-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Get Release Version
- name: Determine build tags
run: |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
echo "TFTASK_TAG=0.0.0-${{ github.event.pull_request.head.sha }}" >> "$GITHUB_ENV"
else
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#task-}
else
VERSION="0.0.0-$(date +%Y%m%d%H%M%S)"
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
echo "SHA_TAG=0.0.0-${GITHUB_SHA}" >> "$GITHUB_ENV"
echo "TFTASK_TAG=${VERSION}" >> "$GITHUB_ENV"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -36,21 +40,25 @@ jobs:
- name: Set up GitHub Actions cache runtime
uses: crazy-max/ghaction-github-runtime@v3

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Build & Push
- name: Build and push task image
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TFTASK_TAG: ${{ env.VERSION }}
TFTASK_TAG: ${{ env.TFTASK_TAG }}
TFTASK_PUSH: "true"
TFTASK_CACHE_FROM: type=gha,scope=infrakube-task
TFTASK_CACHE_TO: type=gha,mode=max,scope=infrakube-task
run: |
cd task-container-build-tools
uv run python build-tftask.py

- name: Publish immutable SHA tag
if: github.event_name == 'push'
run: docker buildx imagetools create --tag ghcr.io/galleybytes/infrakube-task:${SHA_TAG} ghcr.io/galleybytes/infrakube-task:${VERSION}


22 changes: 22 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Development

Just a little bit of guidance on how this project is being developed and tested.

## Testing

Infrakube is tested at three levels: focused unit tests for risky logic, envtest-based controller tests for reconcile behavior, and a kind smoke test that runs real Terraform and Tofu workflows on Kubernetes.

| Layer | Command | What it proves |
| --- | --- | --- |
| Unit | `make test-unit` | Custom JSON behavior, task option resolution, pod/job manifest generation, and other high-risk logic that is easy to regress. |
| Controller integration | `make test-integration` | Terraform and Tofu reconcilers create the expected Kubernetes resources in envtest and wire status/stage state correctly. |
| Kind smoke | `make test-e2e` | A real controller plus real task pods can complete tiny Terraform and Tofu workflows on Kubernetes without paid infrastructure. |

The kind fixtures live under `test/e2e/manifests/` and use inline modules plus the Kubernetes backend so the default CI path stays free and secret-free.

## CI

Pull requests targeting `master` trigger three workflows. The controller build publishes `ghcr.io/galleybytes/infrakube:0.0.0-<commit>` and reuses a cached content tag when the controller inputs have not changed. The task build publishes `ghcr.io/galleybytes/infrakube-task:0.0.0-<commit>`. `.github/workflows/ci.yaml` runs `make test`, waits for those two build workflows to finish for the pull request head SHA, and then runs a kind-based Terraform and Tofu smoke test against those exact images.

Release image workflows are tag-driven. `infrakube-*` tags publish the controller image as `latest`, the requested version tag, and an immutable `0.0.0-<commit>` tag. `task-*` tags publish the task image as the requested version tag and an immutable `0.0.0-<commit>` tag. Pushes to `master` do not rerun the full validation pipeline or release builds.

Loading