forked from bsord/helm-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·86 lines (72 loc) · 2.67 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
set -e
if [ -z "$CHART_FOLDER" ]; then
echo "Chart folder is required but not defined."
exit 1
fi
if [ -z "$REGISTRY_URL" ]; then
echo "Repository url is required but not defined."
exit 1
fi
if [ -z "$REGISTRY_ACCESS_TOKEN" ]; then
if [ -z "$REGISTRY_USERNAME" ] || [ -z "$REGISTRY_PASSWORD" ]; then
echo "Credentials are required, but none defined."
exit 1
fi
fi
if [ "$FORCE" == "1" ] || [ "$FORCE" == "True" ] || [ "$FORCE" == "TRUE" ] || [ "$FORCE" == "true" ]; then
FORCE="-f"
else
FORCE=""
fi
if [ "$UPDATE_DEPENDENCIES" == "1" ] || [ "$UPDATE_DEPENDENCIES" == "True" ] || [ "$UPDATE_DEPENDENCIES" == "TRUE" ] || [ "$UPDATE_DEPENDENCIES" == "true" ]; then
UPDATE_DEPENDENCIES="-u"
else
UPDATE_DEPENDENCIES=""
fi
if [ "$USE_OCI_REGISTRY" == "TRUE" ] || [ "$USE_OCI_REGISTRY" == "true" ]; then
export HELM_EXPERIMENTAL_OCI=1
echo "OCI SPECIFIED, USING HELM OCI FEATURES"
REGISTRY=$(echo "${REGISTRY_URL}" | awk -F[/:] '{print $4}') # Get registry host from url
echo "${REGISTRY_ACCESS_TOKEN}" | helm registry login -u ${REGISTRY_USERNAME} --password-stdin ${REGISTRY} # Authenticate registry
echo "Packaging chart '$CHART_FOLDER'"
PKG_RESPONSE=$(helm package $CHART_FOLDER $UPDATE_DEPENDENCIES) # package chart
echo "$PKG_RESPONSE"
CHART_TAR_GZ=$(basename "$PKG_RESPONSE") # extract tar name from helm package stdout
echo "Pushing chart $CHART_TAR_GZ to '$REGISTRY_URL'"
helm push "$CHART_TAR_GZ" "$REGISTRY_URL"
echo "Successfully pushed chart $CHART_TAR_GZ to '$REGISTRY_URL'"
exit 0
fi
if [ "$REGISTRY_ACCESS_TOKEN" ]; then
echo "Access token is defined, using bearer auth."
REGISTRY_ACCESS_TOKEN="--access-token ${REGISTRY_ACCESS_TOKEN}"
fi
if [ "$REGISTRY_USERNAME" ]; then
echo "Username is defined, using as parameter."
REGISTRY_USERNAME="--username ${REGISTRY_USERNAME}"
fi
if [ "$REGISTRY_PASSWORD" ]; then
echo "Password is defined, using as parameter."
REGISTRY_PASSWORD="--password ${REGISTRY_PASSWORD}"
fi
if [ "$REGISTRY_VERSION" ]; then
echo "Version is defined, using as parameter."
REGISTRY_VERSION="--version ${REGISTRY_VERSION}"
fi
if [ "$REGISTRY_APPVERSION" ]; then
echo "App version is defined, using as parameter."
REGISTRY_APPVERSION="--app-version ${REGISTRY_APPVERSION}"
fi
if [ "$ADD_REPOSITORIES" != "" ]; then
while read addRepositoryArgs;
do
eval $(echo helm repo add $addRepositoryArgs)
done <<< "$ADD_REPOSITORIES"
helm repo update
fi
cd ${CHART_FOLDER}
helm lint .
helm package . ${REGISTRY_APPVERSION} ${REGISTRY_VERSION} ${UPDATE_DEPENDENCIES}
helm inspect chart *.tgz
helm cm-push *.tgz ${REGISTRY_URL} ${REGISTRY_USERNAME} ${REGISTRY_PASSWORD} ${REGISTRY_ACCESS_TOKEN} ${FORCE}