Skip to content

Commit

Permalink
feat: automated deploy check by changes
Browse files Browse the repository at this point in the history
  • Loading branch information
guimroque committed Jan 8, 2025
1 parent 6f802b1 commit ea91ff7
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 152 deletions.
126 changes: 74 additions & 52 deletions .github/workflows/aws-deploy-api-hml.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,83 @@
name: '[API-HML] Deploy to Amazon ECS'
name: "[API-HML] Deploy to Amazon ECS"

on:
push:
branches: [ homologacao ]
branches: [homologacao]

jobs:
check-changes:
name: "[VERIFY] Check for Changes"
runs-on: ubuntu-latest

outputs:
should_deploy: ${{ steps.check.outputs.should_deploy }}

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Check for changes in ./packages/api
id: check
run: |
if git diff --quiet HEAD~1 -- ./packages/api; then
echo "No changes detected in ./packages/api"
echo "::set-output name=should_deploy::false"
else
echo "Changes detected in ./packages/api"
echo "::set-output name=should_deploy::true"
fi
deploy:
name: '[API-HMG] Deploy to Amazon ECS'
name: "[API-HMG] Deploy to Amazon ECS"
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.BAKO_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.BAKO_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login_ecr.outputs.registry }}
ECR_REPOSITORY: bako-safe-api-hmg
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./packages/api
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ./packages/api/hml_api_task_definition.json
container-name: bako-safe-api-hmg
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: bako-safe-api-hmg-service
cluster: Bako-Safe-Hmg
wait-for-service-stability: true


- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.BAKO_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.BAKO_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login_ecr.outputs.registry }}
ECR_REPOSITORY: bako-safe-api-hmg
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./packages/api
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ./packages/api/hml_api_task_definition.json
container-name: bako-safe-api-hmg
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: bako-safe-api-hmg-service
cluster: Bako-Safe-Hmg
wait-for-service-stability: true
124 changes: 74 additions & 50 deletions .github/workflows/aws-deploy-api.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,83 @@
name: '[API] Deploy to Amazon ECS'
name: "[API] Deploy to Amazon ECS"

on:
push:
branches: [ main ]
branches: [main]

jobs:
check-changes:
name: "[VERIFY] Check for Changes"
runs-on: ubuntu-latest

outputs:
should_deploy: ${{ steps.check.outputs.should_deploy }}

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Check for changes in ./packages/api
id: check
run: |
if git diff --quiet HEAD~1 -- ./packages/api; then
echo "No changes detected in ./packages/api"
echo "::set-output name=should_deploy::false"
else
echo "Changes detected in ./packages/api"
echo "::set-output name=should_deploy::true"
fi
deploy:
name: '[API] Deploy to Amazon ECS'
name: "[API] Deploy to Amazon ECS"
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.BAKO_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.BAKO_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login_ecr.outputs.registry }}
ECR_REPOSITORY: bako-safe-api
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./packages/api
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ./packages/api/prod_api_task_definition.json
container-name: bako-safe-api
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: bako-safe-api-service
cluster: Bako-Safe-ECS
wait-for-service-stability: true
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.BAKO_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.BAKO_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login_ecr.outputs.registry }}
ECR_REPOSITORY: bako-safe-api
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./packages/api
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ./packages/api/prod_api_task_definition.json
container-name: bako-safe-api
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: bako-safe-api-service
cluster: Bako-Safe-ECS
wait-for-service-stability: true
Loading

0 comments on commit ea91ff7

Please sign in to comment.