-
Notifications
You must be signed in to change notification settings - Fork 4
204 lines (185 loc) · 7.31 KB
/
software_deployment.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# This is a basic workflow to help you get started with Actions
name: Software Deployment Redux
# Controls when the workflow will run
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
branches: [ main ]
inputs:
distinct_id:
deploymentProject:
description: 'Deployment Project'
required: true
type: choice
default: 'UNITY'
options:
- UNITY
- SIPS
deploymentStage:
description: 'Deployment Target'
required: true
type: choice
default: 'DEV'
options:
- DEV
- TEST
- OPS
- SIPS
deploymentOwner:
description: 'Deployment Owner'
required: true
type: string
default: 'nightly'
deploymentName:
descrition: 'Unique Deployment Name'
required: true
type: string
sourceRepository:
description: 'Service Area Repository'
required: true
type: string
default: 'unity-sds/unity-sps-prototype'
sourceBranch:
description: 'Repository Branch'
required: true
type: string
default: 'main'
eksClusterName:
description: 'EKS Cluster Name'
required: true
type: string
default: 'testtommon6'
awsConnection:
description: 'Method of AWS connection'
required: true
type: choice
default: 'oidc'
options:
- oidc
- keys
- iam
deploymentSource:
description: 'Where the action is being run'
required: true
type: choice
default: 'github'
options:
- github
- act
teardown:
description: 'Teardown software deployment'
required: false
type: boolean
default: false
permissions:
id-token: write # required to use OIDC authentication
contents: read # required to checkout the code from the repo
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "deployment"
deployment:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: SCM CHeckout
uses: actions/checkout@v2
- name: install tools github
if: ${{ inputs.deploymentSource == 'github' }}
run: ./utils/install_utils.sh
- name: install tools act
if: ${{ inputs.deploymentSource == 'act' }}
run: ./utils/install_utils.sh true
- name: echo distinct ID ${{ github.event.inputs.distinct_id }}
run: echo ${{ github.event.inputs.distinct_id }}
- name: Configure default variables
env:
DEFAULT_TARGET: 'mcp'
DEFAULT_REPO: 'unity-sds/unity-cs-sps-demo'
DEFAULT_COMMIT: 'smolenski_tf_test_mcp'
DEFAULT_STAGE: 'DEV'
DEFAULT_PROJECT: 'UNITY'
DEFAULT_OWNER: 'nightly'
DEFAULT_EKSCLUSTERNAME: 'testtommon6'
run: |
echo "TARGET_ENV=${{ github.event.inputs.deploymentTarget || env.DEFAULT_TARGET }}" >> $GITHUB_ENV
echo "TARGET_STAGE=${{ github.event.inputs.deploymentStage || env.DEFAULT_STAGE }}" >> $GITHUB_ENV
echo "REPO_NAME=${{ github.event.inputs.sourceRepository || env.DEFAULT_REPO }}" >> $GITHUB_ENV
echo "COMMIT_HASH=${{ github.event.inputs.sourceBranch || env.DEFAULT_COMMIT }}" >> $GITHUB_ENV
echo "TARGET_PROJECT=${{ github.event.inputs.deploymentProject || env.DEFAULT_PROJECT }}" >> $GITHUB_ENV
echo "TARGET_OWNER=${{ github.event.inputs.deploymentOwner || env.DEFAULT_OWNER }}" >> $GITHUB_ENV
echo "TARGET_CLUSTER=${{ github.event.inputs.eksClusterName || env.DEFAULT_EKSCLUSTERNAME }}" >> $GITHUB_ENV
echo "TARGET_NAME=${{ github.event.inputs.deploymentName || env.DEFAULT_NAME }}" >> $GITHUB_ENV
- name: Configure token
if: ${{ inputs.deploymentSource == 'act' }}
run: echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Display deployment configuration
run :
echo "Target ENV ${{ env.TARGET_ENV }}"
echo "Target STAGE ${{ env.TARGET_STAGE }}"
echo "Target PROJECT ${{ env.TARGET_PROJECT }}"
echo "Target OWNER ${{ env.TARGET_OWNER }}"
echo "Target EKS Cluster ${{ env.TARGET_CLUSTER }}"
echo "Repo Name ${{ env.REPO_NAME }}"
echo "Commit Hash ${{ env.COMMIT_HASH }}"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
if: ${{ inputs.awsConnection == 'oidc' }}
with:
role-to-assume: ${{ secrets[format('OIDC_{0}_ROLE', env.TARGET_STAGE)] }}
aws-region: ${{ vars.AWS_REGION }}
- name: Get AWS Caller Identity
run: aws sts get-caller-identity
- name: Temporary Connect to EKS
run: |
aws eks --region us-west-2 update-kubeconfig --name ${{ env.TARGET_CLUSTER }} && \
kubectl version
# Checks-out the repo to deploy
# While cloning the repository:
# - it clones the repo into the given `path`
# - it checks out the branch defined at `ref`
- name: Clone the service repository for deployment github
uses: actions/checkout@v3
if: ${{ inputs.deploymentSource == 'github' }}
with:
repository: ${{ env.REPO_NAME }}
path: resources/deployable
ref: ${{ env.COMMIT_HASH }}
- name: Clone the service repository for deployment act
uses: actions/checkout@v3
if: ${{ inputs.deploymentSource == 'act' }}
with:
repository: ${{ env.REPO_NAME }}
path: resources/deployable
ref: ${{ env.COMMIT_HASH }}
token: ${{ env.GITHUB_TOKEN }}
- name: Configure app for install
run: |
echo 'eks_cluster_name = "${{ env.TARGET_CLUSTER }}"' >> resources/deployable/terraform-unity/gh_actions.tfvars
echo 'kubeconfig_filepath = "~/.kube/config"' >> resources/deployable/terraform-unity/gh_actions.tfvars
echo 'deployment_name = "${{ env.TARGET_NAME }}"' >> resources/deployable/terraform-unity/gh_actions.tfvars
echo 'release = "${{ env.COMMIT_HASH }}"' >> resources/deployable/terraform-unity/gh_actions.tfvars
- name: Run Terraform scripts apply
if: "${{ ! inputs.teardown }}"
run: |
./utils/run_terraform.sh resources/deployable/terraform-unity apply
- name: Run Terraform scripts destroy
if: ${{ inputs.teardown }}
run: |
./utils/run_terraform.sh resources/deployable/terraform-unity destroy
- name: Send custom JSON data to Slack workflow
id: slack
if: always()
uses: slackapi/[email protected]
with:
# This data can be any valid JSON from a previous step in the GitHub Action
payload: |
{
"status": "Smoke Test Exists = ${{ steps.smoke_test_file.outputs.files_exists }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_CI_DEPLOY }}
# - name: Negative Smoke Test Check
# run: |
# cd ./resources/deployable/smoketest
# sh smokefail.sh