diff --git a/Dockerfile b/Dockerfile index d5c05dd..2b8ce61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM alpine:3 -RUN apk add --update --no-cache bash ca-certificates curl git jq openssh +RUN apk add --update --no-cache bash ca-certificates curl git jq openssh tar lastversion RUN ["bin/sh", "-c", "mkdir -p /src"] COPY ["src", "/src/"] ENTRYPOINT ["/src/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 64c2896..7ba3aaa 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Inputs configure Kustomize GitHub Actions to perform build action. * `kustomize_output_file` - (Optional) Path to to file to write the kustomize build output to. * `kustomize_build_options` - (Optional) Provide build options to kustomize build. * `enable_alpha_plugins` - (Optional) Enable Kustomize plugins. Defaults to `false`. +* `helm_version` - (Optional) The helm version to install and use for `kustomize build --enable-helm` ## Outputs diff --git a/action.yml b/action.yml index edb0839..00bb528 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,10 @@ inputs: description: 'Enable Kustomize plugins' required: false default: '0' + helm_version: + description: 'Specify the version of helm to use (also passes --enable-helm)' + required: false + default: '' token: description: 'GitHub Token for Authentication to Github API (mainly for limit avoidance)' required: false diff --git a/src/entrypoint.sh b/src/entrypoint.sh index fda7037..0c105bc 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -37,10 +37,21 @@ function parse_inputs { enable_alpha_plugins="" if [ "${INPUT_ENABLE_ALPHA_PLUGINS}" == "1" ] || [ "${INPUT_ENABLE_ALPHA_PLUGINS}" == "true" ]; then - enable_alpha_plugins="--enable_alpha_plugins" + if lastversion "${kustomize_version}" --newer-than "4.0.0"; then + enable_alpha_plugins="--enable-alpha-plugins" + else + enable_alpha_plugins="--enable_alpha_plugins" + fi + fi + + enable_helm="" + helm_version="" + if [ -n "${INPUT_HELM_VERSION}" ]; then + enable_helm="--enable-helm" + helm_version=${INPUT_HELM_VERSION} fi - with_token="" + with_token=() if [ "${INPUT_TOKEN}" != "" ]; then with_token=(-H "Authorization: token ${INPUT_TOKEN}") fi @@ -86,18 +97,37 @@ function install_kustomize { } +function install_helm { + url="https://get.helm.sh/helm-v${helm_version}-linux-amd64.tar.gz" + + + echo "Downloading helm v${helm_version}" + curl --retry 30 --retry-max-time 120 -s -S -L ${url} | tar -xzv -C /usr/bin --strip-components=1 --wildcards 'linux-*/helm' + if [ "${?}" -ne 0 ]; then + echo "Failed to download helm v${helm_version}." + exit 1 + fi + echo "Successfully downloaded helm v${helm_version}." + + echo "Allowing execute privilege to helm." + chmod +x /usr/bin/helm + if [ "${?}" -ne 0 ]; then + echo "Failed to update helm privilege." + exit 1 + fi + echo "Successfully added execute privilege to helm." +} + function main { scriptDir=$(dirname ${0}) source ${scriptDir}/kustomize_build.sh parse_inputs - if [ "${kustomize_install}" == "1" ]; then - install_kustomize - fi + [ "${kustomize_install}" == "1" ] && install_kustomize + [ -n "${helm_version}" ] && install_helm kustomize_build - } main "${*}" diff --git a/src/kustomize_build.sh b/src/kustomize_build.sh index e3cebe2..b8b86a1 100755 --- a/src/kustomize_build.sh +++ b/src/kustomize_build.sh @@ -4,7 +4,7 @@ function kustomize_build { # gather output echo "build: info: kustomize build in directory ${kustomize_build_dir}." - build_output=$(kustomize build ${enable_alpha_plugins} ${kustomize_build_options} ${kustomize_build_dir} 2>&1) + build_output=$(kustomize build ${enable_alpha_plugins} ${enable_helm} ${kustomize_build_options} ${kustomize_build_dir} 2>&1) build_exit_code=${?}