Skip to content

Commit 91f09c9

Browse files
authored
Publish a private OCI helm chart and images to ghcr (#30)
* Migrate to a more similar build flow to gitopssets * update license * Add missing CRD * Don't generate a configMap of the config.
1 parent c82a3dd commit 91f09c9

File tree

9 files changed

+175
-128
lines changed

9 files changed

+175
-128
lines changed

.github/workflows/build.yaml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- v*
9+
pull_request:
10+
branches:
11+
- main
12+
pull_request_target:
13+
types:
14+
- closed
15+
workflow_dispatch:
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: ${{ github.repository }}
20+
GOPRIVATE: github.com/weaveworks/cluster-controller
21+
22+
jobs:
23+
test:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read # for actions/checkout to fetch code
27+
steps:
28+
- name: Configure git for private modules
29+
env:
30+
GITHUB_BUILD_USERNAME: ${{ secrets.BUILD_BOT_USER }}
31+
GITHUB_BUILD_TOKEN: ${{ secrets.BUILD_BOT_PERSONAL_ACCESS_TOKEN }}
32+
run: git config --global url."https://${GITHUB_BUILD_USERNAME}:${GITHUB_BUILD_TOKEN}@github.com".insteadOf "https://github.com"
33+
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
37+
- name: Setup
38+
uses: actions/setup-go@v3
39+
with:
40+
go-version: 1.20.x
41+
cache: true
42+
43+
- name: Test
44+
run: make test
45+
46+
build:
47+
runs-on: ubuntu-latest
48+
permissions:
49+
contents: read # for actions/checkout to fetch code
50+
packages: write
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v3
54+
with:
55+
fetch-depth: 0 # for git describe
56+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
57+
58+
- name: Get version
59+
id: get_version
60+
run: echo "::set-output name=VERSION::$(make version)"
61+
62+
- name: Log in to the Container registry
63+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
64+
with:
65+
registry: ${{ env.REGISTRY }}
66+
username: ${{ github.actor }}
67+
password: ${{ secrets.GITHUB_TOKEN }}
68+
69+
- name: Extract metadata (tags, labels) for Docker
70+
id: meta
71+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
72+
with:
73+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
74+
75+
- name: Configure git for private modules
76+
env:
77+
GITHUB_BUILD_USERNAME: ${{ secrets.BUILD_BOT_USER }}
78+
GITHUB_BUILD_TOKEN: ${{ secrets.BUILD_BOT_PERSONAL_ACCESS_TOKEN }}
79+
run: git config --global url."https://${GITHUB_BUILD_USERNAME}:${GITHUB_BUILD_TOKEN}@github.com".insteadOf "https://github.com"
80+
81+
- name: go mod vendor
82+
run: go mod vendor
83+
84+
- name: Build and push Docker image
85+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
86+
with:
87+
context: .
88+
push: true
89+
tags: ${{ steps.meta.outputs.tags }}
90+
labels: ${{ steps.meta.outputs.labels }}
91+
build-args: VERSION=${{ steps.get_version.outputs.VERSION }}
92+
93+
build-push-helm-chart:
94+
runs-on: ubuntu-latest
95+
needs: [build, test]
96+
# only run on tag
97+
if: startsWith(github.ref, 'refs/tags/v')
98+
permissions:
99+
contents: read # for actions/checkout to fetch code
100+
packages: write # write a chart
101+
steps:
102+
- name: Checkout
103+
uses: actions/checkout@v3
104+
with:
105+
fetch-depth: 0 # for git describe
106+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
107+
108+
- name: Configure git for private modules
109+
env:
110+
GITHUB_BUILD_USERNAME: ${{ secrets.BUILD_BOT_USER }}
111+
GITHUB_BUILD_TOKEN: ${{ secrets.BUILD_BOT_PERSONAL_ACCESS_TOKEN }}
112+
run: git config --global url."https://${GITHUB_BUILD_USERNAME}:${GITHUB_BUILD_TOKEN}@github.com".insteadOf "https://github.com"
113+
114+
- name: Install Helm
115+
run: |
116+
wget --no-verbose https://get.helm.sh/helm-v3.12.1-linux-amd64.tar.gz
117+
tar -zxvf helm-v3.12.1-linux-amd64.tar.gz
118+
mv linux-amd64/helm /usr/local/bin/helm
119+
helm version
120+
121+
- name: Login to GitHub Container Registry
122+
uses: docker/login-action@v2
123+
with:
124+
registry: ghcr.io
125+
username: ${{ github.actor }}
126+
password: ${{ secrets.GITHUB_TOKEN }}
127+
128+
- name: Build and publish chart
129+
run: |
130+
make publish-helm-chart

.github/workflows/release.yaml

Lines changed: 0 additions & 59 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ testbin/*
1818

1919
!vendor/**/zz_generated.*
2020

21+
vendor/
22+
2123
# editor and IDE paraphernalia
2224
.idea
2325
*.swp

Dockerfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
# Build the manager binary
2-
FROM golang:1.19 as builder
3-
4-
ARG GITHUB_BUILD_USERNAME
5-
ARG GITHUB_BUILD_TOKEN
6-
RUN git config --global url."https://${GITHUB_BUILD_USERNAME}:${GITHUB_BUILD_TOKEN}@github.com".insteadOf "https://github.com"
2+
FROM golang:1.20 as builder
73

84
WORKDIR /workspace
95
# Copy the Go Modules manifests
106
COPY go.mod go.mod
117
COPY go.sum go.sum
12-
# cache deps before building and copying source so that we don't need to re-download as much
13-
# and so that source changes don't invalidate our downloaded layer
14-
RUN go mod download
8+
COPY vendor vendor
159

1610
# Copy the go source
1711
COPY main.go main.go

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ClusterBootstrapController is under the same license and commercial agreement as Weave GitOps Enterprise, and can only be used in conjunction.
2+

Makefile

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
# To re-generate a bundle for another specific version without changing the standard setup, you can:
44
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
55
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6-
VERSION ?= 0.0.1
6+
VERSION ?= $(shell git describe --tags --always)
7+
# Strip off leading `v`: v0.12.0 -> 0.12.0
8+
# Seems to be idiomatic for chart versions: https://helm.sh/docs/topics/charts/#the-chart-file
9+
CHART_VERSION := $(shell echo $(VERSION) | sed 's/^v//')
10+
CHART_REGISTRY ?= ghcr.io/weaveworks/charts
711

812
# CHANNELS define the bundle channels used in the bundle.
913
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
@@ -29,15 +33,16 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
2933
#
3034
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
3135
# weave.works/cluster-bootstrap-controller-bundle:$VERSION and weave.works/cluster-bootstrap-controller-catalog:$VERSION.
32-
IMAGE_TAG_BASE ?= weaveworks/cluster-bootstrap-controller
36+
IMAGE_TAG_BASE ?= ghcr.io/weaveworks/cluster-bootstrap-controller
3337

3438
# BUNDLE_IMG defines the image:tag used for the bundle.
3539
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
3640
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
3741

3842
IMAGE_TAG := $(shell tools/image-tag)
43+
3944
# Image URL to use all building/pushing image targets
40-
IMG ?= $(IMAGE_TAG_BASE):$(IMAGE_TAG)
45+
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
4146
CRD_OPTIONS ?= "crd"
4247
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
4348
ENVTEST_K8S_VERSION = 1.25
@@ -99,11 +104,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
99104
go run ./main.go
100105

101106
docker-build: test ## Build docker image with the manager.
102-
docker build \
103-
--build-arg=GITHUB_BUILD_TOKEN=$(GITHUB_BUILD_TOKEN) \
104-
--build-arg=GITHUB_BUILD_USERNAME=$(GITHUB_BUILD_USERNAME) \
105-
-t ${IMG} . \
106-
107+
docker build -t ${IMG} .
107108

108109
docker-push: ## Push docker image with the manager.
109110
docker push ${IMG}
@@ -130,7 +131,7 @@ controller-gen: ## Download controller-gen locally if necessary.
130131

131132
KUSTOMIZE = $(shell pwd)/bin/kustomize
132133
kustomize: ## Download kustomize locally if necessary.
133-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v4.5.7)
134+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.7)
134135

135136
ENVTEST = $(shell pwd)/bin/setup-envtest
136137
envtest: ## Download envtest-setup locally if necessary.
@@ -218,3 +219,25 @@ controllers/testdata/crds/cluster.x-k8s.io_clusters.yaml: controllers/testdata/c
218219
curl https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/v1.0.0/config/crd/bases/cluster.x-k8s.io_clusters.yaml -o controllers/testdata/crds/cluster.x-k8s.io_clusters.yaml
219220

220221
download-crds: controllers/testdata/crds/cluster.x-k8s.io_clusters.yaml
222+
223+
HELMIFY = $(shell pwd)/bin/helmify
224+
.PHONY: helmify
225+
helmify:
226+
$(call go-get-tool,$(HELMIFY),github.com/arttor/helmify/cmd/[email protected])
227+
228+
.PHONY: helm
229+
helm: manifests kustomize helmify
230+
$(KUSTOMIZE) build config/default | $(HELMIFY) -crd-dir ../weave-gitops-enterprise/charts/cluster-bootstrap-controller
231+
232+
.PHONY: helm-chart
233+
helm-chart: manifests kustomize helmify
234+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
235+
$(KUSTOMIZE) build config/default | $(HELMIFY) -crd-dir charts/cluster-bootstrap-controller
236+
echo "fullnameOverride: cluster-bootstrap" >> charts/cluster-bootstrap-controller/values.yaml
237+
cp LICENSE charts/cluster-bootstrap-controller/LICENSE
238+
helm lint charts/cluster-bootstrap-controller
239+
helm package charts/cluster-bootstrap-controller --app-version $(VERSION) --version $(CHART_VERSION) --destination /tmp/helm-repo
240+
241+
.PHONY: publish-helm-chart
242+
publish-helm-chart: helm-chart
243+
helm push /tmp/helm-repo/cluster-bootstrap-controller-${CHART_VERSION}.tgz oci://${CHART_REGISTRY}

config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# It should be run by config/default
44
resources:
55
- bases/capi.weave.works_clusterbootstrapconfigs.yaml
6+
- bases/capi.weave.works_secretsyncs.yaml
67
#+kubebuilder:scaffold:crdkustomizeresource
78

89
patchesStrategicMerge:

config/manager/kustomization.yaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
resources:
22
- manager.yaml
3-
4-
generatorOptions:
5-
disableNameSuffixHash: true
6-
7-
configMapGenerator:
8-
- name: manager-config
9-
files:
10-
- controller_manager_config.yaml
3+
apiVersion: kustomize.config.k8s.io/v1beta1
4+
kind: Kustomization
5+
images:
6+
- name: controller
7+
newName: ghcr.io/weaveworks/cluster-bootstrap-controller
8+
newTag: latest

0 commit comments

Comments
 (0)