Skip to content

Commit

Permalink
chore: Improve deployment github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
alepefe committed Nov 13, 2024
1 parent c19f9f9 commit 852cee1
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ on:
- 'package.json'

jobs:

set_environment:
runs-on: ubuntu-latest
name: Set Deployment Environment
Expand All @@ -26,45 +25,54 @@ jobs:
- id: set_env
run: echo "env_name=${{ github.ref_name == 'main' && 'production' || github.ref_name }}" >> $GITHUB_OUTPUT

build_client:
needs: [ set_environment ]
environment:
name: ${{ needs.set_environment.outputs.env_name }}
trigger_build:
runs-on: ubuntu-latest
name: Build Client image and push to Amazon ECR
outputs:
build_api: ${{ steps.changes.outputs.api == 'true' || github.ref_name == 'staging' || github.ref_name == 'main' }}
build_client: ${{ steps.changes.outputs.client == 'true' || github.ref_name == 'staging' || github.ref_name == 'main' }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: dorny/paths-filter@v3
id: client-changes
- name: Detect changes in client and API paths
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
client:
- '.github/workflows/**'
- 'shared/**'
- 'client/**'
api:
- '.github/workflows/**'
- 'shared/**'
- 'api/**'
build_client:
needs: [ set_environment, trigger_build ]
if: ${{ github.event_name == 'workflow_dispatch' || needs.trigger_build.outputs.build_client == 'true' }}
environment:
name: ${{ needs.set_environment.outputs.env_name }}
runs-on: ubuntu-latest
name: Build Client image and push to Amazon ECR
steps:
- name: Configure AWS credentials
if: ${{ github.event_name == 'workflow_dispatch' || steps.client-changes.outputs.client == 'true' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.TF_PIPELINE_USER_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TF_PIPELINE_USER_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.TF_AWS_REGION }}

- name: Login to Amazon ECR
if: ${{ github.event_name == 'workflow_dispatch' || steps.client-changes.outputs.client == 'true' }}
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: 'true'

- name: Set up Docker Buildx
if: ${{ github.event_name == 'workflow_dispatch' || steps.client-changes.outputs.client == 'true' }}
uses: docker/setup-buildx-action@v3

- name: Build, tag, and push Client image to Amazon ECR
if: ${{ github.event_name == 'workflow_dispatch' || steps.client-changes.outputs.client == 'true' }}
uses: docker/build-push-action@v5
with:
build-args: |
Expand All @@ -82,44 +90,30 @@ jobs:
${{ steps.login-ecr.outputs.registry }}/${{ secrets.TF_CLIENT_REPOSITORY_NAME }}:${{ needs.set_environment.outputs.env_name }}
build_api:
needs: [ set_environment ]
needs: [ set_environment, trigger_build ]
if: ${{ github.event_name == 'workflow_dispatch' || needs.trigger_build.outputs.build_api == 'true' }}
environment:
name: ${{ needs.set_environment.outputs.env_name }}
runs-on: ubuntu-latest
name: Build API image and push to Amazon ECR
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: dorny/paths-filter@v3
id: api-changes
with:
filters: |
api:
- 'api/**'
- '.github/workflows/**'
- name: Configure AWS credentials
if: ${{ github.event_name == 'workflow_dispatch' || steps.api-changes.outputs.api == 'true' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.TF_PIPELINE_USER_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TF_PIPELINE_USER_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.TF_AWS_REGION }}

- name: Login to Amazon ECR
if: ${{ github.event_name == 'workflow_dispatch' || steps.api-changes.outputs.api == 'true' }}
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: 'true'

- name: Set up Docker Buildx
if: ${{ github.event_name == 'workflow_dispatch' || steps.api-changes.outputs.api == 'true' }}
uses: docker/setup-buildx-action@v3

- name: Build, tag, and push API image to Amazon ECR
if: ${{ github.event_name == 'workflow_dispatch' || steps.api-changes.outputs.api == 'true' }}
uses: docker/build-push-action@v5
with:
build-args: |
Expand Down

0 comments on commit 852cee1

Please sign in to comment.