-
Notifications
You must be signed in to change notification settings - Fork 3
246 lines (204 loc) · 9.36 KB
/
deploy.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
name: CDK and SAM Deployment
on:
push:
branches: [ "main" ]
paths-ignore:
- '**.png'
- '**.md'
- '**.sh'
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
concurrency: deploy
env:
# https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository
# Create secrets in the repository and they will be pushed to Parameter store, these are required
# If you don't set an API key for square, you can still use ChatGPT by itself
SQUARE_API_KEY: ${{ secrets.SQUARE_API_KEY || 'DISABLED' }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY || 'NEED_TO_SET_THIS' }}
# https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-a-repository
# Create repository variables to override any/all of the below from the defaults
#
CDK_STACK_NAME: ${{ vars.CDK_STACK_NAME || 'chatgpt-square-ivr-cdk' }}
STACK_NAME: ${{ vars.STACK_NAME || 'chatgpt-square-ivr' }}
# The E164 Number to be used when transferring to main number
TRANSFER_NUMBER: ${{ vars.TRANSFER_NUMBER || '+18004444444' }}
# Set to PRODUCTION if you have a real Sqaure Buisness or Leave it as SANDBOX if you just have a dev account
SQUARE_ENVIRONMENT: ${{ vars.SQUARE_ENVIRONMENT || 'SANDBOX' }}
# You can have many locations in Square, need to set to the location you want to query inventory or employees against (required for functions to work)
SQUARE_LOCATION_ID: ${{ vars.SQUARE_LOCATION_ID || 'DISABLED' }}
# https://platform.openai.com/docs/models/overview (requres model with function calling)
OPENAI_MODEL: ${{ vars.OPENAI_MODEL || 'gpt-3.5-turbo-1106' }}
# Polly voices to use for English and Spanish https://docs.aws.amazon.com/polly/latest/dg/ntts-voices-main.html
VOICE_ID_EN: ${{ vars.VOICE_ID_EN || 'Joanna' }}
VOICE_ID_ES: ${{ vars.VOICE_ID_ES || 'Lupe' }}
jobs:
# First we must create all the Chime resources like Voice Connectors, SIP Media Application, SIP Rules, etc.
cdk-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup AWS Credentials
id: aws-creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
# The full role ARN if you are using OIDC
# https://github.com/aws-actions/configure-aws-credentials#oidc
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
# Set up the below secrets if you are not using OIDC and want to use regular keys (best practive is to use just role above with OIDC provider)
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
mask-aws-account-id: true
- name: Add AWS_ACCOUNT_ID to Environment
run: echo "AWS_ACCOUNT_ID=${{ steps.aws-creds.outputs.aws-account-id }}" >> $GITHUB_ENV
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
cache: maven
- name: Install AWS CDK
run: |
# Install latest version of AWS CDK
npm install -g aws-cdk
echo "Node Version: $(node -v)"
echo "CDK Version: $(cdk version)"
- name: Ensure CDK is bootstraped
run: |
cdk bootstrap --ci=true -c accountId=${AWS_ACCOUNT_ID} aws://${AWS_ACCOUNT_ID}/us-east-1
cdk bootstrap --ci=true -c accountId=${AWS_ACCOUNT_ID} aws://${AWS_ACCOUNT_ID}/us-west-2
- name: Add PBX_HOSTNAME to Environment if var is set
if: ${{ vars.PBX_HOSTNAME }}
run: echo "PBX_HOSTNAME=${{ vars.PBX_HOSTNAME }}" >> $GITHUB_ENV
- name: Add CHIME_AREA_CODE to Environment if var is set
if: ${{ vars.CHIME_AREA_CODE }}
run: echo "CHIME_AREA_CODE=${{ vars.CHIME_AREA_CODE }}" >> $GITHUB_ENV
- name: Deploy Stack with CDK
working-directory: ./ChimeCDKProvision
run: |
# Deploy to both regions in parallel
cdk deploy -c accountId=${AWS_ACCOUNT_ID} -c stackName=${CDK_STACK_NAME} -c regionEast=us-east-1 -c regionWest=us-west-2 --concurrency=2 --all --require-approval=never --ci=true
# Now deploy the app into 2 regions at the same time via SAM with matrix job
sam-deploy:
strategy:
matrix:
region: [ us-east-1, us-west-2 ]
runs-on: ubuntu-latest
environment: ${{ matrix.region }}
needs: [cdk-deploy]
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup AWS Credentials
id: aws-creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ matrix.region }}
# The full role ARN if you are using OIDC
# https://github.com/aws-actions/configure-aws-credentials#oidc
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
# Set up the below secrets if you are not using OIDC and want to use regular keys (best practive is to use just role above with OIDC provider)
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
mask-aws-account-id: true
- name: Add AWS_ACCOUNT_ID to Environment
run: echo "AWS_ACCOUNT_ID=${{ steps.aws-creds.outputs.aws-account-id }}" >> $GITHUB_ENV
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
cache: maven
- name: Build/Install Needed Libraries
# Exclude modules that SAM builds so it can use SAM cache and speed deploys
run: >
mvn -B install -DskipTests
--no-transfer-progress
--projects '!ChimeSMA,!ChatGPT,!ChimeCDKProvision'
--projects '!cloud.cleo.chimesma:generate-poly-prompt'
- name: Setup AWS SAM
uses: aws-actions/setup-sam@v2
with:
use-installer: true
- name: Push Square API Key to Parameter store
run: >
aws ssm put-parameter
--name /${STACK_NAME}/SQUARE_API_KEY
--description "Square API Key used for stack ${STACK_NAME}"
--type String
--value ${SQUARE_API_KEY}
--overwrite
- name: Push OpenAI API Key to Parameter store
run: >
aws ssm put-parameter
--name /${STACK_NAME}/OPENAI_API_KEY
--description "OpenAI API Key used for stack ${STACK_NAME}"
--type String
--value ${OPENAI_API_KEY}
--overwrite
- name: Cache SAM Build files
uses: actions/cache@v3
with:
path: .aws-sam
key: ${{ runner.os }}-sam
- name: SAM Build
run: sam build
- name: Does Stack exist
id: stack-exists
continue-on-error: true
run: aws cloudformation describe-stacks --stack-name ${STACK_NAME}
- name: Delete any Custom resource Logs if stack doesn't exist
if: steps.stack-exists.outcome == 'failure'
run: |
aws logs delete-log-group --log-group-name "/aws/lambda/${STACK_NAME}-PromptCopier"
aws logs delete-log-group --log-group-name "/aws/lambda/${STACK_NAME}-PromptCreator"
- name: SAM Deploy
run: >
sam deploy --no-fail-on-empty-changeset --no-confirm-changeset
--region ${{ matrix.region }}
--stack-name ${STACK_NAME}
--parameter-overrides
SQUAREAPIKEY=/${STACK_NAME}/SQUARE_API_KEY
OPENAIAPIKEY=/${STACK_NAME}/OPENAI_API_KEY
SMAID=/${CDK_STACK_NAME}/SMA_ID
VOICECONNECTORARN=/${CDK_STACK_NAME}/VC_ARN
SQUAREENVIRONMENT=${SQUARE_ENVIRONMENT}
SQUARELOCATIONID=${SQUARE_LOCATION_ID}
TRANSFERNUMBER=${TRANSFER_NUMBER}
OPENAIMODEL=${OPENAI_MODEL}
VOICEIDEN=${VOICE_ID_EN}
VOICEIDES=${VOICE_ID_ES}
- name: Update SMA Endpoint
run: |
# The SMA ID is was pushed to param store by the CDK stack
SMA_ID=$(aws ssm get-parameter --name /${CDK_STACK_NAME}/SMA_ID --query Parameter.Value --output text)
# Chime for some reason loses reference to lambda, so always set to dummay and then back to what it should be
TARGET_ENDPOINT=arn:aws:lambda:${{ matrix.region }}:${AWS_ACCOUNT_ID}:function:${STACK_NAME}-ChimeSMA
DUMMY_ENDPOINT=$(aws ssm get-parameter --name /${CDK_STACK_NAME}/LAMBDA_ARN --query Parameter.Value --output text)
aws chime-sdk-voice update-sip-media-application --sip-media-application-id ${SMA_ID} --endpoints LambdaArn=${DUMMY_ENDPOINT}
aws chime-sdk-voice update-sip-media-application --sip-media-application-id ${SMA_ID} --endpoints LambdaArn=${TARGET_ENDPOINT}
# Run a couple tests to make sure ChatGPT is responding and able to make Square calls
run-tests:
if: ${{ vars.RUN_TESTS }}
strategy:
matrix:
region: [ us-east-1, us-west-2 ]
runs-on: ubuntu-latest
environment: "${{ matrix.region }}-tests"
needs: [sam-deploy]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Execute Tests
uses: ./.github/actions/test
with:
region: ${{ matrix.region }}
stack-name: ${{ vars.STACK_NAME || 'chatgpt-square-ivr' }}
aws-role: ${{ secrets.AWS_ROLE_TO_ASSUME }}
session-id: ${{ github.run_id }}-${{ github.run_attempt }}