Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
332 stars 57 forks source link

Transformed Files Not Getting Uploaded to Static Web App #1094

Open crosscuttech opened 1 year ago

crosscuttech commented 1 year ago

I'm attempting to deploy a Blazor WASM app to an Azure Static Web App. I've got a working pipeline that will Restore/Build/Test/Publish my Blazor project and a Release pipeline that will take the published artifact and deploy it to various development/test/stage environments. Within the Release pipeline, I need to update a key in my appsettings.json for each targeted environment. This is what my committed appsettings.json looks like:

{ "HttpClient": { "BaseAddress": "" } }

For my release pipeline, I have the following tasks for my Agent Job:

  1. Extract the files from the artifact zip.
  2. Transform the extracted appSettings.json using variables
  3. A Powershell script to output the contents of appsettings.json
  4. Deploy to my Azure Static Web App

Each of these tasks appear to complete successfully but the BaseAddress key is blank on deployed code because the application crashes. If I disable the Transform Appsettings step, commit a valid, working URL to the appsettings.json, and deploy that release, everything works. I've also tried swapping around the extract and transforms steps and that doesn't seem to work either.

Here's the YML for the tasks in the Release pipeline:

steps:
- task: ExtractFiles@1
    displayName: 'Extract files '
    inputs:
    destinationFolder: '$(System.DefaultWorkingDirectory)/blazor'
    overwriteExistingFiles: true
- task: FileTransform@2
    displayName: 'Transform AppSettings'
    inputs:
    folderPath: '$(System.DefaultWorkingDirectory)/blazor'
    jsonTargetFiles: '**/appsettings.json'
- powershell: |
    Get-Content /home/vsts/work/r1/a/blazor/wwwroot/appsettings.json
  displayName: 'PowerShell Script'
- task: AzureStaticWebApp@0
    displayName: 'Static Web App: Blazor WASM'
    inputs:
    workingDirectory: '$(System.DefaultWorkingDirectory)/blazor'
    app_location: /wwwroot
    skip_app_build: true
    skip_api_build: true
    is_static_export: false
    verbose: true
    azure_static_web_apps_api_token: 'XXXXXXXXXX'

Here's the log output from the powershell script:

2023-03-05T23:39:43.1126886Z ##[section]Starting: PowerShell Script
2023-03-05T23:39:43.1135560Z ==============================================================================
2023-03-05T23:39:43.1135890Z Task         : PowerShell
2023-03-05T23:39:43.1136046Z Description  : Run a PowerShell script on Linux, macOS, or Windows
2023-03-05T23:39:43.1136308Z Version      : 2.212.0
2023-03-05T23:39:43.1136459Z Author       : Microsoft Corporation
2023-03-05T23:39:43.1136646Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2023-03-05T23:39:43.1136981Z ==============================================================================
2023-03-05T23:39:43.2459559Z Generating script.
2023-03-05T23:39:43.2507383Z ========================== Starting Command Output ===========================
2023-03-05T23:39:43.2516327Z [command]/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/home/vsts/work/_temp/182f90f5-9857-47fc-ba47-5da7313553be.ps1'
2023-03-05T23:39:45.0275678Z {
2023-03-05T23:39:45.0282721Z     "HttpClient": {
2023-03-05T23:39:45.0283779Z         "BaseAddress": "https://mywebapi.azurewebsites.net/api/"
2023-03-05T23:39:45.0284432Z     }
2023-03-05T23:39:45.0284926Z }
2023-03-05T23:39:45.1639506Z ##[section]Finishing: PowerShell Script

Here's the log from the Static Web App:

