-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CAI-252] Chatbot/deploy workflow #1231
Closed
Closed
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e7b8ac9
chore(chatbot): Define IAM Role to use on chatbot deploy
batdevis 4dd8373
chore(chatbot): deploy workflow pipeline
batdevis 378fe4d
fix(chatbot): dockerfile
batdevis 732f654
Merge branch 'main' into chatbot/deploy-workflow
batdevis cc8dc4b
fix(chatbot): update lambda image
batdevis e288b07
chore: policy
batdevis f3501e7
Merge branch 'main' into chatbot/deploy-workflow
batdevis f74b717
chore: terraform fmt
batdevis db71dc4
Merge branch 'main' into chatbot/deploy-workflow
batdevis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,174 @@ | ||||||||||||||||||||||||||||||||||||||
name: Deploy Chatbot | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
on: | ||||||||||||||||||||||||||||||||||||||
push: | ||||||||||||||||||||||||||||||||||||||
branches: ['main'] | ||||||||||||||||||||||||||||||||||||||
# Run only if there are at least one change matching the following paths | ||||||||||||||||||||||||||||||||||||||
paths: | ||||||||||||||||||||||||||||||||||||||
- 'apps/chatbot/**' | ||||||||||||||||||||||||||||||||||||||
- '.github/workflows/deploy_chatbot.yaml' | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
workflow_dispatch: | ||||||||||||||||||||||||||||||||||||||
inputs: | ||||||||||||||||||||||||||||||||||||||
environment: | ||||||||||||||||||||||||||||||||||||||
description: 'The environment used as target' | ||||||||||||||||||||||||||||||||||||||
type: choice | ||||||||||||||||||||||||||||||||||||||
required: true | ||||||||||||||||||||||||||||||||||||||
default: dev | ||||||||||||||||||||||||||||||||||||||
options: | ||||||||||||||||||||||||||||||||||||||
- dev | ||||||||||||||||||||||||||||||||||||||
- prod | ||||||||||||||||||||||||||||||||||||||
logLevel: | ||||||||||||||||||||||||||||||||||||||
description: 'Log level' | ||||||||||||||||||||||||||||||||||||||
required: true | ||||||||||||||||||||||||||||||||||||||
default: 'warning' | ||||||||||||||||||||||||||||||||||||||
type: choice | ||||||||||||||||||||||||||||||||||||||
options: | ||||||||||||||||||||||||||||||||||||||
- warning | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
defaults: | ||||||||||||||||||||||||||||||||||||||
run: | ||||||||||||||||||||||||||||||||||||||
shell: bash | ||||||||||||||||||||||||||||||||||||||
working-directory: apps/chatbot | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
permissions: | ||||||||||||||||||||||||||||||||||||||
id-token: write # This is required for requesting the JWT | ||||||||||||||||||||||||||||||||||||||
contents: read # This is required for actions/checkout | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
jobs: | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
cd_deploy_chatbot: | ||||||||||||||||||||||||||||||||||||||
name: Build and push Chatbot API lambda image (on ${{ matrix.environment }}) | ||||||||||||||||||||||||||||||||||||||
if: github.event_name == 'push' && github.event.ref == 'refs/heads/main' | ||||||||||||||||||||||||||||||||||||||
runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
continue-on-error: false | ||||||||||||||||||||||||||||||||||||||
strategy: | ||||||||||||||||||||||||||||||||||||||
matrix: | ||||||||||||||||||||||||||||||||||||||
environment: [ 'dev' ] | ||||||||||||||||||||||||||||||||||||||
environment: ${{ matrix.environment }} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
concurrency: | ||||||||||||||||||||||||||||||||||||||
group: ${{ github.workflow }}-${{ matrix.environment }} | ||||||||||||||||||||||||||||||||||||||
cancel-in-progress: false | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
steps: | ||||||||||||||||||||||||||||||||||||||
- name: Checkout | ||||||||||||||||||||||||||||||||||||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Configure AWS Credentials | ||||||||||||||||||||||||||||||||||||||
uses: ./.github/actions/configure-aws-credentials | ||||||||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||||||||
aws_region: ${{ env.AWS_REGION || 'eu-south-1' }} | ||||||||||||||||||||||||||||||||||||||
role_to_assume: ${{ secrets.IAM_ROLE_DEPLOY_CHATBOT }} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Login to Amazon ECR | ||||||||||||||||||||||||||||||||||||||
id: login-ecr | ||||||||||||||||||||||||||||||||||||||
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1 | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Build Push and Tag | ||||||||||||||||||||||||||||||||||||||
# Enabling the "continue on error" option allows for a manual rollback | ||||||||||||||||||||||||||||||||||||||
# to be performed in case of any issues. Without this option, the step | ||||||||||||||||||||||||||||||||||||||
# will fail if the image already exists in the Elastic Container | ||||||||||||||||||||||||||||||||||||||
# Registry (ECR). However, by activating this option, the deployment | ||||||||||||||||||||||||||||||||||||||
# process will proceed to the next steps even if the ECR image already | ||||||||||||||||||||||||||||||||||||||
# exists | ||||||||||||||||||||||||||||||||||||||
continue-on-error: true | ||||||||||||||||||||||||||||||||||||||
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 | ||||||||||||||||||||||||||||||||||||||
env: | ||||||||||||||||||||||||||||||||||||||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||||||||||||||||||||||||||||||||||||||
ECR_REPOSITORY: chatbot | ||||||||||||||||||||||||||||||||||||||
IMAGE_TAG: ${{ github.sha }} | ||||||||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||||||||
context: apps/chatbot | ||||||||||||||||||||||||||||||||||||||
file: docker/app.Dockerfile | ||||||||||||||||||||||||||||||||||||||
push: true | ||||||||||||||||||||||||||||||||||||||
tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | ||||||||||||||||||||||||||||||||||||||
provenance: false | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Generate task-definition file | ||||||||||||||||||||||||||||||||||||||
run: aws ecs describe-task-definition --task-definition chatbot-task-def --query taskDefinition > task-definition.json | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Update ImageTag in task-definition | ||||||||||||||||||||||||||||||||||||||
id: task-def | ||||||||||||||||||||||||||||||||||||||
uses: aws-actions/amazon-ecs-render-task-definition@4225e0b507142a2e432b018bc3ccb728559b437a # v1.2.0 | ||||||||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||||||||
task-definition: apps/chatbot/task-definition.json | ||||||||||||||||||||||||||||||||||||||
container-name: chatbot-docker | ||||||||||||||||||||||||||||||||||||||
image: ${{ steps.login-ecr.outputs.registry }}/chatbot:${{ github.sha }} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Deploy new ECS task definition | ||||||||||||||||||||||||||||||||||||||
uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a # v1.4.11 | ||||||||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||||||||
task-definition: ${{ steps.task-def.outputs.task-definition }} | ||||||||||||||||||||||||||||||||||||||
service: chatbot-ecs | ||||||||||||||||||||||||||||||||||||||
cluster: chatbot-ecs-cluster | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+99
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: AWS set lambda function image | ||||||||||||||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||||||||||||||
aws lambda update-function-code --function-name env.CHATBOT_LAMBDA_NAME --image-uri ${{ steps.login-ecr.outputs.registry }}/chatbot:${{ github.sha }} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
manual_deploy: | ||||||||||||||||||||||||||||||||||||||
name: Build and push Chatbot API lambda image (manual trigger) - (${{ inputs.environment }}) | ||||||||||||||||||||||||||||||||||||||
if: github.event_name == 'workflow_dispatch' | ||||||||||||||||||||||||||||||||||||||
runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
continue-on-error: false | ||||||||||||||||||||||||||||||||||||||
environment: ${{ inputs.environment }} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
concurrency: | ||||||||||||||||||||||||||||||||||||||
group: ${{ github.workflow }}-${{ inputs.environment }} | ||||||||||||||||||||||||||||||||||||||
cancel-in-progress: false | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
steps: | ||||||||||||||||||||||||||||||||||||||
- name: Checkout | ||||||||||||||||||||||||||||||||||||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Configure AWS Credentials | ||||||||||||||||||||||||||||||||||||||
uses: ./.github/actions/configure-aws-credentials | ||||||||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||||||||
aws_region: ${{ env.AWS_REGION || 'eu-south-1' }} | ||||||||||||||||||||||||||||||||||||||
role_to_assume: ${{ secrets.IAM_ROLE_DEPLOY_CHATBOT }} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Login to Amazon ECR | ||||||||||||||||||||||||||||||||||||||
id: login-ecr | ||||||||||||||||||||||||||||||||||||||
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1 | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Build Push and Tag | ||||||||||||||||||||||||||||||||||||||
# Enabling the "continue on error" option allows for a manual rollback | ||||||||||||||||||||||||||||||||||||||
# to be performed in case of any issues. Without this option, the step | ||||||||||||||||||||||||||||||||||||||
# will fail if the image already exists in the Elastic Container | ||||||||||||||||||||||||||||||||||||||
# Registry (ECR). However, by activating this option, the deployment | ||||||||||||||||||||||||||||||||||||||
# process will proceed to the next steps even if the ECR image already | ||||||||||||||||||||||||||||||||||||||
# exists | ||||||||||||||||||||||||||||||||||||||
continue-on-error: true | ||||||||||||||||||||||||||||||||||||||
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 | ||||||||||||||||||||||||||||||||||||||
env: | ||||||||||||||||||||||||||||||||||||||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||||||||||||||||||||||||||||||||||||||
ECR_REPOSITORY: chatbot | ||||||||||||||||||||||||||||||||||||||
IMAGE_TAG: ${{ github.sha }} | ||||||||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||||||||
context: apps/chatbot | ||||||||||||||||||||||||||||||||||||||
push: true | ||||||||||||||||||||||||||||||||||||||
tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | ||||||||||||||||||||||||||||||||||||||
provenance: false | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Generate task-definition file | ||||||||||||||||||||||||||||||||||||||
run: aws ecs describe-task-definition --task-definition chatbot-task-def --query taskDefinition > task-definition.json | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Update ImageTag in task-definition | ||||||||||||||||||||||||||||||||||||||
id: task-def | ||||||||||||||||||||||||||||||||||||||
uses: aws-actions/amazon-ecs-render-task-definition@4225e0b507142a2e432b018bc3ccb728559b437a # v1.2.0 | ||||||||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||||||||
task-definition: apps/chatbot/task-definition.json | ||||||||||||||||||||||||||||||||||||||
container-name: chatbot-docker | ||||||||||||||||||||||||||||||||||||||
image: ${{ steps.login-ecr.outputs.registry }}/chatbot:${{ github.sha }} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
- name: Deploy new ECS task definition | ||||||||||||||||||||||||||||||||||||||
uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a # v1.4.11 | ||||||||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||||||||
task-definition: ${{ steps.task-def.outputs.task-definition }} | ||||||||||||||||||||||||||||||||||||||
service: chatbot-ecs | ||||||||||||||||||||||||||||||||||||||
cluster: chatbot-ecs-cluster | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
Comment on lines
+154
to
+171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto
Suggested change
|
||||||||||||||||||||||||||||||||||||||
- name: AWS set lambda function image | ||||||||||||||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||||||||||||||
aws lambda update-function-code --function-name env.CHATBOT_LAMBDA_NAME --image-uri ${{ steps.login-ecr.outputs.registry }}/chatbot:${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is only necessary when deploying to ECS. In this case where we use Lambda, a task definition is not needed