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
11 changes: 11 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,14 @@ jobs:
with:
go-version: v1.26.2
- run: make verify

image-build:
name: image-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: v1.26.2
- uses: docker/setup-buildx-action@v3
- run: make image-local
147 changes: 32 additions & 115 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,143 +26,60 @@ jobs:
- name: Delete non-semver tags
run: 'git tag -d $(git tag -l | grep -v "^v")'

# Set up Docker Buildx for multi-platform builds
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# If you notice signing errors, you may need to update the cosign version.
- uses: sigstore/cosign-installer@v3.7.0


- name: Install Helm
uses: azure/setup-helm@v3
with:
version: 'v3.12.0'

- name: Set LDFLAGS
run: echo LDFLAGS="$(make ldflags)" | tee -a >> $GITHUB_ENV
- name: Compute build env
run: |
{
echo "LDFLAGS=$(make ldflags)"
echo "IMAGE_REPO=ghcr.io/${{ github.repository_owner }}"
echo "IMAGE_TAGS=latest ${{ github.sha }} 0.0.0-${{ github.sha }} ${{ github.ref_name }}"
echo "BUILDX_CACHE_FROM=type=gha"
echo "BUILDX_CACHE_TO=type=gha,mode=max"
echo "COSIGN_ARGS=-a sha=${{ github.sha }} -a ref=${{ github.ref }} -a run_id=${{ github.run_id }} -a run_attempt=${{ github.run_attempt }}"
} >> "$GITHUB_ENV"
# Common OCI labels (one per line so build-image.sh can split on newlines)
{
echo 'IMAGE_LABELS<<EOF'
echo "org.opencontainers.image.source=https://github.com/${{ github.repository }}"
echo "org.opencontainers.image.revision=${{ github.sha }}"
echo "org.opencontainers.image.version=${{ github.ref_name }}"
echo 'EOF'
} >> "$GITHUB_ENV"
# Helm chart version: semver from tag, otherwise 0.0.0-<sha>
if [[ "${{ github.ref_type }}" == "tag" ]]; then
chart_version="${{ github.ref_name }}"
echo "CHART_VERSION=${chart_version#v}" >> "$GITHUB_ENV"
else
echo "CHART_VERSION=0.0.0-${{ github.sha }}" >> "$GITHUB_ENV"
fi

