Skip to content

Commit

Permalink
trying a manual helm chart building approach instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Jan 22, 2024
1 parent e418339 commit 0b1f340
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 7 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Helm
uses: azure/setup-helm@v3
- name: Create Helm Chart
run: make create-helmchart-release
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --release-notes=docs/release_notes/${{ steps.prep.outputs.VERSION }}.md --skip-validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install Helm
uses: azure/setup-helm@v3
- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_RELEASE_NAME_TEMPLATE: "helm-chart-{{ .Version }}"
- name: Build and release the helm charts
run: |
helm registry login ghcr.io -u skarlso -p ${{ secrets.GITHUB_TOKEN }}
helm package --version ${{ steps.prep.outputs.VERSION }} --app-version ${{ steps.prep.outputs.VERSION }} ./output/crd-bootstrap
helm push ${{ github.event.repository.name }}-${{ steps.prep.outputs.VERSION }}.tgz oci://ghcr.io/skarlso/helm
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ archives:
release:
extra_files:
- glob: output/install.yaml
- glob: output/helm_chart.tar.gz
checksum:
name_template: 'checksums.txt'
extra_files:
- glob: output/install.yaml
- glob: output/helm_chart.tar.gz
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi

##@ Build Dependencies

### Creates helm charts
.PHONY: create-helmchart
create-helmchart:
./hack/create_helm_chart.sh "local" "crd-bootstrap"

.PHONY: create-helmchart-release
create-helmchart-release:
./hack/create_helm_chart.sh "release" "crd-bootstrap"

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
Expand Down
88 changes: 88 additions & 0 deletions hack/create_helm_chart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

CONTROLLER="${2}"

check_dependency() {
if ! command -v helm &> /dev/null
then
echo "Helm could not be found. Please install Helm to proceed."
exit
fi
if ! command -v kustomize &> /dev/null
then
echo "kustomize could not be found. Please install kustomize to proceed."
exit
fi
}

create_helm_chart() {
helm create "${1}/${CONTROLLER}"
cd "${1}/${CONTROLLER}" || exit
rm -r templates
mkdir templates
mkdir crds
rm -r charts
rm values.yaml
cd ../helm_temp || exit

case "${1}" in
"helm" )
#mac
split -p "^---$" "install.yaml" "helm_";
;;
"output" )
#ubuntu
csplit "install.yaml" "/^---$/" {*} --prefix "helm_" -q;
;;
* )
exit
;;
esac

rm install.yaml
# Move into crds & templates folders after renaming
HELM_FILES=($(ls ))
for input in "${HELM_FILES[@]}"; do
FILENAME=$(cat "${input}" | grep '^ name: ' | head -1 | sed 's/name: //g' | sed 's/\./_/g' | sed 's/ //g')
TYPE=$(cat "${input}" | grep '^kind: ' | head -1 | sed 's/kind: //g' | sed 's/\./_/g' | tr '[:upper:]' '[:lower:]' | sed 's/ //g')
if grep -q "kind: CustomResourceDefinition" "${input}" ; then
mv ${input} ../${CONTROLLER}/crds/${FILENAME}.yaml
else
mv ${input} ../${CONTROLLER}/templates/${TYPE}_${FILENAME}.yaml
fi
done
cd ..
rm -rf helm_temp
}

create_from_local_resource_manifests() {
echo "Creating from local manifests in the repository"
rm -rf helm
mkdir -p helm
mkdir -p "helm/helm_temp"
kustomize build ./config/default > ./helm/helm_temp/install.yaml

create_helm_chart "helm"
}

create_from_github_release() {
echo "Creating from the release"
mkdir -p "output/helm_temp"
cp ./output/install.yaml ./output/helm_temp/install.yaml
create_helm_chart "output"
tar -czf helm_chart.tar.gz ${CONTROLLER}
}

check_dependency
case "${1}" in
"local" )
create_from_local_resource_manifests
;;
"release" )
create_from_github_release
;;
* )
echo -n "unknown"
exit
;;
esac

0 comments on commit 0b1f340

Please sign in to comment.