-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
87 lines (76 loc) · 3.53 KB
/
action.yml
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
87
name: 'Kubernetes Helm Multi-Deploy (No Docker)'
description: "Deploys all helm chart folders inside a 'deployment' folder in the project root."
icon: play
color: green
inputs:
image-tag:
description: "The image tag to use in the deployments."
required: true
k8s-namespace:
description: "Deployment namespace in kubernetes."
required: true
environment-slug:
description: "Short name of deployment environment. Should be like 'dev', 'prod'. Set this if you have a values-<env>.yaml."
required: false
helm-extra-args:
description: "Add additional/custom helm arguments/commands."
required: false
helm-chart-name-prefix:
description: "Add string to prefix helm chart name (eg: dev-)"
required: false
helm-chart-name-suffix:
description: "Add string to suffix helm chart name (eg: -dev)"
required: false
dry-run:
description: "Skip the actual deployment and just show a diff."
required: false
default: false
timeout:
description: "The timeout time for helm operations."
required: false
default: 300s
wait:
description: "Wait for deployment to complete and be healthy before returning (uses helm --wait option)."
required: false
default: false
runs:
using: 'composite'
steps:
- shell: bash
run: |
(kubectl --help &> /dev/null && helm diff version &> /dev/null) || (echo "Please install kubectl, helm, and helm-diff in your runner. Alternatively use one of our docker-based versions of this action: https://github.com/DevOps-Nirvana/" && exit 1)
HELM_IMAGE_TAG=${{ inputs.image-tag }}
HELM_K8S_NAMESPACE=${{ inputs.k8s-namespace }}
HELM_ENVIRONMENT_SLUG=${{ inputs.environment-slug }}
HELM_DRY_RUN=${{ inputs.dry-run }}
HELM_EXTRA_ARGS=${{ inputs.helm-extra-args }}
HELM_TIMEOUT=${{ inputs.timeout }}
HELM_CHART_NAME_PREFIX=${{ inputs.helm-chart-name-prefix }}
HELM_CHART_NAME_SUFFIX=${{ inputs.helm-chart-name-suffix }}
HELM_WAIT=""
if [ "${{ inputs.wait }}" = "true" ]; then
HELM_WAIT="--wait"
fi
cd deployment
# Creating namespace if necessary
kubectl create namespace $HELM_K8S_NAMESPACE || true
# Setup our helm args
export HELM_EXTRA_ARGS="$HELM_EXTRA_ARGS --set image.tag=$HELM_IMAGE_TAG --set global.image.tag=$HELM_IMAGE_TAG --set global.namespace=$HELM_K8S_NAMESPACE";
# Iterate through all our deployments
for CURRENT_HELM_CHART in $(ls -d */ | grep -Evi "helm_value_files|templates" | tr '/' ' '); do
echo "Update our helm chart dependencies"
helm dependency update $CURRENT_HELM_CHART || true
# Discover values files
VALUES_ENV_FILE=`find $CURRENT_HELM_CHART -name values-${HELM_ENVIRONMENT_SLUG}.yaml`
VALUES_FILE_ARGS="-f $CURRENT_HELM_CHART/values.yaml${VALUES_ENV_FILE:+ -f $VALUES_ENV_FILE}"
echo "--- HELM DIFF ---"
helm diff upgrade --allow-unreleased --namespace $HELM_K8S_NAMESPACE $HELM_UPDIFF_EXTRA_ARGS $HELM_CHART_NAME_PREFIX$CURRENT_HELM_CHART$HELM_CHART_NAME_SUFFIX ./$CURRENT_HELM_CHART \
$VALUES_FILE_ARGS \
$HELM_EXTRA_ARGS
if [ "$HELM_DRY_RUN" = "false" ]; then
echo "--- HELM UPGRADE ---"
helm upgrade --install --atomic --timeout $HELM_TIMEOUT $HELM_WAIT --namespace $HELM_K8S_NAMESPACE $HELM_CHART_NAME_PREFIX$CURRENT_HELM_CHART$HELM_CHART_NAME_SUFFIX ./$CURRENT_HELM_CHART \
$VALUES_FILE_ARGS \
$HELM_EXTRA_ARGS;
fi
done