From 3ef11443e6b41b51ce075bdb2faa2b50b79f6e31 Mon Sep 17 00:00:00 2001 From: Arthur Morrow Date: Thu, 26 Dec 2024 15:34:44 -0500 Subject: [PATCH] arranged frontend to deploy properly with appi connection Jira ticket: CAMS-417 --- .github/workflows/continuous-deployment.yml | 1 + .github/workflows/reusable-build-frontend.yml | 101 ++++++++++++++++++ .github/workflows/sub-build.yml | 66 +++--------- .github/workflows/sub-deploy-code-slot.yml | 18 ++++ 4 files changed, 137 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/reusable-build-frontend.yml diff --git a/.github/workflows/continuous-deployment.yml b/.github/workflows/continuous-deployment.yml index 45c91ebbb..61f5b17db 100644 --- a/.github/workflows/continuous-deployment.yml +++ b/.github/workflows/continuous-deployment.yml @@ -111,6 +111,7 @@ jobs: migrationFunctionName: ${{ needs.setup.outputs.migrationFunctionName }} environment: ${{ needs.setup.outputs.ghaEnvironment }} launchDarklyEnvironment: ${{ vars.CAMS_LAUNCH_DARKLY_ENV }} + azAppResourceGrpEncrypted: ${{ needs.setup.outputs.azResourceGrpAppEncrypted }} deploy: name: Cloud Resource Deployment diff --git a/.github/workflows/reusable-build-frontend.yml b/.github/workflows/reusable-build-frontend.yml new file mode 100644 index 000000000..5ba221fe8 --- /dev/null +++ b/.github/workflows/reusable-build-frontend.yml @@ -0,0 +1,101 @@ +name: Build Frontend + +on: + workflow_call: + inputs: + nodeVersion: + required: true + type: string + isDeployment: + default: false + type: boolean + camsServerHostname: + required: true + type: string + camsServerPort: + required: true + type: string + camsServerProtocol: + required: true + type: string + camsBasePath: + required: true + type: string + webappName: + required: true + type: string + environment: + required: true + type: string + launchDarklyEnvironment: + required: true + type: string + azResourceGrpAppEncrypted: + required: true + type: string +jobs: + frontend: + defaults: + run: + working-directory: user-interface + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + steps: + - uses: actions/checkout@v3 + + - uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + environment: ${{ vars.AZURE_ENVIRONMENT }} + + - uses: cloudposse/github-action-secret-outputs@main + id: rgApp + with: + secret: ${{ secrets.PGP_SIGNING_PASSPHRASE }} + op: decode + in: ${{ inputs.azResourceGrpAppEncrypted }} + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.nodeVersion }} + cache: "npm" + cache-dependency-path: user-interface/package-lock.json + + - name: Execute Build + run: | + pushd ../common + npm ci + popd + + appiString=$(az monitor app-insights component show --app appi-${{ inputs.webappName }} -g ${{ steps.rgApp.outputs.out }} --query "connectionString" -o tsv || true) + + npm ci + export CAMS_SERVER_HOSTNAME=${{ inputs.camsServerHostname }} + export CAMS_SERVER_PORT=${{ inputs.camsServerPort }} + export CAMS_SERVER_PROTOCOL=${{ inputs.camsServerProtocol }} + export CAMS_BASE_PATH=${{ inputs.camsBasePath }} + export CAMS_APPLICATIONINSIGHTS_CONNECTION_STRING="${appiString}" + export CAMS_FEATURE_FLAG_CLIENT_ID="${{ secrets.LD_DEVELOPMENT_CLIENT_ID }}" + export CAMS_LAUNCH_DARKLY_ENV="${{ inputs.launchDarklyEnvironment }}" + export CAMS_LOGIN_PROVIDER=${{ vars.CAMS_LOGIN_PROVIDER }} + export CAMS_LOGIN_PROVIDER_CONFIG='${{ vars.CAMS_LOGIN_PROVIDER_CONFIG }}' + export CAMS_INFO_SHA=${{ github.sha }} + npm run build --if-present + + - name: Package + if: inputs.isDeployment + run: | + pushd ./build + zip -r ./${{ inputs.webappName }}.zip . + popd + mkdir ./artifacts + mv ./build/${{ inputs.webappName }}.zip ./artifacts/ + + - name: Upload Frontend Artifact + if: inputs.isDeployment + uses: actions/upload-artifact@v4.4.0 + with: + name: ${{ inputs.webappName }}-build + path: user-interface/artifacts/ + if-no-files-found: error diff --git a/.github/workflows/sub-build.yml b/.github/workflows/sub-build.yml index a5fcd5c01..790c1b30d 100644 --- a/.github/workflows/sub-build.yml +++ b/.github/workflows/sub-build.yml @@ -33,56 +33,24 @@ on: launchDarklyEnvironment: required: true type: string + azResourceGrpAppEncrypted: + required: true + type: string jobs: - frontend: - defaults: - run: - working-directory: user-interface - runs-on: ubuntu-latest - environment: ${{ inputs.environment }} - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: ${{ inputs.nodeVersion }} - cache: "npm" - cache-dependency-path: user-interface/package-lock.json - - - name: Execute Build - run: | - pushd ../common - npm ci - popd - - npm ci - export CAMS_SERVER_HOSTNAME=${{ inputs.camsServerHostname }} - export CAMS_SERVER_PORT=${{ inputs.camsServerPort }} - export CAMS_SERVER_PROTOCOL=${{ inputs.camsServerProtocol }} - export CAMS_BASE_PATH=${{ inputs.camsBasePath }} - export CAMS_APPLICATIONINSIGHTS_CONNECTION_STRING="${{ secrets.AZ_APPINSIGHTS_WEBAPP_CONNECTION_STRING }}" - export CAMS_FEATURE_FLAG_CLIENT_ID="${{ secrets.LD_DEVELOPMENT_CLIENT_ID }}" - export CAMS_LAUNCH_DARKLY_ENV="${{ inputs.launchDarklyEnvironment }}" - export CAMS_LOGIN_PROVIDER=${{ vars.CAMS_LOGIN_PROVIDER }} - export CAMS_LOGIN_PROVIDER_CONFIG='${{ vars.CAMS_LOGIN_PROVIDER_CONFIG }}' - export CAMS_INFO_SHA=${{ github.sha }} - npm run build --if-present - - - name: Package - run: | - pushd ./build - zip -r ./${{ inputs.webappName }}.zip . - popd - mkdir ./artifacts - mv ./build/${{ inputs.webappName }}.zip ./artifacts/ - - - name: Upload Frontend Artifact - uses: actions/upload-artifact@v4.4.0 - with: - name: ${{ inputs.webappName }}-build - path: user-interface/artifacts/ - if-no-files-found: error + build-frontend-predeployment: + name: Build Frontend Predeployment + uses: ./.github/workflows/reusable-build-frontend.yml + secrets: inherit # pragma: allowlist secret + with: + nodeVersion: ${{ vars.NODE_VERSION }} + camsServerHostname: ${{ inputs.apiFunctionName }}.azurewebsites.us + camsServerPort: ${{ vars.CAMS_SERVER_PORT }} + camsServerProtocol: ${{ vars.CAMS_SERVER_PROTOCOL }} + camsBasePath: ${{ vars.CAMS_BASE_PATH }} + webappName: ${{ inputs.webappName }} + environment: ${{ inputs.environment }} + launchDarklyEnvironment: ${{ vars.CAMS_LAUNCH_DARKLY_ENV }} + azResourceGrpAppEncrypted: ${{ inputs.azResourceGrpAppEncrypted }} backend: defaults: diff --git a/.github/workflows/sub-deploy-code-slot.yml b/.github/workflows/sub-deploy-code-slot.yml index f523c95f9..bc3a54da6 100644 --- a/.github/workflows/sub-deploy-code-slot.yml +++ b/.github/workflows/sub-deploy-code-slot.yml @@ -35,8 +35,25 @@ on: type: string jobs: + build-frontend-deployment: + name: Build Frontend deployment + uses: ./.github/workflows/reusable-build-frontend.yml + secrets: inherit # pragma: allowlist secret + with: + nodeVersion: ${{ vars.NODE_VERSION }} + camsServerHostname: ${{ inputs.apiFunctionName }}.azurewebsites.us + camsServerPort: ${{ vars.CAMS_SERVER_PORT }} + camsServerProtocol: ${{ vars.CAMS_SERVER_PROTOCOL }} + camsBasePath: ${{ vars.CAMS_BASE_PATH }} + webappName: ${{ inputs.webappName }} + environment: ${{ inputs.ghaEnvironment }} + launchDarklyEnvironment: ${{ vars.CAMS_LAUNCH_DARKLY_ENV }} + azResourceGrpAppEncrypted: ${{ inputs.azResourceGrpAppEncrypted }} + isDeployment: true + deploy-code: if: ${{ inputs.initialDeployment == 'true' }} + needs: [build-frontend-deployment] name: Slot Code Deployment uses: ./.github/workflows/sub-deploy-code.yml with: @@ -50,6 +67,7 @@ jobs: secrets: inherit # pragma: allowlist secret deploy-webapp-slot: + needs: [build-frontend-deployment] runs-on: ubuntu-latest environment: ${{ inputs.ghaEnvironment }} steps: