Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ The following inputs are available as `step.with` keys:
| `action` | String | Determines if we `install`/`uninstall` the chart, or `list`. (Optional, Defaults to `install`) |
| `dry-run` | Boolean | Toggles `dry-run` option for `install`/`uninstall` action. (Defaults to `false`) |
| `config-files` | String | Comma separated list of helm values files. |
| `namespace` | String | Kubernetes namespace to use. To create the namespace if it doesn't exist, also set `create-namespace` to `true`. |
| `create-namespace` | Boolean | Adds `--create-namespace` when set to `true`. Requires cluster API permissions. (Default: `true`) |
| `namespace` | String | Kubernetes namespace to use. To create the namespace if it doesn't exist, also set `create-namespace` to `true`. |
| `create-namespace` | Boolean | Adds `--create-namespace` when set to `true`. Requires cluster API permissions. (Default: `true`) |
| `values` | String | Comma separated list of value set for helms. e.x: `key1=value1, key2=value2` |
| `name` | String | The name of the helm release. |
| `chart-path` | String | The path to the chart. (defaults to `helm/`) |
Expand All @@ -67,7 +67,9 @@ The following inputs are available as `step.with` keys:
| `username` | String | Chart repository username where to locate the requested chart. |
| `password` | String | Chart repository password where to locate the requested chart. |
| `use-secrets-vals` | Boolean | Use secrets plugin using vals to evaluate the secrets |
| `helm-extra-args` | String | Append any string containing any extra option that might escape the ones present in this action.
| `helm-extra-args` | String | Append any string containing any extra option that might escape the ones present in this action. |
| `log-diff` | Boolean | Outputs the diff of changes for `install` action. (Defaults to `false`) |
| `debug` | Boolean | Turns on debug mode (Defaults to `false`) |

## Example 1 - local repo chart

Expand Down
15 changes: 13 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ inputs:
dry-run:
description: 'Toggles dry-run flag for install/uninstall actions'
required: false
default: false
default: "false"
chart-path:
description: 'The path of the chart.'
required: false
Expand Down Expand Up @@ -99,6 +99,15 @@ inputs:
helm-extra-args:
description: 'Append any string containing any extra option that might escape the ones present in this action.'
required: false
log-diff:
description: 'Log the diff of the helm chart before applying it, only works with install action.'
required: false
default: "false"
debug:
description: 'Turns on debug mode.'
required: false
default: "false"

runs:
using: 'docker'
image: 'Dockerfile'
Expand Down Expand Up @@ -131,4 +140,6 @@ runs:
REPO_PASSWORD: ${{ inputs.password }}
VERSION: ${{ inputs.version }}
USE_SECRETS_VALS: ${{ inputs.use-secrets-vals }}
HELM_EXTRA_ARGS: ${{ inputs.helm-extra-args }}
HELM_EXTRA_ARGS: ${{ inputs.helm-extra-args }}
LOG_DIFF: ${{ inputs.log-diff }}
DEBUG: ${{ inputs.debug }}
35 changes: 31 additions & 4 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ fi
if [ "${HELM_ACTION}" == "install" ]; then

if [ -n "${USE_SECRETS_VALS}" ]; then
HELM_COMMAND="helm secrets --backend vals --evaluate-templates true upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}"
HELM_COMMAND="helm secrets --backend vals --evaluate-templates true upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}"
else
# Upgrade or install the chart. This does it all.
HELM_COMMAND="helm upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}"
HELM_COMMAND="helm upgrade --install --timeout ${TIMEOUT} ${HELM_AUTH}"
fi

HELM_TEMPLATE_COMMAND="helm template --is-upgrade --timeout ${TIMEOUT} ${HELM_AUTH}"

# If we should wait, then do so
if [ -n "${HELM_WAIT}" ]; then
HELM_COMMAND="${HELM_COMMAND} --wait"
Expand All @@ -145,6 +147,7 @@ if [ "${HELM_ACTION}" == "install" ]; then
for config_file in ${DEPLOY_CONFIG_FILES//,/ }
do
HELM_COMMAND="${HELM_COMMAND} -f ${config_file}"
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} -f ${config_file}"
done

if [ -n "$DEPLOY_VALUES" ]; then
Expand All @@ -161,21 +164,29 @@ if [ "${HELM_ACTION}" == "install" ]; then
continue
fi
HELM_COMMAND="${HELM_COMMAND} --set ${value}"
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --set ${value}"
done
fi

if [ -n "$VERSION" ]; then
HELM_COMMAND="${HELM_COMMAND} --version ${VERSION}"
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --version ${VERSION}"
fi

if [ "${UPDATE_DEPS}" == "true" ]; then
HELM_COMMAND="${HELM_COMMAND} --dependency-update"
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --dependency-update"
fi

if [ "${DRY_RUN}" == "true" ]; then
HELM_COMMAND="${HELM_COMMAND} --dry-run"
fi

if [ "${DEBUG}" == "true" ]; then
HELM_COMMAND="${HELM_COMMAND} --debug"
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --debug"
fi

elif [ "${HELM_ACTION}" == "uninstall" ]; then
HELM_COMMAND="helm uninstall --timeout ${TIMEOUT}"

Expand All @@ -190,8 +201,12 @@ else
exit 2
fi

KUBECTL_DIFF_COMMAND="kubectl"

if [ -n "$DEPLOY_NAMESPACE" ]; then
HELM_COMMAND="${HELM_COMMAND} -n ${DEPLOY_NAMESPACE}"
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} -n ${DEPLOY_NAMESPACE}"
KUBECTL_DIFF_COMMAND="${KUBECTL_DIFF_COMMAND} -n ${DEPLOY_NAMESPACE}"
fi

# Create namespace if it doesn't exist. Requires cluster API permissions.
Expand All @@ -210,6 +225,7 @@ fi

# Execute Commands
HELM_COMMAND="${HELM_COMMAND} ${DEPLOY_NAME}"
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} ${DEPLOY_NAME}"

if [ "${HELM_ACTION}" == "install" ]; then
if [ "${OCI_REGISTRY}" == "true" ]; then
Expand All @@ -220,7 +236,18 @@ if [ "${HELM_ACTION}" == "install" ]; then
fi
fi
HELM_COMMAND="${HELM_COMMAND} ${DEPLOY_CHART_PATH}"
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} ${DEPLOY_CHART_PATH}"
fi

HELM_COMMAND="${HELM_COMMAND} ${HELM_EXTRA_ARGS}"
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} ${HELM_EXTRA_ARGS}"

if [ "${LOG_DIFF}" == "true" ] && [ "${HELM_ACTION}" == "install" ]; then
HELM_TEMPLATE_COMMAND="${HELM_TEMPLATE_COMMAND} --dry-run --skip-tests"
KUBECTL_DIFF_COMMAND="${KUBECTL_DIFF_COMMAND} diff --server-side=false"
echo "Diffing before applying: ${HELM_TEMPLATE_COMMAND} | ${KUBECTL_DIFF_COMMAND} -f -"
${HELM_TEMPLATE_COMMAND} | ${KUBECTL_DIFF_COMMAND} -f - || true # Ignore kubectl diff exit code
fi

echo "Executing: ${HELM_COMMAND} ${HELM_EXTRA_ARGS}"
${HELM_COMMAND} ${HELM_EXTRA_ARGS}
echo "Executing: ${HELM_COMMAND}"
${HELM_COMMAND}