Update createHelmYaml.sh
All checks were successful
Build docker container / Build image (push) Successful in 15s
All checks were successful
Build docker container / Build image (push) Successful in 15s
This commit is contained in:
parent
e47a77a743
commit
9dd332bfbe
@ -1,48 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Function to create HelmChart YAML
|
|
||||||
createHelmYaml() {
|
|
||||||
# Load values from Chart.yaml
|
|
||||||
chart_version=$(yq -r '.dependencies[0].version' Chart.yaml)
|
|
||||||
chart_name=$(yq -r '.name' Chart.yaml)
|
|
||||||
chart_repo=$(yq -r '.dependencies[0].repository' Chart.yaml)
|
|
||||||
chart_namespace=$(yq -r '.annotations.namespace' Chart.yaml)
|
|
||||||
|
|
||||||
# Check if chart_namespace is empty and default to chart_name if it is
|
|
||||||
if [[ -z "$chart_namespace" ]]; then
|
|
||||||
chart_namespace="$chart_name"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Determine the correct chart and repo values based on chart_repo
|
|
||||||
if [[ $chart_repo == oci://* ]]; then
|
|
||||||
chart="${chart_repo}/${chart_name}"
|
|
||||||
else
|
|
||||||
repo="$chart_repo"
|
|
||||||
chart="$chart_name"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Load the raw content of values.yaml
|
|
||||||
|
|
||||||
values_content=$(cat values.yaml | yq -r ".$chart_name")
|
|
||||||
|
|
||||||
# Create HelmChart content in a variable
|
|
||||||
helm_chart_yaml=$(yq eval -n -r ".apiVersion = \"helm.cattle.io/v1\" |
|
|
||||||
.kind = \"HelmChart\" |
|
|
||||||
.metadata.name = \"$chart_name\" |
|
|
||||||
.metadata.namespace = \"$chart_namespace\" |
|
|
||||||
.spec.chart = \"$chart\" |
|
|
||||||
.spec.version = \"$chart_version\" |
|
|
||||||
.spec.targetNamespace = \"$chart_namespace\" |
|
|
||||||
.spec.valuesContent = \"$values_content\"")
|
|
||||||
|
|
||||||
# If repo is set, add it to the spec
|
|
||||||
if [[ -n "$repo" ]]; then
|
|
||||||
helm_chart_yaml=$(echo "$helm_chart_yaml" | yq eval ".spec.repo = \"$repo\"")
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Print the final YAML to stdout
|
|
||||||
echo "$helm_chart_yaml"
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkKubeConfig(){
|
function checkKubeConfig(){
|
||||||
echo "# Check if kubeconfig exists..."
|
echo "# Check if kubeconfig exists..."
|
||||||
@ -62,7 +19,31 @@ function checkKubeConfig(){
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
function printHelm(){
|
||||||
|
helm dependency build .
|
||||||
|
helm template -g . --set-json="chart_template.subchartData=$(yq '.dependencies[0]' Chart.yaml -ojson | jq -rc)"
|
||||||
|
}
|
||||||
|
|
||||||
|
function deployHelm(){
|
||||||
|
checkKubeConfig
|
||||||
|
printHelm
|
||||||
|
echo "Deploying in 5 seconds..."
|
||||||
|
sleep 5
|
||||||
|
helm template -g --set-json="chart_template.subchartData=$(yq '.dependencies[0]' Chart.yaml -ojson | jq -rc)" . | kubectl apply -f -
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function packageHelm(){
|
||||||
|
if [[ -z "$REPO_SECRET" ]]; then
|
||||||
|
echo "No credentials..."
|
||||||
|
false
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
helm package .
|
||||||
|
helmPackage="$(yq '.name' Chart.yaml)-$(yq '.version' Chart.yaml)"
|
||||||
|
curl --user "$REPO_SECRET" -X POST --upload-file ./chart_template-0.0.2.tgz https://git.ties.one/api/packages/public/helm/api/charts
|
||||||
|
|
||||||
|
}
|
||||||
# if actions is not set
|
# if actions is not set
|
||||||
if [[ -z "$action" ]]; then
|
if [[ -z "$action" ]]; then
|
||||||
action="print"
|
action="print"
|
||||||
@ -78,20 +59,13 @@ fi
|
|||||||
|
|
||||||
# Check if the action environment variable is set to 'print'
|
# Check if the action environment variable is set to 'print'
|
||||||
if [[ "$action" == "print" ]]; then
|
if [[ "$action" == "print" ]]; then
|
||||||
createHelmYaml
|
printHelm
|
||||||
elif [[ "$action" == "deploy" ]]; then
|
elif [[ "$action" == "deploy" ]]; then
|
||||||
checkKubeConfig
|
deployHelm
|
||||||
createHelmYaml | kubectl apply -f -
|
|
||||||
elif [[ "$action" == "helm-print" ]]; then
|
|
||||||
helm dependency build .
|
|
||||||
helm template -g . --set-json="chart_template.subchartData=$(yq '.dependencies[0]' Chart.yaml -ojson | jq -rc)"
|
|
||||||
elif [[ "$action" == "helm-deploy" ]]; then
|
elif [[ "$action" == "helm-deploy" ]]; then
|
||||||
checkKubeConfig
|
deployHelm
|
||||||
helm dependency build .
|
elif [[ "$action" == "package" ]]; then
|
||||||
helm template -g --set-json="chart_template.subchartData=$(yq '.dependencies[0]' Chart.yaml -ojson | jq -rc)" .
|
packageHelm
|
||||||
echo "Deploying in 5 seconds..."
|
|
||||||
sleep 5
|
|
||||||
helm template -g --set-json="chart_template.subchartData=$(yq '.dependencies[0]' Chart.yaml -ojson | jq -rc)" . | kubectl apply -f -
|
|
||||||
else
|
else
|
||||||
echo "# invalid action"
|
echo "# invalid action"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user