diff --git a/.github/workflows/build-deploy-frontend.yml b/.github/workflows/build-deploy-frontend.yml index c7cf0de0..5a1432e0 100644 --- a/.github/workflows/build-deploy-frontend.yml +++ b/.github/workflows/build-deploy-frontend.yml @@ -10,7 +10,7 @@ on: options: - dev - demo - demo-blob-name: + storage-account-name: description: 'After the demo env gets created, copy its blob storage name here' required: false @@ -19,55 +19,34 @@ permissions: contents: read jobs: - build: - name: Build + build-frontend: runs-on: ubuntu-latest - defaults: - run: - working-directory: frontend - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Install Node.js - uses: actions/setup-node@v4 + - uses: actions/checkout@v4 + - uses: ./.github/actions/build-frontend + name: Build frontend with: - node-version: '20' - - name: Install NPM packages - run: npm ci - - name: Build project - run: VITE_API_URL='https://reportvision-ocr-${{ inputs.deploy-env }}.azurewebsites.net/' npm run build - - name: Run unit tests - run: npm run test - - name: Create client build archive - shell: bash - run: | - echo "::group::Create application archive" - tar -C ./dist/ -czf ./client.tgz . - echo "::endgroup::" - - name: Upload production-ready build files - uses: actions/upload-artifact@v4 - with: - name: production-files - path: ./frontend/client.tgz + api-endpoint: https://reportvision-ocr-${{ inputs.deploy-env }}.azurewebsites.net/ + frontend-tarball: ./frontend.tgz + frontend-path: ./frontend + frontend-build-path: ./frontend/dist/ + node-version: 20 - deploy: + deploy-with-blob-name-optional: name: Deploy runs-on: ubuntu-latest environment: ${{ inputs.deploy-env }} - needs: [build] + needs: [build-frontend] steps: - name: Download Artifacts To Job uses: actions/download-artifact@v4 with: - name: production-files + name: frontend-tarball - name: Unpack client shell: bash run: | - echo "::group::Unpack client" - mkdir client-build; - tar -C client-build -zxvf client.tgz - echo "::endgroup::" + mkdir frontend-deploy; + tar -C frontend-deploy -zxvf frontend.tgz - name: Azure login uses: azure/login@v2 with: @@ -77,10 +56,10 @@ jobs: - name: Upload to Azure blob storage shell: bash run: | - if [ -z "${{ inputs.demo-blob-name }}" ]; then - az storage blob upload-batch --account-name reportvisionfrontend${{ inputs.deploy-env }} -d '$web' -s client-build/ --overwrite + if [ -z "${{ inputs.storage-account-name }}" ]; then + az storage blob upload-batch --account-name reportvisionfrontend${{ inputs.deploy-env }} -d '$web' -s frontend-deploy/ --overwrite else - az storage blob upload-batch --account-name ${{ inputs.demo-blob-name }} -d '$web' -s client-build/ --overwrite + az storage blob upload-batch --account-name ${{ inputs.storage-account-name }} -d '$web' -s frontend-deploy/ --overwrite fi - name: Azure logout shell: bash diff --git a/.github/workflows/build-deploy-ocr.yml b/.github/workflows/build-deploy-ocr.yml index 9c558297..79bf2f4f 100644 --- a/.github/workflows/build-deploy-ocr.yml +++ b/.github/workflows/build-deploy-ocr.yml @@ -3,69 +3,74 @@ name: Create, publish, deploy a OCR API image on: workflow_dispatch: inputs: - tag: - description: 'Version tag for new release' - required: true - -env: - REGISTRY: ghcr.io - VERSION: ${{ inputs.tag }} + deploy-env: + description: 'The environment to deploy to' + required: true + type: choice + options: + - dev + - demo + ocr-version: + description: 'Create a version for this OCR API image' + required: true +permissions: + contents: read + packages: write + attestations: write + id-token: write jobs: - build-and-push-image: + build-publish-ocr: + name: Build and Publish OCR runs-on: ubuntu-latest - permissions: - contents: read - packages: write - attestations: write - id-token: write + outputs: + docker_inspect: ${{ steps.image_check.outputs.docker_inspect }} steps: - name: Checkout repository uses: actions/checkout@v4 - name: Log in to the Container registry uses: docker/login-action@v3 with: - registry: ${{ env.REGISTRY }} + registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Lowercase the repo name run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} - # - name: Check if image exists - # id: image_check - # run: docker manifest inspect ${{ env.REGISTRY }}/${{ env.REPO }}-ocr-api:${{ env.VERSION }} > /dev/null ; echo $? - - name: Build and push Docker image - id: push - uses: docker/build-push-action@v6 + - name: Check if image exists + id: image_check + run: | + echo "docker_inspect=$( + docker manifest inspect ghcr.io/${{ env.REPO }}-ocr-api:${{ inputs.ocr-version }} > /dev/null ; echo $? + )" >> $GITHUB_OUTPUT + - name: Build and Push backend + if: ${{ steps.image_check.outputs.docker_inspect == 1 }} + uses: ./.github/actions/build-publish-api with: - context: ./OCR/ - file: ./OCR/Dockerfile - push: true - tags: ${{ env.REGISTRY }}/${{ env.REPO }}-ocr-api:${{ env.VERSION }} + docker-registry: ghcr.io + docker-pw: ${{ secrets.GITHUB_TOKEN }} + docker-username: ${{ github.actor }} + docker-tag: ${{ inputs.ocr-version }} + dockerfile-path: ./OCR/Dockerfile + docker-context-path: ./OCR/ + api-name: ocr-api - deploy: + deploy-ocr: + name: Deploy OCR runs-on: ubuntu-latest - permissions: - contents: read - packages: write - attestations: write - id-token: write - needs: build-and-push-image - environment: dev + environment: ${{ inputs.deploy-env }} + needs: [build-publish-ocr] steps: + - uses: actions/checkout@v4 - uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - - name: Lowercase the repo name - run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} - - - name: Deploy to Azure Web App - id: deploy-to-webapp - uses: azure/webapps-deploy@v3 + - name: Deploy OCR-API + uses: ./.github/actions/deploy-api with: - app-name: reportvision-ocr-dev - images: '${{ env.REGISTRY }}/${{ env.REPO}}-ocr-api:${{ env.VERSION }}' - + deploy-env: ${{ inputs.deploy-env }} + docker-tag: ${{ inputs.ocr-version }} + docker-registry: ghcr.io + api-name: ocr-api diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 4eef2fe9..f582f04d 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -22,10 +22,22 @@ permissions: jobs: build-publish-ocr: + name: Build and Publish OCR runs-on: ubuntu-latest + outputs: + docker_inspect: ${{ steps.image_check.outputs.docker_inspect }} steps: - uses: actions/checkout@v4 + - name: Lowercase the repo name + run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} + - name: Check if image exists + id: image_check + run: | + echo "docker_inspect=$( + docker manifest inspect ghcr.io/${{ env.REPO }}-ocr-api:${{ inputs.ocr-version }} > /dev/null ; echo $? + )" >> $GITHUB_OUTPUT - name: Build and Push backend + if: ${{ steps.image_check.outputs.docker_inspect == 1 }} uses: ./.github/actions/build-publish-api with: docker-registry: ghcr.io @@ -37,6 +49,7 @@ jobs: api-name: ocr-api build-frontend: + name: Build Frontend runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -50,6 +63,7 @@ jobs: node-version: 20 environment-setup: + name: Setup Azure Environment runs-on: ubuntu-latest environment: ${{ inputs.deploy-env }} steps: @@ -69,7 +83,8 @@ jobs: azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} app-name: reportvision - deploy-backend: + deploy-ocr: + name: Deploy OCR runs-on: ubuntu-latest environment: ${{ inputs.deploy-env }} needs: [build-publish-ocr, environment-setup] @@ -89,6 +104,7 @@ jobs: api-name: ocr-api deploy-frontend: + name: Deploy Frontend runs-on: ubuntu-latest environment: ${{ inputs.deploy-env }} needs: [build-frontend, environment-setup]