fix(config): correct API_URL construction for env, prod, and local #339
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: hhai.dev container CI/CD | |
| # Build apps into Docker images, push to | |
| # GitHub container registry and deploy | |
| # on host machine. | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| paths: | |
| - "apps/**" | |
| - "api/**" | |
| - "docker/**" | |
| - "package.json" | |
| - "package-lock.json" | |
| - "Cargo.toml" | |
| - "Cargo.lock" | |
| - "turbo.json" | |
| workflow_dispatch: | |
| jobs: | |
| files-changed: | |
| name: Detect which files' changed | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 3 | |
| # Map a step output to a job output | |
| outputs: | |
| www: ${{ steps.changes.outputs.www }} | |
| backend: ${{ steps.changes.outputs.api }} | |
| migrate: ${{ steps.changes.outputs.migrate }} | |
| # Config related changes that do not require a build but trigger a deploy | |
| deploy: ${{ steps.changes.outputs.deploy }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Check for file changes | |
| uses: dorny/paths-filter@v3 | |
| id: changes | |
| with: | |
| token: ${{ github.token }} | |
| filters: | | |
| www: | |
| - "apps/hhai.dev/**" | |
| - "docker/hhai-dev-www.Dockerfile" | |
| - "package.json" | |
| - "package-lock.json" | |
| api: | |
| - "api/src/**" | |
| - "api/Cargo.toml" | |
| - "Cargo.lock" | |
| - "docker/hhai-dev-api.Dockerfile" | |
| migrate: | |
| - "api/migrations/**" | |
| - "api/schema.prisma" | |
| - "docker/hhai-dev-migrator.Dockerfile" | |
| deploy: | |
| - "docker/Caddyfile" | |
| - "docker/docker-compose*.yml" | |
| - "docker/*.Dockerfile" | |
| - "docker/vector/vector.toml" | |
| # test-backend: | |
| # name: Test backend API | |
| # needs: files-changed | |
| # if: ${{ needs.files-changed.outputs.backend == 'true' }} | |
| # runs-on: ubuntu-latest | |
| # steps: | |
| # - uses: actions/checkout@v4 | |
| # - uses: dtolnay/rust-toolchain@stable | |
| # - run: cargo test --workspace --all-features | |
| build-and-push-www: | |
| name: Build www | |
| needs: files-changed | |
| if: ${{ needs.files-changed.outputs.www == 'true' }} | |
| uses: ./.github/workflows/container-ci.yml | |
| with: | |
| name: hhai.dev www | |
| tags: ghcr.io/wonrax/hhai-dev-www:latest | |
| dockerfile: docker/hhai-dev-www.Dockerfile | |
| secrets: inherit | |
| build-and-push-backend: | |
| name: Build API | |
| # needs: [files-changed, test-backend] | |
| needs: [files-changed] | |
| if: ${{ needs.files-changed.outputs.backend == 'true' }} | |
| uses: ./.github/workflows/container-ci.yml | |
| with: | |
| name: hhai.dev api | |
| tags: ghcr.io/wonrax/hhai-dev-api:latest | |
| dockerfile: docker/hhai-dev-api.Dockerfile | |
| secrets: inherit | |
| build-and-push-migrate: | |
| name: Build database migrator | |
| needs: files-changed | |
| if: ${{ needs.files-changed.outputs.migrate == 'true' }} | |
| uses: ./.github/workflows/container-ci.yml | |
| with: | |
| name: hhai.dev migrate | |
| tags: ghcr.io/wonrax/hhai-dev-migrator:latest | |
| dockerfile: docker/hhai-dev-migrator.Dockerfile | |
| secrets: inherit | |
| deploy: | |
| name: Deploy | |
| uses: ./.github/workflows/deploy.yml | |
| needs: | |
| - build-and-push-www | |
| - build-and-push-backend | |
| - build-and-push-migrate | |
| - files-changed | |
| # According to GHA docs, this job won't run if one of its needs is | |
| # skipped. We want to deploy if at least one needed job is successful | |
| # and no jobs fail. We don't care about skipping job because we don't | |
| # want to re-build and re-deploy unchanged code. | |
| # Related links: | |
| # https://docs.github.com/en/actions/learn-github-actions/expressions#failure | |
| # https://docs.github.com/en/actions/learn-github-actions/contexts#needs-context | |
| if: ${{ !failure() && ( | |
| needs.build-and-push-backend.result == 'success' || | |
| needs.build-and-push-www.result == 'success' || | |
| needs.build-and-push-migrate.result == 'success' || | |
| needs.files-changed.outputs.deploy == 'true' ) }} | |
| secrets: inherit | |
| invalidate-cdn-cache: | |
| name: Invalidate CloudFront cache | |
| needs: [build-and-push-www, deploy] | |
| # always() is needed otherwise the job will be skipped | |
| # even if needs jobs succeed | |
| if: ${{ always() && | |
| needs.build-and-push-www.result == 'success' && | |
| needs.deploy.result == 'success' }} | |
| runs-on: ubuntu-latest | |
| environment: deploy | |
| steps: | |
| - name: Invalidate CloudFront | |
| uses: chetan/invalidate-cloudfront-action@v2 | |
| env: | |
| DISTRIBUTION: ${{ vars.CLOUDFRONT_DISTRIBUTION }} | |
| PATHS: "/*" | |
| AWS_REGION: "us-east-1" | |
| AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |