Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add GitHub Actions workflow for building and publishing #241

Merged
merged 3 commits into from
Jan 30, 2025
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
79 changes: 79 additions & 0 deletions .github/workflows/build-push-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build and Publish

on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]

env:
KO_DOCKER_REPO: ghcr.io/${{ github.repository }}/controller

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: Install Dependencies
run: |
go mod download
go install sigs.k8s.io/controller-tools/cmd/[email protected]
go install sigs.k8s.io/kustomize/kustomize/[email protected]
go install github.com/google/ko@latest

- name: Run tests
run: make test WHAT=unit

- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set Release Version
run: |
if [[ $GITHUB_REF == refs/tags/v* ]]; then
# Trim the 'v' prefix from the tag
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
else
echo "RELEASE_VERSION=dev-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
fi

# Build and push image on push to main
- name: Build and Push Image
if: github.event_name != 'pull_request'
run: |
make publish-image

# Build image only on PR
- name: Build Image (PR)
if: github.event_name == 'pull_request'
run: |
make build-image

# Push helm chart only on tag
- name: Package and Push Helm Chart
if: github.ref_type == 'tag'
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
# Use sed compatible with Linux (GitHub Actions runners)
cp ./config/crd/bases/* helm/crds/
sed -i "s/tag: .*/tag: \"${RELEASE_VERSION}\"/" helm/values.yaml
sed -i "s/version: .*/version: ${RELEASE_VERSION}/" helm/Chart.yaml
sed -i "s/appVersion: .*/appVersion: \"${RELEASE_VERSION}\"/" helm/Chart.yaml
helm package helm
HELM_IMAGE=ghcr.io/${{ github.repository }} make publish-helm
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
AWS_REGION ?= us-west-2
RELEASE_VERSION ?= dev-$(shell git rev-parse --short HEAD)
ECR_REPO ?= public.ecr.aws/kro
OCI_REPO ?= ghcr.io/kro-run/kro

CONTROLLER_IMAGE ?= ${ECR_REPO}/controller:${RELEASE_VERSION}
HELM_IMAGE ?= ${ECR_REPO}
KO_DOCKER_REPO ?= ${ECR_REPO}/kro
CONTROLLER_IMAGE ?= ${OCI_REPO}/controller:${RELEASE_VERSION}
HELM_IMAGE ?= ${OCI_REPO}
KO_DOCKER_REPO ?= ${OCI_REPO}/kro

KOCACHE ?= ~/.ko
KO_PUSH ?= true
Expand Down Expand Up @@ -176,13 +176,13 @@ $(CONTROLLER_GEN): $(LOCALBIN)

.PHONY: image
build-image: ## Build the kro controller images using ko build
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) KO_DOCKER_REPO="public.ecr.aws/kro/controller" \
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) \
ko build --bare github.com/kro-run/kro/cmd/controller \
--push=false --tags ${RELEASE_VERSION} --sbom=none

.PHONY: publish
publish-image: ## Publish the kro controller images to ECR
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) KO_DOCKER_REPO="public.ecr.aws/kro/controller" \
publish-image: ## Publish the kro controller images to ghcr.io
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) \
ko publish --bare github.com/kro-run/kro/cmd/controller \
--tags ${RELEASE_VERSION} --sbom=none

Expand Down
2 changes: 1 addition & 1 deletion helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fullnameOverride: ""

image:
# The location of the container image repository
repository: public.ecr.aws/kro/controller
repository: ghcr.io/kro-run/kro/controller
# Image pull policy (IfNotPresent: pull the image only if it is not present locally)
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
Expand Down
4 changes: 2 additions & 2 deletions website/docs/docs/getting-started/01-Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ echo $KRO_VERSION
```
Install kro using Helm
```
helm install kro oci://public.ecr.aws/kro/kro \
helm install kro oci://ghcr.io/kro-run/kro/kro \
--namespace kro \
--create-namespace \
--version=${KRO_VERSION}
Expand Down Expand Up @@ -84,7 +84,7 @@ export KRO_VERSION=<new-version>

Upgrade the controller
```
helm upgrade kro oci://public.ecr.aws/kro/kro \
helm upgrade kro oci://ghcr.io/kro-run/kro/kro \
--namespace kro \
--version=${KRO_VERSION}
```
Expand Down
Loading