1818 SLACK_ICON : https://files.dataherald.com/random/github-actions.png
1919 SLACK_USERNAME : GitHub Actions
2020 SLACK_CHANNEL : eng-notifications
21+ OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
22+ PINECONE_API_KEY : ${{ secrets.PINECONE_API_KEY }}
2123
2224jobs :
2325 extract-branch-names :
@@ -78,13 +80,13 @@ jobs:
7880 target_env : branch
7981 image_tag : ${{ needs.extract-branch-names.outputs.branch_name}}-${{ github.sha }}
8082
81- deploy-backend-dbs-infra :
82- name : Deploy Backend and DBs infrastructure
83+ deploy-backend :
84+ name : Deploy Backend infrastructure
8385 needs : [extract-branch-names, build-engine, build-server]
8486 runs-on : ubuntu-latest
8587 defaults :
8688 run :
87- working-directory : ./apps/ai/server/terraform
89+ working-directory : ./apps/ai/server/terraform/branch
8890 outputs :
8991 api_url : ${{ steps.get-api-url.outputs.api_url }}
9092 steps :
@@ -105,9 +107,12 @@ jobs:
105107 terraform_wrapper : false
106108 - name : Apply Terraform
107109 env :
108- PINECONE_API_KEY : ${{ secrets.PINECONE_API_KEY }}
109110 TF_VAR_sha : ${{ github.sha }}
110111 TF_VAR_branch_name : ${{ needs.extract-branch-names.outputs.branch_name }}
112+ TF_VAR_vpc_id : ${{ vars.VPC_ID }}
113+ TF_VAR_subnet_1_id : ${{ vars.PRIVATE_SUBNET_1_ID }}
114+ TF_VAR_subnet_2_id : ${{ vars.PRIVATE_SUBNET_2_ID }}
115+ TF_VAR_ecs_security_group_id : ${{ vars.BRANCH_SECURITY_GROUP_ID }}
111116 TF_VAR_pinecone_index_name : ${{ needs.extract-branch-names.outputs.db_name }}
112117 TF_VAR_mongodb_uri : ${{ vars.EPHEMERAL_MONGODB_URI }}
113118 TF_VAR_mongodb_name : ${{ needs.extract-branch-names.outputs.db_name }}
@@ -116,8 +121,8 @@ jobs:
116121
117122 run : |
118123 terraform init -upgrade -backend-config="key=${{ needs.extract-branch-names.outputs.branch_name }}"
119- terraform plan
120- terraform apply -auto-approve
124+ terraform plan -target=module.aws_ecs
125+ terraform apply -target=module.aws_ecs - auto-approve
121126 - name : Get API URL
122127 id : get-api-url
123128 run : |
@@ -135,7 +140,36 @@ jobs:
135140 if [ -n "$UNTAGGED_SERVER_IMAGES" ] && [ "$UNTAGGED_SERVER_IMAGES" != "[]" ]; then
136141 aws ecr batch-delete-image --repository-name $ECR_SERVER_REPOSITORY --image-ids "$UNTAGGED_SERVER_IMAGES" --region us-east-1
137142 fi
138-
143+ create-vector-db :
144+ name : Create PineconeDB
145+ needs : [extract-branch-names]
146+ runs-on : ubuntu-latest
147+ defaults :
148+ run :
149+ working-directory : ./apps/ai/server/terraform/branch
150+ steps :
151+ - name : Check out code
152+ uses : actions/checkout@v4
153+ with :
154+ token : ${{ secrets.GH_ACCESS_TOKEN }}
155+ submodules : true
156+ - name : Configure AWS credentials
157+ uses : aws-actions/configure-aws-credentials@v4
158+ with :
159+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
160+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
161+ aws-region : ${{ vars.AWS_REGION }}
162+ - name : Setup Terraform
163+ uses : hashicorp/setup-terraform@v3
164+ with :
165+ terraform_wrapper : false
166+ - name : Apply Terraform
167+ env :
168+ TF_VAR_pinecone_index_name : ${{ needs.extract-branch-names.outputs.db_name }}
169+ run : |
170+ terraform init -upgrade -backend-config="key=${{ needs.extract-branch-names.outputs.branch_name }}"
171+ terraform plan -target=module.pinecone_index
172+ terraform apply -target=module.pinecone_index -auto-approve
139173 populate-db :
140174 name : Populate MongoDB
141175 needs : [extract-branch-names, start-self-hosted-runner]
@@ -201,7 +235,7 @@ jobs:
201235 extract-branch-names,
202236 start-self-hosted-runner,
203237 populate-db,
204- deploy-backend-dbs-infra ,
238+ create-vector-db ,
205239 ]
206240 runs-on : ${{ needs.start-self-hosted-runner.outputs.label }}
207241 defaults :
@@ -215,8 +249,6 @@ jobs:
215249 submodules : true
216250 - name : Populate PineconeDB
217251 env :
218- OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
219- PINECONE_API_KEY : ${{ secrets.PINECONE_API_KEY }}
220252 PINECONE_INDEX_NAME : ${{ needs.extract-branch-names.outputs.db_name }}
221253 MONGODB_URI : ${{ vars.EPHEMERAL_MONGODB_URI }}
222254 MONGODB_USERNAME : ${{ secrets.MONGODB_USERNAME }}
@@ -231,7 +263,7 @@ jobs:
231263
232264 deploy-frontend :
233265 name : Deploy Frontend
234- needs : [extract-branch-names, deploy-backend-dbs-infra ]
266+ needs : [extract-branch-names, deploy-backend]
235267 runs-on : ubuntu-latest
236268 outputs :
237269 url : ${{ steps.console_dns.outputs.url }}
@@ -252,10 +284,10 @@ jobs:
252284 - name : Deploy to Vercel and set custom domain alias
253285 run : |
254286 echo Deploying to Vercel with the following environment variables:
255- echo "NEXT_PUBLIC_API_URL=${{ needs.deploy-backend-dbs-infra .outputs.api_url }}"
287+ echo "NEXT_PUBLIC_API_URL=${{ needs.deploy-backend.outputs.api_url }}"
256288 echo "AUTH0_BASE_URL=${{ steps.console_dns.outputs.url }}"
257289
258- vercel deploy --yes --build-env NEXT_PUBLIC_API_URL=${{ needs.deploy-backend-dbs-infra .outputs.api_url }} --env AUTH0_BASE_URL=${{ steps.console_dns.outputs.url }} --token=${{ secrets.VERCEL_ACCESS_TOKEN }} >deployment-url.txt 2>error.txt
290+ vercel deploy --yes --build-env NEXT_PUBLIC_API_URL=${{ needs.deploy-backend.outputs.api_url }} --env AUTH0_BASE_URL=${{ steps.console_dns.outputs.url }} --token=${{ secrets.VERCEL_ACCESS_TOKEN }} >deployment-url.txt 2>error.txt
259291
260292 # check the exit code
261293 code=$?
@@ -274,7 +306,7 @@ jobs:
274306 needs :
275307 [
276308 extract-branch-names,
277- deploy-backend-dbs-infra ,
309+ deploy-backend,
278310 populate-db,
279311 populate-vector-db,
280312 deploy-frontend,
@@ -299,12 +331,12 @@ jobs:
299331 needs :
300332 [
301333 extract-branch-names,
302- deploy-backend-dbs-infra ,
334+ deploy-backend,
303335 populate-db,
304336 populate-vector-db,
305337 deploy-frontend,
306338 ]
307- if : needs.deploy-backend-dbs-infra .result == 'failure' || needs.populate-db.result == 'failure' || needs.populate-vector-db.result == 'failure' || needs.deploy-frontend.result == 'failure'
339+ if : needs.deploy-backend.result == 'failure' || needs.populate-db.result == 'failure' || needs.populate-vector-db.result == 'failure' || needs.deploy-frontend.result == 'failure'
308340 runs-on : ubuntu-latest
309341 steps :
310342 - name : Send failed notification
@@ -324,12 +356,12 @@ jobs:
324356 needs :
325357 [
326358 extract-branch-names,
327- deploy-backend-dbs-infra ,
359+ deploy-backend,
328360 populate-db,
329361 populate-vector-db,
330362 deploy-frontend,
331363 ]
332- if : needs.deploy-backend-dbs-infra .result == 'success' && needs.populate-db.result == 'success' && needs.populate-vector-db.result == 'success' && needs.deploy-frontend.result == 'success'
364+ if : needs.deploy-backend.result == 'success' && needs.populate-db.result == 'success' && needs.populate-vector-db.result == 'success' && needs.deploy-frontend.result == 'success'
333365 runs-on : ubuntu-latest
334366 steps :
335367 - name : Send success notification
@@ -341,7 +373,7 @@ jobs:
341373 The branch environment deployment succeeded. Here are the details:
342374
343375 *Branch*: `${{ needs.extract-branch-names.outputs.branch }}`
344- *API URL*: ${{ needs.deploy-backend-dbs-infra .outputs.api_url }}
376+ *API URL*: ${{ needs.deploy-backend.outputs.api_url }}
345377 *Console URL*: ${{ needs.deploy-frontend.outputs.url }}
346378 SLACK_COLOR : success
347379
0 commit comments