Skip to content

Commit 1f4142a

Browse files
authored
Merge pull request #241 from a-hilaly/github-in-action
ci: add GitHub Actions workflow for building and publishing
2 parents 6ece1fc + d511295 commit 1f4142a

File tree

4 files changed

+89
-10
lines changed

4 files changed

+89
-10
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Build and Publish
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
env:
11+
KO_DOCKER_REPO: ghcr.io/${{ github.repository }}/controller
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v4
26+
with:
27+
go-version: '1.23'
28+
29+
- name: Install Dependencies
30+
run: |
31+
go mod download
32+
go install sigs.k8s.io/controller-tools/cmd/[email protected]
33+
go install sigs.k8s.io/kustomize/kustomize/[email protected]
34+
go install github.com/google/ko@latest
35+
36+
- name: Run tests
37+
run: make test WHAT=unit
38+
39+
- name: Log in to GitHub Container Registry
40+
if: github.event_name != 'pull_request'
41+
uses: docker/login-action@v3
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Set Release Version
48+
run: |
49+
if [[ $GITHUB_REF == refs/tags/v* ]]; then
50+
# Trim the 'v' prefix from the tag
51+
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
52+
else
53+
echo "RELEASE_VERSION=dev-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
54+
fi
55+
56+
# Build and push image on push to main
57+
- name: Build and Push Image
58+
if: github.event_name != 'pull_request'
59+
run: |
60+
make publish-image
61+
62+
# Build image only on PR
63+
- name: Build Image (PR)
64+
if: github.event_name == 'pull_request'
65+
run: |
66+
make build-image
67+
68+
# Push helm chart only on tag
69+
- name: Package and Push Helm Chart
70+
if: github.ref_type == 'tag'
71+
run: |
72+
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
73+
# Use sed compatible with Linux (GitHub Actions runners)
74+
cp ./config/crd/bases/* helm/crds/
75+
sed -i "s/tag: .*/tag: \"${RELEASE_VERSION}\"/" helm/values.yaml
76+
sed -i "s/version: .*/version: ${RELEASE_VERSION}/" helm/Chart.yaml
77+
sed -i "s/appVersion: .*/appVersion: \"${RELEASE_VERSION}\"/" helm/Chart.yaml
78+
helm package helm
79+
HELM_IMAGE=ghcr.io/${{ github.repository }} make publish-helm

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
33
AWS_REGION ?= us-west-2
44
RELEASE_VERSION ?= dev-$(shell git rev-parse --short HEAD)
5-
ECR_REPO ?= public.ecr.aws/kro
5+
OCI_REPO ?= ghcr.io/kro-run/kro
66

7-
CONTROLLER_IMAGE ?= ${ECR_REPO}/controller:${RELEASE_VERSION}
8-
HELM_IMAGE ?= ${ECR_REPO}
9-
KO_DOCKER_REPO ?= ${ECR_REPO}/kro
7+
CONTROLLER_IMAGE ?= ${OCI_REPO}/controller:${RELEASE_VERSION}
8+
HELM_IMAGE ?= ${OCI_REPO}
9+
KO_DOCKER_REPO ?= ${OCI_REPO}/kro
1010

1111
KOCACHE ?= ~/.ko
1212
KO_PUSH ?= true
@@ -176,13 +176,13 @@ $(CONTROLLER_GEN): $(LOCALBIN)
176176

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

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

helm/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fullnameOverride: ""
55

66
image:
77
# The location of the container image repository
8-
repository: public.ecr.aws/kro/controller
8+
repository: ghcr.io/kro-run/kro/controller
99
# Image pull policy (IfNotPresent: pull the image only if it is not present locally)
1010
pullPolicy: IfNotPresent
1111
# Overrides the image tag whose default is the chart appVersion.

website/docs/docs/getting-started/01-Installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ echo $KRO_VERSION
4040
```
4141
Install kro using Helm
4242
```
43-
helm install kro oci://public.ecr.aws/kro/kro \
43+
helm install kro oci://ghcr.io/kro-run/kro/kro \
4444
--namespace kro \
4545
--create-namespace \
4646
--version=${KRO_VERSION}
@@ -84,7 +84,7 @@ export KRO_VERSION=<new-version>
8484

8585
Upgrade the controller
8686
```
87-
helm upgrade kro oci://public.ecr.aws/kro/kro \
87+
helm upgrade kro oci://ghcr.io/kro-run/kro/kro \
8888
--namespace kro \
8989
--version=${KRO_VERSION}
9090
```

0 commit comments

Comments
 (0)