add notes to refactor #72
This file contains 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: Build and deploy all of ReportVision's services to a development environment | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
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-publish-ocr: | ||
name: Build and Publish OCR | ||
runs-on: ubuntu-latest | ||
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: 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: | | ||
echo "docker_inspect=$( | ||
docker manifest inspect ghcr.io/${{ env.REPO }}-ocr-api:${{ inputs.ocr-version }} > /dev/null ; echo $? | ||
)" >> $GITHUB_OUTPUT | ||
# Pull the image from GHCR | ||
# - name: Pull OCR Docker image from GHCR | ||
# run: | | ||
# docker pull ghcr.io/${{ github.repository }}-ocr-api:${{ inputs.ocr-version }} | ||
# Debugging step to check the value of docker_inspect | ||
- name: Debug image inspect result | ||
run: echo "Docker inspect result: ${{ steps.image_check.outputs.docker_inspect }}" | ||
# TODO: Check if image exists, if not create and build & if it does then do a docker pull | ||
- name: Build and Push backend | ||
if: ${{ steps.image_check.outputs.docker_inspect == 0 }} # TODO: May need to change this back to 1, but test out 0 | ||
uses: ./.github/actions/build-publish-api | ||
with: | ||
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 | ||
- name: Upload Docker Build Artifact | ||
if: ${{ steps.image_check.outputs.docker_inspect == 1 }} | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ocr-docker-image-artifact | ||
path: ./OCR/dev-dockerfile # Path to the artifact | ||
# Check to see if the file is uploaded in this directory | ||
- name: List files in OCR directory | ||
run: ls -l ./OCR | ||
build-frontend: | ||
name: Build Frontend | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/build-frontend | ||
name: Build frontend | ||
with: | ||
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 | ||
environment-setup: | ||
name: Setup Azure Environment | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.deploy-env }} | ||
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 }} | ||
- uses: ./.github/actions/tf-setup | ||
name: Setup this environment with Terraform | ||
with: | ||
deploy-env: ${{ inputs.deploy-env }} | ||
azure-resource-group: reportvision-rg-${{ inputs.deploy-env }} | ||
azure-client-id: ${{ secrets.AZURE_CLIENT_ID }} | ||
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
app-name: reportvision | ||
deploy-ocr: | ||
name: Deploy OCR | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.deploy-env }} | ||
needs: [build-publish-ocr, environment-setup] | ||
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: Download Docker Artifact (Optional) | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: ocr-docker-image-artifact # The name of the artifact to download | ||
path: ./OCR # Path where the artifact will be saved | ||
# Ensure that the downloaded artifact is available | ||
- name: List files in the downloaded artifact directory (for debugging) | ||
run: ls -l ./downloaded-artifact | ||
- name: Deploy OCR-API | ||
uses: ./.github/actions/deploy-api | ||
with: | ||
deploy-env: ${{ inputs.deploy-env }} | ||
docker-tag: ${{ inputs.ocr-version }} | ||
docker-registry: ghcr.io | ||
api-name: ocr-api | ||
deploy-frontend: | ||
name: Deploy Frontend | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.deploy-env }} | ||
needs: [build-frontend, environment-setup] | ||
if: ${{ inputs.deploy-env != 'demo'}} | ||
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: Deploy frontend | ||
uses: ./.github/actions/deploy-frontend | ||
with: | ||
frontend-tarball: frontend.tgz | ||
deploy-env: ${{ inputs.deploy-env }} |