2023-03-05T23:39:45.5140370Z ##[section]Starting: Static Web App: Blazor WASM
2023-03-05T23:39:45.5148254Z ==============================================================================
2023-03-05T23:39:45.5148538Z Task         : Deploy Azure Static Web App
2023-03-05T23:39:45.5148715Z Description  : [PREVIEW] Build and deploy an Azure Static Web App
2023-03-05T23:39:45.5149115Z Version      : 0.217.0
2023-03-05T23:39:45.5149285Z Author       : Microsoft Corporation
2023-03-05T23:39:45.5149452Z Help         : https://aka.ms/swadocs
2023-03-05T23:39:45.5149601Z ==============================================================================
2023-03-05T23:39:45.6909319Z [command]/usr/bin/bash /home/vsts/work/_tasks/AzureStaticWebApp_18aad896-e191-4720-88d6-8ced4806941a/0.217.0/launch-docker.sh
2023-03-05T23:39:46.0495094Z stable: Pulling from appsvc/staticappsclient
2023-03-05T23:39:46.0517587Z 6aefca2dc61d: Pulling fs layer
2023-03-05T23:39:46.0519483Z 967757d56527: Pulling fs layer
2023-03-05T23:39:46.0519967Z c357e2c68cb3: Pulling fs layer
2023-03-05T23:39:46.0520583Z c766e27afb21: Pulling fs layer
2023-03-05T23:39:46.0520976Z d913781da675: Pulling fs layer
2023-03-05T23:39:46.0521351Z 54fa687f58b4: Pulling fs layer
2023-03-05T23:39:46.0521724Z c939a09b5983: Pulling fs layer
2023-03-05T23:39:46.0522127Z e198984d5536: Pulling fs layer
2023-03-05T23:39:46.0522501Z 21e57609d6b3: Pulling fs layer
2023-03-05T23:39:46.0522874Z c1881f2146e9: Pulling fs layer
2023-03-05T23:39:46.0523261Z 4bd05412a8e0: Pulling fs layer
2023-03-05T23:39:46.0523634Z 8146c9dfd394: Pulling fs layer
2023-03-05T23:39:46.0524006Z f0ffa7b9e9dc: Pulling fs layer
2023-03-05T23:39:46.0524392Z 1bdd8cf46ef0: Pulling fs layer
2023-03-05T23:39:46.0524761Z 5ee2ffb527ea: Pulling fs layer
2023-03-05T23:39:46.0525179Z 8d112204afe5: Pulling fs layer
2023-03-05T23:39:46.0526090Z 8cfc8710ef27: Pulling fs layer
2023-03-05T23:39:46.0526471Z 6550e89384e0: Pulling fs layer
2023-03-05T23:39:46.0526845Z c766e27afb21: Waiting
2023-03-05T23:39:46.0527183Z d913781da675: Waiting
2023-03-05T23:39:46.0527530Z 54fa687f58b4: Waiting
2023-03-05T23:39:46.0527879Z c939a09b5983: Waiting
2023-03-05T23:39:46.0528213Z e198984d5536: Waiting
2023-03-05T23:39:46.0528596Z 21e57609d6b3: Waiting
2023-03-05T23:39:46.0528948Z c1881f2146e9: Waiting
2023-03-05T23:39:46.0529287Z 4bd05412a8e0: Waiting
2023-03-05T23:39:46.0529621Z 8146c9dfd394: Waiting
2023-03-05T23:39:46.0529969Z f0ffa7b9e9dc: Waiting
2023-03-05T23:39:46.0530350Z 1bdd8cf46ef0: Waiting
2023-03-05T23:39:46.0530686Z 5ee2ffb527ea: Waiting
2023-03-05T23:39:46.0531036Z 8d112204afe5: Waiting
2023-03-05T23:39:46.0531493Z 8cfc8710ef27: Waiting
2023-03-05T23:39:46.0531789Z 6550e89384e0: Waiting
2023-03-05T23:39:46.1923428Z 967757d56527: Verifying Checksum
2023-03-05T23:39:46.1923848Z 967757d56527: Download complete
2023-03-05T23:39:46.2342464Z c357e2c68cb3: Verifying Checksum
2023-03-05T23:39:46.2343448Z c357e2c68cb3: Download complete
2023-03-05T23:39:46.4775370Z 6aefca2dc61d: Verifying Checksum
2023-03-05T23:39:46.4775848Z 6aefca2dc61d: Download complete
2023-03-05T23:39:46.6319540Z c766e27afb21: Verifying Checksum
2023-03-05T23:39:46.6319980Z c766e27afb21: Download complete
2023-03-05T23:39:46.8927796Z 54fa687f58b4: Verifying Checksum
2023-03-05T23:39:46.8928238Z 54fa687f58b4: Download complete
2023-03-05T23:39:47.0045143Z e198984d5536: Verifying Checksum
2023-03-05T23:39:47.0045582Z e198984d5536: Download complete
2023-03-05T23:39:47.1783261Z c939a09b5983: Verifying Checksum
2023-03-05T23:39:47.1783751Z c939a09b5983: Download complete
2023-03-05T23:39:47.1968113Z 21e57609d6b3: Verifying Checksum
2023-03-05T23:39:47.1973397Z 21e57609d6b3: Download complete
2023-03-05T23:39:47.2414868Z 4bd05412a8e0: Verifying Checksum
2023-03-05T23:39:47.2420001Z 4bd05412a8e0: Download complete
2023-03-05T23:39:47.2526254Z c1881f2146e9: Verifying Checksum
2023-03-05T23:39:47.2526603Z c1881f2146e9: Download complete
2023-03-05T23:39:47.4776618Z f0ffa7b9e9dc: Verifying Checksum
2023-03-05T23:39:47.4778800Z f0ffa7b9e9dc: Download complete
2023-03-05T23:39:48.1049522Z 1bdd8cf46ef0: Verifying Checksum
2023-03-05T23:39:48.1053663Z 1bdd8cf46ef0: Download complete
2023-03-05T23:39:48.3939994Z d913781da675: Verifying Checksum
2023-03-05T23:39:48.3940578Z d913781da675: Download complete
2023-03-05T23:39:48.4640077Z 8d112204afe5: Verifying Checksum
2023-03-05T23:39:48.4642746Z 8d112204afe5: Download complete
2023-03-05T23:39:48.5397256Z 8cfc8710ef27: Verifying Checksum
2023-03-05T23:39:48.5404596Z 8cfc8710ef27: Download complete
2023-03-05T23:39:48.6305170Z 6550e89384e0: Verifying Checksum
2023-03-05T23:39:48.6305559Z 6550e89384e0: Download complete
2023-03-05T23:39:48.7280455Z 5ee2ffb527ea: Verifying Checksum
2023-03-05T23:39:48.7280875Z 5ee2ffb527ea: Download complete
2023-03-05T23:39:50.3348431Z 6aefca2dc61d: Pull complete
2023-03-05T23:39:51.1797565Z 8146c9dfd394: Verifying Checksum
2023-03-05T23:39:51.1798043Z 8146c9dfd394: Download complete
2023-03-05T23:39:53.1688980Z 967757d56527: Pull complete
2023-03-05T23:39:53.5303034Z c357e2c68cb3: Pull complete
2023-03-05T23:39:56.3730649Z c766e27afb21: Pull complete
2023-03-05T23:40:02.4359870Z d913781da675: Pull complete
2023-03-05T23:40:02.9137746Z 54fa687f58b4: Pull complete
2023-03-05T23:40:04.9686522Z c939a09b5983: Pull complete
2023-03-05T23:40:05.0328523Z e198984d5536: Pull complete
2023-03-05T23:40:05.1487924Z 21e57609d6b3: Pull complete
2023-03-05T23:40:05.2411504Z c1881f2146e9: Pull complete
2023-03-05T23:40:05.3372466Z 4bd05412a8e0: Pull complete
2023-03-05T23:40:17.9819929Z 8146c9dfd394: Pull complete
2023-03-05T23:40:18.4726913Z f0ffa7b9e9dc: Pull complete
2023-03-05T23:40:22.7168362Z 1bdd8cf46ef0: Pull complete
2023-03-05T23:40:23.6160344Z 5ee2ffb527ea: Pull complete
2023-03-05T23:40:23.6745935Z 8d112204afe5: Pull complete
2023-03-05T23:40:23.7487156Z 8cfc8710ef27: Pull complete
2023-03-05T23:40:23.8086989Z 6550e89384e0: Pull complete
2023-03-05T23:40:23.8160241Z Digest: sha256:6e8c2f7004cfd75ccbf2d1f5a402999432989eecd692d5536d47d46a07bb22ff
2023-03-05T23:40:23.8186497Z Status: Downloaded newer image for mcr.microsoft.com/appsvc/staticappsclient:stable
2023-03-05T23:40:24.2362836Z DeploymentId: 928d8805-9e31-4fb4-8cfa-67f6054cdb83
2023-03-05T23:40:24.2363158Z 
2023-03-05T23:40:24.3408046Z Verbose logging enabled
2023-03-05T23:40:24.3837946Z Build timeout not specified, defaulting to 15 minutes
2023-03-05T23:40:24.3838808Z App Directory Location: '/wwwroot' was found.
2023-03-05T23:40:24.3844883Z Looking for event info
2023-03-05T23:40:24.3850704Z Could not get event info. Proceeding
2023-03-05T23:40:25.1528868Z Skipping step to build /working_dir/wwwroot with Oryx
2023-03-05T23:40:25.1541545Z ##[warning]Could not find staticwebapp.config.json file.
2023-03-05T23:40:25.1549140Z Didn't find Oryx manifest file under location: /928d8805-9e31-4fb4-8cfa-67f6054cdb83-swa-oryx/app-manifest/oryx-manifest.toml
2023-03-05T23:40:25.1629334Z Determined default file to be: index.html
2023-03-05T23:40:25.2486089Z No Api directory specified. Azure Functions will not be created.
2023-03-05T23:40:25.2790800Z ##[warning]Either no Api directory was specified, or the specified directory was not found. Azure Functions will not be created.
2023-03-05T23:40:25.6216703Z Zipping App Artifacts
2023-03-05T23:40:25.6217681Z App Zip will be created from directory: /working_dir/wwwroot
2023-03-05T23:40:26.7127488Z Done Zipping App Artifacts
2023-03-05T23:40:26.7127971Z Uploading build artifacts.
2023-03-05T23:40:27.7658092Z Skipping function upload as functions are identical to last successful deployment.
2023-03-05T23:40:28.1396764Z ##[section]Finished Upload. Polling on deployment.
2023-03-05T23:40:28.2254368Z Status: InProgress. Time: 0.0855073(s)
2023-03-05T23:40:43.3045574Z Status: Succeeded. Time: 15.1647466(s)
2023-03-05T23:40:43.3046637Z ##[section]Deployment Complete :)
2023-03-05T23:40:43.3047809Z ##[section]Visit your site at: https://mywebappui.azurestaticapps.net
2023-03-05T23:40:43.3822398Z Thanks for using Azure Static Web Apps!
2023-03-05T23:40:43.3823354Z Exiting
2023-03-05T23:40:43.5339474Z ##[section]Finishing: Static Web App: Blazor WASM
crosscuttech commented 1 year ago

As a work around:

Create a new Storage Account in Azure with a Static Site. In Devops, disable the AzureStaticWebApp@0 task in the Release Pipeline. Add a AzureFileCopy@3 Task in exactly the same spot (after the file transformations). Point the AzureFileCopy@3 Task to the new Storage site.

Once I did that, my code is getting uploaded with the proper file transformations.