Skip to content

Build Docker and Deploy Terraform

name: Build and Deploy

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:

permissions:
  id-token: write
  contents: read
  pull-requests: write

jobs:
  docker_build_artifact:
    uses: tx-pts-dai/github-workflows/.github/workflows/docker-build.yaml@v1

  docker_push_ecr:
    if: github.event_name == 'push'
    needs: [docker_build_artifact]
    strategy:
      fail-fast: true
      matrix:
        stack: [app]
        environment: [dev, int, prod]
    uses: tx-pts-dai/github-workflows/.github/workflows/docker-push-ecr.yaml@v1
    with:
      environment: ${{ matrix.stack }}-${{ matrix.environment }}

  plan:
    if: github.event_name == 'pull_request'
    needs: [docker_build_artifact]
    strategy:
      fail-fast: false
      matrix:
        stack: [app]
        environment: [dev, int, prod]
    uses: tx-pts-dai/github-workflows/.github/workflows/tf-plan.yaml@v1
    with:
      environment: ${{ matrix.stack }}-${{ matrix.environment }}

  apply:
    if: github.ref_name == github.event.repository.default_branch && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
    needs: [docker_push_ecr]
    strategy:
      fail-fast: true
      max-parallel: 1
      matrix:
        stack: [app]
        environment: [dev, int, prod]
    uses: tx-pts-dai/github-workflows/.github/workflows/tf-apply.yaml@v1
    with:
      environment: ${{ matrix.stack }}-${{ matrix.environment }}