Skip to content

Remove from supression list #16100

Remove from supression list

Remove from supression list #16100

name: Deploy test admin environment
on:
pull_request:
branches:
- main
types:
- labeled
- opened
- reopened
- synchronize
env:
AWS_DEFAULT_REGION: ca-central-1
FUNCTION_NAME: "notify-admin-pr"
IMAGE: notify/admin
REGISTRY: 239043911459.dkr.ecr.ca-central-1.amazonaws.com
ROLE_ARN: arn:aws:iam::239043911459:role/notify-admin-pr
ACCOUNT_ID: ${{ secrets.STAGING_AWS_ACCOUNT_ID }}
permissions:
id-token: write
contents: write
pull-requests: write
jobs:
build-and-push-container:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'Renovate') }}
runs-on: ubuntu-latest
steps:
- name: Set envs
run: echo "PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Configure credentials to Notify using OIDC
uses: aws-actions/configure-aws-credentials@ececac1a45f3b08a01d2dd070d28d111c5fe6722 # v4.1.0
with:
role-to-assume: arn:aws:iam::${{env.ACCOUNT_ID}}:role/notification-admin-test-admin-workflows
role-session-name: NotifyAdminTestAdminWorkflows
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@5a88a04c91d5c6f97aae0d9be790e64d9b1d47b7 # v1.7.1
- name: Move dockerignore
run: |
mv ci/Dockerfile.lambda.dockerignore .
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
run: |
docker buildx build \
--build-arg GIT_SHA=${{ github.sha }} \
--platform linux/amd64 \
--provenance=false \
--output type=image,push=true \
-t ${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.PR_NUMBER }} \
-f ci/Dockerfile.lambda .
- name: Delete old images
run: |
IMAGES_TO_DELETE="$(aws ecr list-images --repository-name $IMAGE --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json)"
aws ecr batch-delete-image \
--repository-name $IMAGE \
--image-ids "$IMAGES_TO_DELETE" || true
- name: Logout of Amazon ECR
run: docker logout $REGISTRY
deploy-test-admin:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'Renovate') }}
runs-on: ubuntu-latest
outputs:
LAMBDA_URL: ${{ steps.create-update-lambda.outputs.pr_url }}
needs: build-and-push-container
steps:
- name: Set envs
run: echo "PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")" >> $GITHUB_ENV
- name: Configure credentials to Notify using OIDC
uses: aws-actions/configure-aws-credentials@ececac1a45f3b08a01d2dd070d28d111c5fe6722 # v4.1.0
with:
role-to-assume: arn:aws:iam::${{env.ACCOUNT_ID}}:role/notification-admin-test-admin-workflows
role-session-name: NotifyAdminTestAdminWorkflows
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Create/Update lambda function
id: create-update-lambda
run: |
if aws lambda get-function --function-name $FUNCTION_NAME-$PR_NUMBER ; then
aws lambda update-function-code \
--function-name $FUNCTION_NAME-$PR_NUMBER \
--image-uri $REGISTRY/$IMAGE:$PR_NUMBER
else
aws lambda create-function \
--function-name $FUNCTION_NAME-$PR_NUMBER \
--package-type Image \
--role $ROLE_ARN \
--timeout 15 \
--memory-size 1024 \
--code ImageUri=$REGISTRY/$IMAGE:$PR_NUMBER \
--description "$GITHUB_REPOSITORY/pull/$PR_NUMBER" \
--vpc-config SubnetIds=${{ secrets.PR_REVIEW_ENV_SUBNET_IDS }},SecurityGroupIds=${{ secrets.PR_REVIEW_ENV_SECURITY_GROUP_IDS }}
aws lambda wait function-active --function-name $FUNCTION_NAME-$PR_NUMBER
aws lambda add-permission \
--function-name $FUNCTION_NAME-$PR_NUMBER \
--statement-id AllowPublicInvokeFunctionUrl \
--action lambda:InvokeFunctionUrl \
--principal "*" \
--function-url-auth-type NONE
aws lambda add-permission \
--function-name $FUNCTION_NAME-$PR_NUMBER \
--statement-id AllowPublicInvokeFunction \
--action lambda:InvokeFunction \
--principal "*"
URL="$(aws lambda create-function-url-config --function-name $FUNCTION_NAME-$PR_NUMBER --auth-type NONE | jq .FunctionUrl)"
echo "URL=$URL" >> $GITHUB_ENV
aws lambda update-function-configuration \
--function-name $FUNCTION_NAME-$PR_NUMBER \
--environment "Variables={\
NOTIFY_ENVIRONMENT=staging,\
FLASK_APP=application.py,\
IP_GEOLOCATE_SERVICE=False,\
REDIS_ENABLED=True,\
SENDING_DOMAIN=staging.notification.cdssandbox.xyz,\
API_HOST_NAME=https://api.staging.notification.cdssandbox.xyz,\
ADMIN_BASE_URL=$URL,\
AWS_XRAY_SDK_ENABLED=False
}"
aws logs create-log-group --log-group-name /aws/lambda/$FUNCTION_NAME-$PR_NUMBER
aws logs put-retention-policy --log-group-name /aws/lambda/$FUNCTION_NAME-$PR_NUMBER --retention-in-days 14
fi
aws lambda wait function-updated --function-name $FUNCTION_NAME-$PR_NUMBER
aws lambda put-function-concurrency \
--function-name $FUNCTION_NAME-$PR_NUMBER \
--reserved-concurrent-executions 5
PR_URL=$(aws lambda get-function-url-config --function-name $FUNCTION_NAME-$PR_NUMBER --query 'FunctionUrl' --output text)
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
- name: Update PR
if: env.URL != ''
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## :test_tube: Review environment\n${process.env.URL.slice(1, -1)}`
})