custom_act_runner/createHelmYaml.sh
ties 9dd332bfbe
All checks were successful
Build docker container / Build image (push) Successful in 15s
Update createHelmYaml.sh
2024-08-29 13:41:55 +00:00

72 lines
1.7 KiB
Bash

#!/bin/bash
function checkKubeConfig(){
echo "# Check if kubeconfig exists..."
if [[ -n "$KUBECONFIG_DATA" ]]; then
echo "Check if kubeconfig is valid..."
kubectl version
if [ $? -ne 0 ]; then
echo "# Failed to connect to Kubernetes..."
bash createServiceAccount.sh
false
exit 1
fi
else
echo "# No kubeconfig available..."
createServiceAccount.sh
false
exit 1
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 [[ -z "$action" ]]; then
action="print"
fi
echo "# Action: $action"
# if KUBECONFIG_DATA is set
if [[ -n "$KUBECONFIG_DATA" ]]; then
mkdir -p /root/.kube
echo "$KUBECONFIG_DATA" > /root/.kube/config
chmod 600 /root/.kube/config
fi
# Check if the action environment variable is set to 'print'
if [[ "$action" == "print" ]]; then
printHelm
elif [[ "$action" == "deploy" ]]; then
deployHelm
elif [[ "$action" == "helm-deploy" ]]; then
deployHelm
elif [[ "$action" == "package" ]]; then
packageHelm
else
echo "# invalid action"
fi