hongbo-miao/hongbomiao.com

View on GitHub
.github/workflows/build.yml

Summary

Maintainability
Test Coverage
---
name: Build

'on':
  push:
    branches: [main]
  schedule:
    - cron: 0 11 * * *

jobs:
  detect-changes:
    name: Detect Changes
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 10
    permissions:
      pull-requests: read
    outputs:
      api-go: ${{ steps.filter.outputs.api-go }}
      api-node: ${{ steps.filter.outputs.api-node }}
      api-python: ${{ steps.filter.outputs.api-python }}
      flink-stream-tweets: ${{ steps.filter.outputs.flink-stream-tweets }}
      hm-alpine: ${{ steps.filter.outputs.hm-alpine }}
      hm-confluent-schema-registry: ${{ steps.filter.outputs.hm-confluent-schema-registry }}
      hm-kafka-iot-kafka-connect: ${{ steps.filter.outputs.hm-kafka-iot-kafka-connect }}
      hm-kafka-logging-kafka-connect: ${{ steps.filter.outputs.hm-kafka-logging-kafka-connect }}
      hm-kafka-opa-kafka-connect: ${{ steps.filter.outputs.hm-kafka-opa-kafka-connect }}
      hm-keydb: ${{ steps.filter.outputs.hm-keydb }}
      hm-opal-client: ${{ steps.filter.outputs.hm-opal-client }}
      hm-pgbackrest: ${{ steps.filter.outputs.hm-pgbackrest }}
      hm-prefect-calculate: ${{ steps.filter.outputs.hm-prefect-calculate }}
      hm-prefect-greet: ${{ steps.filter.outputs.hm-prefect-greet }}
      hm-prefect-ingest-data: ${{ steps.filter.outputs.hm-prefect-ingest-data }}
      hm-prefect-print-platform: ${{ steps.filter.outputs.hm-prefect-print-platform }}
      hm-rasa: ${{ steps.filter.outputs.hm-rasa }}
      hm-spark-find-retired-people-python: ${{ steps.filter.outputs.hm-spark-find-retired-people-python }}
      hm-spark-find-retired-people-scala: ${{ steps.filter.outputs.hm-spark-find-retired-people-scala }}
      hm-spark-ingest-from-s3-to-kafka: ${{ steps.filter.outputs.hm-spark-ingest-from-s3-to-kafka }}
      hm-traefik: ${{ steps.filter.outputs.hm-traefik }}
      web: ${{ steps.filter.outputs.web }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - uses: dorny/paths-filter@v3.0.2
        id: filter
        with:
          filters: |
            api-go:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'api-go/**'
            api-node:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'api-node/**'
            api-python:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'api-python/**'
            flink-stream-tweets:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-processing/flink/applications/stream-tweets/**'
            hm-alpine:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'hm-alpine/**'
            hm-confluent-schema-registry:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'kubernetes/argo-cd/applications/production-hm/confluent-schema-registry/build/**'
            hm-kafka-iot-kafka-connect:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'hm-kafka/kafka-connect-cluster/iot-kafka-connect/**'
            hm-kafka-logging-kafka-connect:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'hm-kafka/kafka-connect-cluster/logging-kafka-connect/**'
            hm-kafka-opa-kafka-connect:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'hm-kafka/kafka-connect-cluster/opa-kafka-connect/**'
            hm-keydb:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-storage/hm-keydb/**'
            hm-opal-client:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'authorization/hm-opal-client/**'
            hm-pgbackrest:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-storage/hm-pgbackrest/**'
            hm-prefect-calculate:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-orchestration/hm-prefect/workflows/calculate/**'
            hm-prefect-greet:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-orchestration/hm-prefect/workflows/greet/**'
            hm-prefect-ingest-data:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-orchestration/hm-prefect/workflows/ingest-data/**'
            hm-prefect-print-platform:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-orchestration/hm-prefect/workflows/print-platform/**'
            hm-rasa:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'machine-learning/hm-rasa/**'
            hm-spark-find-retired-people-python:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-processing/hm-spark/applications/find-retired-people-python/**'
            hm-spark-find-retired-people-scala:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-processing/hm-spark/applications/find-retired-people-scala/**'
            hm-spark-ingest-from-s3-to-kafka:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'data-processing/hm-spark/applications/ingest-from-s3-to-kafka/**'
            hm-traefik:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'hm-traefik/**'
            web:
              - '.dockerignore'
              - '.github/workflows/build.yml'
              - 'web/**'

  build-hm-web:
    name: Build hm-web
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.web == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./web/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-web:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-api-node:
    name: Build hm-api-node
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.api-node == 'true' || needs.detect-changes.outputs.web == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./api-node/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-api-node:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-api-python:
    name: Build hm-api-python
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.api-python == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./api-python/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-api-python:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-graphql-server:
    name: Build hm-graphql-server
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.api-go == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./api-go/build/package/graphql_server/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-graphql-server:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-grpc-server:
    name: Build hm-grpc-server
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.api-go == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./api-go/build/package/grpc_server/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-grpc-server:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-config-loader:
    name: Build hm-config-loader
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.api-go == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./api-go/build/package/config_loader/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-config-loader:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-decision-logger:
    name: Build hm-decision-logger
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.api-go == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./api-go/build/package/decision_logger/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-decision-logger:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-prefect-calculate:
    name: Build hm-prefect-calculate
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-prefect-calculate == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./data-orchestration/hm-prefect/workflows/calculate/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-prefect-calculate:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-prefect-greet:
    name: Build hm-prefect-greet
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-prefect-greet == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./data-orchestration/hm-prefect/workflows/greet/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-prefect-greet:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-prefect-ingest-data:
    name: Build hm-prefect-ingest-data
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-prefect-ingest-data == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./data-orchestration/hm-prefect/workflows/ingest-data/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-prefect-ingest-data:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-prefect-print-platform:
    name: Build hm-prefect-print-platform
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-prefect-print-platform == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./data-orchestration/hm-prefect/workflows/print-platform/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-prefect-print-platform:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-spark-find-retired-people-python:
    name: Build hm-spark-find-retired-people-python
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-spark-find-retired-people-python == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./data-processing/hm-spark/applications/find-retired-people-python/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-spark-find-retired-people-python:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-spark-find-retired-people-scala:
    name: Build hm-spark-find-retired-people-scala
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-spark-find-retired-people-scala == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./data-processing/hm-spark/applications/find-retired-people-scala/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-spark-find-retired-people-scala:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-spark-ingest-from-s3-to-kafka:
    name: Build hm-spark-ingest-from-s3-to-kafka
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-spark-ingest-from-s3-to-kafka == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./data-processing/hm-spark/applications/ingest-from-s3-to-kafka/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-spark-ingest-from-s3-to-kafka:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-kafka-iot-kafka-connect:
    name: Build hm-kafka-iot-kafka-connect
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-kafka-iot-kafka-connect == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./hm-kafka/kafka-connect-cluster/iot-kafka-connect/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-kafka-iot-kafka-connect:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-kafka-logging-kafka-connect:
    name: Build hm-kafka-logging-kafka-connect
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-kafka-logging-kafka-connect == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./hm-kafka/kafka-connect-cluster/logging-kafka-connect/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-kafka-logging-kafka-connect:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-kafka-opa-kafka-connect:
    name: Build hm-kafka-opa-kafka-connect
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-kafka-opa-kafka-connect == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./hm-kafka/kafka-connect-cluster/opa-kafka-connect/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-kafka-opa-kafka-connect:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-confluent-schema-registry:
    name: Build hm-confluent-schema-registry
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-confluent-schema-registry == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./kubernetes/argo-cd/applications/production-hm/confluent-schema-registry/build/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-confluent-schema-registry:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-opal-client:
    name: Build hm-opal-client
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-opal-client == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./authorization/hm-opal-client/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-opal-client:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-rasa-action-server:
    name: Build hm-rasa-action-server
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-rasa == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./machine-learning/hm-rasa/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-rasa-action-server:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-flink-stream-tweets:
    name: Build flink-stream-tweets
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.flink-stream-tweets == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Retrieve the secret and decode it to a file
        working-directory: data-processing/flink/applications/stream-tweets/src/main/resources
        env:
          PROPERTIES_BASE64: ${{ secrets.HM_STEAMING_APPLICATION_PROPERTIES_BASE64 }}
        run: |
          echo $HM_STEAMING_APPLICATION_PROPERTIES_BASE64 | base64 --decode > application-production.properties
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./data-processing/flink/applications/stream-tweets/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-flink-stream-tweets:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-keydb:
    name: Build hm-keydb
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-keydb == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Get redisgraph.so
        working-directory: data-storage/hm-keydb
        run: |
          docker create --cidfile=/tmp/cid.txt redislabs/redisgraph:latest
          docker cp $(cat /tmp/cid.txt):/usr/lib/redis/modules/redisgraph.so ./modules/
          docker container rm $(cat /tmp/cid.txt)
          rm -f /tmp/cid.txt
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./data-storage/hm-keydb/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-keydb:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-traefik:
    name: Build hm-traefik
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-traefik == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./hm-traefik/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-traefik:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  build-hm-alpine:
    name: Build hm-alpine
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-alpine == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 60
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3.2.0
        with:
          platforms: amd64,arm64
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3.7.1
      - name: Log in GitHub Container Registry
        uses: docker/login-action@v3.3.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: wandalen/wretry.action@v3.5.0
        with:
          action: docker/build-push-action@v5.1.0
          with: |
            context: .
            file: ./hm-alpine/Dockerfile
            push: true
            tags: ghcr.io/hongbo-miao/hm-alpine:latest
            cache-from: type=gha
            cache-to: type=gha,mode=max
          attempt_limit: 3
          attempt_delay: 2000

  upload-pgbackrest:
    name: Upload pgbackrest
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.hm-pgbackrest == 'true' }}
    runs-on: ubuntu-22.04
    environment: production
    timeout-minutes: 10
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Build pgbackrest
        run: |
          docker build --file=data-storage/hm-pgbackrest/Dockerfile --tag=ghcr.io/hongbo-miao/hm-pgbackrest:latest .
      - name: Extract pgbackrest
        run: |
          docker create --name=hm-pgbackrest ghcr.io/hongbo-miao/hm-pgbackrest:latest
          docker cp hm-pgbackrest:/usr/src/app/build/pgbackrest-release-2.43/src/pgbackrest pgbackrest
      - name: Upload pgbackrest
        uses: actions/upload-artifact@v4
        with:
          name: pgbackrest
          path: pgbackrest

  deploy-hm-api-node:
    name: Deploy hm-api-node
    needs: detect-changes
    if: ${{ needs.detect-changes.outputs.api-node == 'true' || needs.detect-changes.outputs.web == 'true' }}
    runs-on: ubuntu-22.04
    environment:
      name: production-web
      url: https://www.hongbomiao.com
    timeout-minutes: 150
    steps:
      - name: Checkout
        uses: actions/checkout@v4.2.1
      - name: Set up Node.js
        uses: actions/setup-node@v4.0.4
        with:
          node-version-file: web/.nvmrc
          cache: npm
          cache-dependency-path: web/package-lock.json
      - name: Build web
        run: |
          cd api-node
          npm run build:web
          cd ..
          rm -f .gitignore
          git add .
          git config --global user.name "Hongbo Miao"
          git config --global user.email "3375461+hongbo-miao@users.noreply.github.com"
          git commit --message="chore(api-node): build web"
      - name: Deploy to Heroku
        uses: akhileshns/heroku-deploy@v3.13.15
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: production-web
          heroku_email: hongbo.miao@outlook.com
          appdir: api-node