Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docker image check for faster OCR deployments #354

Merged
merged 13 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 18 additions & 44 deletions .github/workflows/build-deploy-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ on:
type: choice
options:
- dev
- dev2
- dev3
- dev4
- dev5
- dev6
- demo
demo-blob-name:
storage-account-name:
description: 'After the demo env gets created, copy its blob storage name here'
required: false

Expand All @@ -24,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the npm packages being installed in the ./frontend.tgz file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats correct. at least with GHA, packaging all the frontend files into a tarball/zip makes downloading from other jobs smoother.

frontend-path: ./frontend
Copy link
Collaborator Author

@derekadombek derekadombek Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def doing a lot of scope creeping on this PR but its a needed clean-up.

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 @@ -82,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 @@ -27,10 +27,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 @@ -42,6 +54,7 @@ jobs:
api-name: ocr-api

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

environment-setup:
name: Setup Azure Environment
runs-on: ubuntu-latest
environment: ${{ inputs.deploy-env }}
steps:
Expand All @@ -74,7 +88,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 @@ -94,6 +109,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
Loading