-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
152 lines (143 loc) · 6.44 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Helm Deployment Action
author: DevOps
description: 'Pull a Helm chart from an OCI-compliant repository and save to a local directory. Then deploy to Kubernetes using that chart and a specified values file.'
inputs:
# AWS Authentication
aws-access-key-id:
description: 'AWS Access Key ID to authenticate for deploying to ECR and the desired EKS cluster.'
required: true
aws-secret-access-key:
description: 'AWS Secret Access Key to authenticate for deploying to ECR and the desired EKS cluster.'
required: true
aws-region:
description: 'Region used for ECR login.'
required: false
default: 'us-east-1'
# CDK Configuration
deploy-cdk:
description: 'Determine to deploy CDK or not. Default is "false".'
required: false
default: 'false'
cdk-directory:
description: 'The directory to deploy CDK from. Default is "deploy".'
required: false
default: 'deploy'
# Helm Configuration
release-name:
description: 'Name of Helm Release. This is also used to build the ECR Repo name.'
required: true
helm-base-chart:
description: 'Chart to deploy the service with.'
required: false
default: 'monochart'
helm-target-directory:
description: 'Target directory to save the chart to. This needs to be an empty directory so the chart can be specified automatically. Will save to ./helm-chart/<chart name>.'
required: false
default: './helm-chart/'
helm-chart-version:
description: 'Helm Chart version.'
required: false
helm-namespace:
description: 'Kubernetes Namespace for the deployment. Default will use the same name as the release-name.'
required: false
default: ''
helm-values-file-directory:
description: 'The Director that holds the Helm Values file for the deployment. Default is "./deploy/helm".'
required: false
default: './deploy/helm'
helm-values-file-name:
description: 'The name of the Helm Values file for the Deployment. Default is "values.yaml".'
required: false
default: 'values.yaml'
helm-additional-values:
description: 'Comma seperated string that contains extra values set for helm.'
required: false
helm-additional-args:
description: 'Handles inline options such as atomic, or timeout. By default, atomic is enabled.'
required: false
default: '--atomic --timeout 2m30s'
helm-problems-timeout:
description: 'Number of seconds to wait before checking potential issues (as an integer of seconds). Adding a value enables problem detection.'
required: false
default: '120'
helm-print-template:
description: 'Allowed values are true/false. Determines whether or not to run "helm template" with the specified values. Defaults to true.'
required: false
default: 'true'
runs:
using: "composite"
steps:
- name: Authenticate with AWS
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ inputs.aws-access-key-id }}
aws-secret-access-key: ${{ inputs.aws-secret-access-key }}
aws-region: ${{ inputs.aws-region }}
- name: Extract Branch name and AWS Account ID
id: core-values
shell: bash
run: |
export UNESCAPED_BRANCH_NAME=${GITHUB_REF#refs/heads/}
echo "branch=$(echo ${UNESCAPED_BRANCH_NAME})" >> $GITHUB_OUTPUT
echo "clean-branch=$(echo ${UNESCAPED_BRANCH_NAME} | sed 's/_//g' | tr '[:upper:]' '[:lower:]' | cut -c -38)" >> $GITHUB_OUTPUT
echo "aws-account-id=$(aws sts get-caller-identity --query Account --output text)" >> $GITHUB_OUTPUT
- name: Set Job Values
id: job-values
shell: bash
run: |
if [[ "${{ inputs.helm-base-chart }}" == "monochart" ]]; then
echo "helm-chart=${{ steps.core-values.outputs.aws-account-id }}.dkr.ecr.us-east-1.amazonaws.com/monochart" >> $GITHUB_OUTPUT
else
echo "helm-chart=${{ inputs.helm-base-chart }}" >> $GITHUB_OUTPUT
fi
if [[ "${{ inputs.helm-namespace }}" == "" ]]; then
echo "helm-namespace=${{ inputs.release-name }}" >> $GITHUB_OUTPUT
else
echo "helm-namespace=${{ inputs.helm-namespace }}" >> $GITHUB_OUTPUT
fi
if [[ "${{ steps.core-values.outputs.branch }}" =~ (main|master) ]]; then
echo "release=${{ inputs.release-name }}" >> $GITHUB_OUTPUT
else
echo "release=$(echo ${{ inputs.release-name }}-${{ steps.core-values.outputs.clean-branch }})" >> $GITHUB_OUTPUT
fi
if [ -f ${{ inputs.helm-values-file-directory }}/${{ steps.core-values.outputs.branch }}.${{ inputs.helm-values-file-name }} ]; then
echo "Branch values file found"
echo "values-file=${{ inputs.helm-values-file-directory }}/${{ inputs.helm-values-file-name }},${{ inputs.helm-values-file-directory }}/${{ steps.core-values.outputs.branch }}.${{ inputs.helm-values-file-name }}" >> $GITHUB_OUTPUT;
else
echo "values-file=${{ inputs.helm-values-file-directory }}/${{ inputs.helm-values-file-name }}" >> $GITHUB_OUTPUT;
fi
- name: Login to AWS ECR
id: login-source-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Deploy CDK
if: ${{ inputs.deploy-cdk == 'true' }}
env:
AWS_ACCOUNT_ID: ${{ steps.core-values.outputs.aws-account-id }}
AWS_REGION: ${{ inputs.aws-region }}
BRANCH_NAME: ${{ steps.core-values.outputs.branch }}
BRANCH_DATABASE: ${{ steps.core-values.outputs.branch }}
shell: bash
run: |
cd ${{ inputs.cdk-directory }}
cdk deploy --require-approval never
- name: Pull Helm Chart
id: pull-chart
env:
BASE_CHART: ${{ steps.job-values.outputs.helm-chart }}
CHART_VERSION: ${{ inputs.helm-chart-version }}
TARGET_DIRECTORY: ${{ inputs.helm-target-directory }}
shell: bash
run: ${{ github.action_path }}/helm-chart-pull-action.sh
- name: Install/Upgrade Helm Chart
id: helm-upgrade-action
env:
ADDITIONAL_ARGS: ${{ inputs.helm-additional-args }}
ADDITIONAL_VALUES: ${{ inputs.helm-additional-values }}
HELM_CHART: "${{ steps.pull-chart.outputs.chart-path }}"
NAMESPACE: ${{ steps.job-values.outputs.helm-namespace }}
PRINT_TEMPLATE: ${{ inputs.helm-print-template }}
PROBLEMS_TIMEOUT: ${{ inputs.helm-problems-timeout }}
RELEASE_NAME: ${{ steps.job-values.outputs.release }}
VALUES_FILE: ${{ steps.job-values.outputs.values-file }}
shell: bash
run: ${{ github.action_path }}/helm-upgrade-action.sh