fastapi-v2 / .github /workflows /deployment.yml
BMCVRN's picture
Deleting Hidden Message Fix (#18)
98b7d12 verified
name: Reusable Deployment Workflow
on:
workflow_call:
inputs:
active_env:
required: true
type: string
ecr_url:
required: true
type: string
ecs_service:
required: true
type: string
ecs_cluster:
required: true
type: string
ecs_task_definition:
required: true
type: string
container_name:
required: true
type: string
env:
AWS_REGION: ap-southeast-1
permissions:
contents: read
id-token: write
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment:
name: ${{ inputs.active_env }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
IMAGE_TAG: ${{ github.sha }}
run: |
docker build --build-arg FASTAPI_KEY=${{secrets.FASTAPI_KEY}} --build-arg BING_API_KEY=${{secrets.BING_API_KEY}} --build-arg OPENAI_API_KEY=${{secrets.OPENAI_API_KEY}} -t ${{inputs.ecr_url}}:$IMAGE_TAG .
docker push ${{inputs.ecr_url}}:$IMAGE_TAG
echo "image=${{inputs.ecr_url}}:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@c804dfbdd57f713b6c079302a4c01db7017a36fc
with:
task-definition: ${{ inputs.ecs_task_definition }}
container-name: ${{ inputs.container_name }}
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ inputs.ecs_service }}
cluster: ${{ inputs.ecs_cluster }}
wait-for-service-stability: true