Skip to content

Commit

Permalink
Fix docker image check for faster OCR deployments (#354)
Browse files Browse the repository at this point in the history
* Try to fix Docker image check

* try with new image name

* try with full workflow

* try with new image in full workflow

* wip

* wip

* fixed

* test frontend workflow with changes

* test frontend workflow with changes

* test ocr build and deploy with changes

* test with already registered docker images

* clean-up worked

* wip

---------

Co-authored-by: Administrator <[email protected]>
  • Loading branch information
derekadombek and Administrator authored Nov 5, 2024
1 parent 53880ca commit 295ce46
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 82 deletions.
57 changes: 18 additions & 39 deletions .github/workflows/build-deploy-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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
Expand Down
89 changes: 47 additions & 42 deletions .github/workflows/build-deploy-ocr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 17 additions & 1 deletion .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +49,7 @@ jobs:
api-name: ocr-api

build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -50,6 +63,7 @@ jobs:
node-version: 20

environment-setup:
name: Setup Azure Environment
runs-on: ubuntu-latest
environment: ${{ inputs.deploy-env }}
steps:
Expand All @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit 295ce46

Please sign in to comment.