# Login to GitHub Container Registry (used by both ko and Docker)
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push konnector image using Dockerfile.konnector
- name: Build and push konnector image
uses: docker/build-push-action@v6
id: build-konnector
with:
context: .
file: ./Dockerfile.konnector
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/konnector:latest
ghcr.io/${{ github.repository_owner }}/konnector:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/konnector:0.0.0-${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/konnector:${{ github.ref_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
LDFLAGS=${{ env.LDFLAGS }}
labels: |
org.opencontainers.image.title=Kube Bind Konnector
org.opencontainers.image.description=Kube Bind konnector component
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ github.ref_name }}

# Sign the konnector image
- name: Sign konnector image
env:
COSIGN_EXPERIMENTAL: 'true'
run: |
img="ghcr.io/${{ github.repository_owner }}/konnector@${{ steps.build-konnector.outputs.digest }}"
echo "signing ${img}"
cosign sign ${img} \
--yes \
-a sha=${{ github.sha }} \
-a ref=${{ github.ref }} \
-a run_id=${{ github.run_id }} \
-a run_attempt=${{ github.run_attempt }}

# Build and push backend image using Dockerfile (includes frontend)
- name: Build and push backend image
uses: docker/build-push-action@v6
id: build
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/backend:latest
ghcr.io/${{ github.repository_owner }}/backend:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/backend:0.0.0-${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/backend:${{ github.ref_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
LDFLAGS=${{ env.LDFLAGS }}
labels: |
org.opencontainers.image.title=Kube Bind Backend
org.opencontainers.image.description=Kube Bind backend with integrated Vue.js frontend
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ github.ref_name }}

# Sign the backend image
- name: Sign backend image
- name: Login to GHCR for Helm
env:
COSIGN_EXPERIMENTAL: 'true'
run: |
img="ghcr.io/${{ github.repository_owner }}/backend@${{ steps.build.outputs.digest }}"
echo "signing ${img}"
cosign sign ${img} \
--yes \
-a sha=${{ github.sha }} \
-a ref=${{ github.ref }} \
-a run_id=${{ github.run_id }} \
-a run_attempt=${{ github.run_attempt }}

- name: Package and push Helm charts as OCI
env:
HELM_EXPERIMENTAL_OCI: 1
run: |
# Login to GitHub Container Registry for Helm
echo "${{ github.token }}" | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin

# Set chart version - use tag name if available, otherwise use semver format
if [[ "${{ github.ref_type }}" == "tag" ]]; then
CHART_VERSION="${{ github.ref_name }}"
# Remove 'v' prefix if present
CHART_VERSION="${CHART_VERSION#v}"
else
CHART_VERSION="0.0.0-${{ github.sha }}"
fi

# Package and push each chart in deploy/charts/
for chart_dir in deploy/charts/*/; do
if [ -f "${chart_dir}Chart.yaml" ]; then
chart_name=$(basename "$chart_dir")
echo "Processing chart: $chart_name"

# Update chart version and appVersion in Chart.yaml
sed -i "s/^version:.*/version: ${CHART_VERSION}/" "${chart_dir}Chart.yaml"
sed -i "s/^appVersion:.*/appVersion: ${CHART_VERSION}/" "${chart_dir}Chart.yaml"

# Package the chart
helm package "$chart_dir" --version "${CHART_VERSION}"
HELM_EXPERIMENTAL_OCI: '1'
run: echo "${{ github.token }}" | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin

# Push to GitHub Container Registry
helm push "${chart_name}-${CHART_VERSION}.tgz" "oci://ghcr.io/${{ github.repository_owner }}/charts"
- name: Build, push, and sign images
run: make release-images

echo "Helm chart pushed to oci://ghcr.io/${{ github.repository_owner }}/charts/${chart_name}:${CHART_VERSION}"
fi
done
- name: Build and push Helm charts
run: make release-helm

- uses: actions/delete-package-versions@v3
with:
Expand Down
30 changes: 29 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,39 @@ deploy-docs: venv ## Deploy docs
build-web:
cd web && npm run build

# Image / release configuration.
# IMAGE_TAGS is the space-separated list of tag suffixes applied to each component image.
# IMAGE_PUSH_PLATFORMS is the platform list for `image-push` (multi-arch by default).
# CHART_VERSION is the helm chart version; defaults to 0.0.0-$REV.
# IMAGE_METADATA_DIR holds buildx metadata files used by `image-sign`.
export IMAGE_TAGS ?= $(REV)
IMAGE_PUSH_PLATFORMS ?= linux/amd64,linux/arm64
export CHART_VERSION ?= 0.0.0-$(REV)
IMAGE_METADATA_DIR ?= $(BUILD_DIR)/image-metadata

# Example: make IMAGE_REPO=ghcr.io/<username> image-local
# Set PLATFORMS to override default architectures (e.g., make PLATFORMS=linux/amd64,linux/arm64 image-local)
# For local builds, default to current architecture on Linux platform to support --load
.PHONY: image-local
image-local: export PLATFORMS ?= linux/$(shell go env GOARCH)
image-local:
image-local: ## Build images locally (single platform, --load) for the current commit
@LDFLAGS="$(LDFLAGS)" hack/build-image.sh

.PHONY: image-push
image-push: export PLATFORMS = $(IMAGE_PUSH_PLATFORMS)
image-push: export PUSH = true
image-push: export OUTPUT_DIR = $(IMAGE_METADATA_DIR)
image-push: ## Build multi-arch images and push to IMAGE_REPO with all IMAGE_TAGS
@LDFLAGS="$(LDFLAGS)" hack/build-image.sh

.PHONY: image-sign
image-sign: export OUTPUT_DIR = $(IMAGE_METADATA_DIR)
image-sign: ## Cosign-sign pushed images by digest (requires cosign + image-push run first)
@hack/image-sign.sh

.PHONY: release-images
release-images: image-push image-sign ## Build, push, and sign release images

# Kind cluster configuration
KIND_CLUSTER ?= kube-bind
DOCKER_REPO ?= $(IMAGE_REPO)
Expand Down Expand Up @@ -452,6 +477,9 @@ goreleaser-test: install-goreleaser ## Test GoReleaser flow locally
helm-push-local: ## Push Helm charts to IMAGE_REPO registry
@hack/helm-push.sh

.PHONY: release-helm
release-helm: helm-build-local helm-push-local ## Package and push helm charts to IMAGE_REPO

.PHONY: helm-test
helm-test: helm-build-local ## Test Helm chart installation (dry-run)
@hack/helm-test.sh
Expand Down
116 changes: 87 additions & 29 deletions hack/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,98 @@

set -eu

echo "Building images locally with tag $REV for platforms: $PLATFORMS"
# Inputs (env vars):
# IMAGE_REPO registry+namespace, e.g. ghcr.io/kube-bind or kube-bind (required)
# PLATFORMS buildx platform list, default: linux/<host arch>
# IMAGE_TAGS space-separated tag suffixes, default: $REV
# PUSH true|false; default: true if PLATFORMS is multi-arch, else false (--load)
# LDFLAGS go ldflags passed as build-arg
# OUTPUT_DIR if set, write <component>.metadata.json files (used by image-sign.sh)
# BUILDX_CACHE_FROM passed to --cache-from (e.g. type=gha)
# BUILDX_CACHE_TO passed to --cache-to (e.g. type=gha,mode=max)
# IMAGE_LABELS newline- or space-separated key=value labels (applied to both images)

: "${IMAGE_REPO:?IMAGE_REPO must be set}"
: "${PLATFORMS:=linux/$(go env GOARCH)}"
: "${IMAGE_TAGS:=${REV:?REV must be set when IMAGE_TAGS is unset}}"

if [[ -z "${PUSH:-}" ]]; then
if [[ "$PLATFORMS" == *","* ]]; then
PUSH=true
else
PUSH=false
fi
fi

if [[ "$PUSH" == "true" ]]; then
OUTPUT_FLAG="--push"
else
OUTPUT_FLAG="--load"
if [[ "$PLATFORMS" == *","* ]]; then
echo "PUSH=false with multi-platform PLATFORMS=$PLATFORMS will fail (--load only supports a single platform)." >&2
exit 1
fi
fi

command -v docker >/dev/null 2>&1 || { echo "docker not found. Please install Docker"; exit 1; }
docker buildx version >/dev/null 2>&1 || { echo "docker buildx not found. Please enable buildx in Docker"; exit 1; }

# Create buildx builder if it doesn't exist
docker buildx create --name kube-bind-builder --use 2>/dev/null || docker buildx use kube-bind-builder 2>/dev/null || true
# Reuse an existing active builder (e.g. one set up by docker/setup-buildx-action in CI).
# Only create our own if none is active — otherwise we'd lose the GHA cache wiring.
if ! docker buildx inspect >/dev/null 2>&1; then
docker buildx create --name kube-bind-builder --use >/dev/null
fi
docker buildx inspect --bootstrap >/dev/null 2>&1

# Check if building for multiple platforms
if [[ "$PLATFORMS" == *","* ]]; then
echo "Multi-platform build detected. Images will be pushed to registry instead of loaded locally."
LOAD_FLAG="--push"
else
echo "Single platform build. Images will be loaded to local Docker daemon."
LOAD_FLAG="--load"
cache_args=()
if [[ -n "${BUILDX_CACHE_FROM:-}" ]]; then
cache_args+=("--cache-from" "$BUILDX_CACHE_FROM")
fi
if [[ -n "${BUILDX_CACHE_TO:-}" ]]; then
cache_args+=("--cache-to" "$BUILDX_CACHE_TO")
fi

label_args=()
if [[ -n "${IMAGE_LABELS:-}" ]]; then
while IFS= read -r label; do
[[ -z "$label" ]] && continue
label_args+=("--label" "$label")
done <<< "$(echo "$IMAGE_LABELS" | tr ' ' '\n')"
fi

build_image() {
local component="$1"
local dockerfile="$2"

local tag_args=()
for t in $IMAGE_TAGS; do
tag_args+=("-t" "${IMAGE_REPO}/${component}:${t}")
done

local metadata_args=()
if [[ -n "${OUTPUT_DIR:-}" ]]; then
mkdir -p "$OUTPUT_DIR"
metadata_args+=("--metadata-file" "${OUTPUT_DIR}/${component}.metadata.json")
fi

echo "Building ${component} image (platforms: $PLATFORMS, push: $PUSH)..."
docker buildx build \
--platform "$PLATFORMS" \
--build-arg LDFLAGS="${LDFLAGS:-}" \
"${tag_args[@]}" \
"${cache_args[@]}" \
"${label_args[@]}" \
"${metadata_args[@]}" \
-f "$dockerfile" \
$OUTPUT_FLAG .
}

build_image konnector Dockerfile.konnector
build_image backend Dockerfile

echo "Building konnector image..."
docker buildx build \
--platform $PLATFORMS \
--build-arg LDFLAGS="$LDFLAGS" \
-t "$IMAGE_REPO/konnector:$REV" \
-f Dockerfile.konnector \
$LOAD_FLAG .

echo "Building backend image..."
docker buildx build \
--platform $PLATFORMS \
--build-arg LDFLAGS="$LDFLAGS" \
-t "$IMAGE_REPO/backend:$REV" \
-f Dockerfile \
$LOAD_FLAG .

echo "Successfully built images:"
echo " $IMAGE_REPO/konnector:$REV ($PLATFORMS)"
echo " $IMAGE_REPO/backend:$REV ($PLATFORMS)"
echo "Successfully built images on platforms ${PLATFORMS}"
echo "Tags:"
for t in $IMAGE_TAGS; do
echo " ${IMAGE_REPO}/konnector:${t}"
echo " ${IMAGE_REPO}/backend:${t}"
done
11 changes: 7 additions & 4 deletions hack/helm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

set -eu

echo "Building Helm charts locally..."
# Inputs (env vars):
# REV short git sha (required if CHART_VERSION is unset)
# CHART_VERSION chart version string; default: 0.0.0-$REV

HELM="$(UGET_PRINT_PATH=absolute make --no-print-directory install-helm)"
: "${CHART_VERSION:=0.0.0-${REV:?REV must be set when CHART_VERSION is unset}}"

echo "Building Helm charts (version: $CHART_VERSION)..."

# Set chart version to semver format for local builds (0.0.0-<git-sha>)
CHART_VERSION="0.0.0-$REV";
HELM="$(UGET_PRINT_PATH=absolute make --no-print-directory install-helm)"

for chart_dir in deploy/charts/*/; do
if [ -f "${chart_dir}Chart.yaml" ]; then
Expand Down
Loading
Loading