-
Notifications
You must be signed in to change notification settings - Fork 3
Deployement: CD for kaapi guardrail in EC2 #95
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
Open
nishika26
wants to merge
19
commits into
main
Choose a base branch
from
enhancement/cd_staging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−1
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
178c62b
hotfix: drop name field in run guardrail endpoint
nishika26 5ab0c6d
feat(*): deployment automation for guardrails
nishika26 409ed8a
Merge branch 'main' into enhancement/cd_staging
Ayush8923 eae16a0
PR reviews
nishika26 9f06cc6
PR reviews
nishika26 0c5cebf
PR reviews
nishika26 5474b4e
debugging
nishika26 d907a8e
debugging
nishika26 34d4365
debugging
nishika26 46920f2
debugging
nishika26 81f1da9
new parameter command
nishika26 2bc4e53
fix timeout error
nishika26 9ef9e9c
decrease wait time
nishika26 8968f13
changed parameter command
nishika26 852f39e
making small change to test deployment
nishika26 dcd9c8a
change to main and add --rm
nishika26 aedaf7f
change back to cd staging branch for testing
nishika26 953d52b
adding entry point seperately
nishika26 4ca4470
change to main
nishika26 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 hidden or 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,94 @@ | ||
| name: Deploy Kaapi Guardrails Staging To EC2 | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: guardrail-staging-ec2-deploy | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| environment: AWS_STAGING_ENV_SECRETS | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v6 | ||
| with: | ||
| role-to-assume: ${{ secrets.EC2_DEPLOY_ROLE_ARN }} | ||
| aws-region: ${{ secrets.AWS_REGION }} | ||
|
|
||
| - name: Trigger deploy on EC2 via SSM | ||
| id: ssm | ||
| env: | ||
| INSTANCE_ID: ${{ secrets.STAGING_EC2_INSTANCE_ID }} | ||
| BUILD_DIRECTORY: ${{ secrets.BUILD_DIRECTORY }} | ||
| run: | | ||
| CMD_ID=$(aws ssm send-command \ | ||
| --instance-ids "$INSTANCE_ID" \ | ||
| --document-name "AWS-RunShellScript" \ | ||
| --comment "Deploy kaapi-guardrails staging" \ | ||
| --parameters commands="[\"set -eux\",\"sudo chown -R ec2-user:ec2-user ${BUILD_DIRECTORY}\",\"sudo -iu ec2-user bash -lc \\\"cd ${BUILD_DIRECTORY} && git fetch origin && git reset --hard origin/main && docker compose build && docker compose run --rm --entrypoint \\\\\\\"\\\\\\\" backend uv run alembic upgrade head && docker compose up -d --remove-orphans && docker image prune -f\\\"\"]" \ | ||
| --query "Command.CommandId" \ | ||
| --output text) | ||
|
|
||
| echo "cmd_id=$CMD_ID" >> "$GITHUB_OUTPUT" | ||
| echo "Sent SSM command: $CMD_ID" | ||
|
|
||
| - name: Wait for SSM command to finish | ||
| env: | ||
| INSTANCE_ID: ${{ secrets.STAGING_EC2_INSTANCE_ID }} | ||
| CMD_ID: ${{ steps.ssm.outputs.cmd_id }} | ||
| run: | | ||
| for i in {1..20}; do | ||
| STATUS=$(aws ssm get-command-invocation \ | ||
| --command-id "$CMD_ID" \ | ||
| --instance-id "$INSTANCE_ID" \ | ||
| --query "Status" \ | ||
| --output text) | ||
|
Ayush8923 marked this conversation as resolved.
|
||
|
|
||
| echo "Current Status: $STATUS" | ||
|
|
||
| if [ "$STATUS" = "Success" ]; then | ||
| echo "Deployment completed successfully." | ||
|
|
||
| aws ssm get-command-invocation \ | ||
| --command-id "$CMD_ID" \ | ||
| --instance-id "$INSTANCE_ID" \ | ||
| --query '{Status:Status,Stdout:StandardOutputContent,Stderr:StandardErrorContent}' \ | ||
| --output json | ||
|
|
||
| exit 0 | ||
| fi | ||
|
|
||
| if [ "$STATUS" = "Failed" ] || [ "$STATUS" = "Cancelled" ] || [ "$STATUS" = "TimedOut" ]; then | ||
| echo "Deployment failed." | ||
|
|
||
| aws ssm get-command-invocation \ | ||
| --command-id "$CMD_ID" \ | ||
| --instance-id "$INSTANCE_ID" \ | ||
| --query '{Status:Status,Stdout:StandardOutputContent,Stderr:StandardErrorContent}' \ | ||
| --output json | ||
|
|
||
| exit 1 | ||
| fi | ||
|
|
||
| sleep 15 | ||
| done | ||
|
|
||
| echo "Deployment timed out after waiting too long." | ||
|
|
||
| aws ssm get-command-invocation \ | ||
| --command-id "$CMD_ID" \ | ||
| --instance-id "$INSTANCE_ID" \ | ||
| --query '{Status:Status,Stdout:StandardOutputContent,Stderr:StandardErrorContent}' \ | ||
| --output json | ||
|
|
||
| exit 1 | ||
File renamed without changes.
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.