Azure / static-web-apps-cli

Azure Static Web Apps CLI ✨
https://aka.ms/swa/cli-local-development
MIT License
600 stars 119 forks source link

deploy command does not actually deploy #603

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hi,

trying to deploy my already-built angular application to azure static web site with pwsh script from ubuntu OS in my container which will run as deploy container in our azure devops pipeline. I'm using following instructions

        az login --service-principal -u $armClientId -p $armClientSecret --tenant $armTenantId -o none
        $deploymentToken = az staticwebapp secrets list --name $staticWebSiteName --query "properties.apiKey"
        swa init --yes
        swa deploy --env production `
            --deployment-token $deploymentToken `
            --resource-group $rgName `
            --app-name $staticWebSiteName `
            --app-location $artifactPath `
            --no-use-keychain `
            --verbose=silly

Expected behavior I expect that my angular frontend in $artifactPath will be packed to zip and then uploaded to azure static web app instance $staticWebSiteName and if not command writes into console what is wrong and returns non-zero code. What actually happens is that i get following console output

Welcome to Azure Static Web Apps CLI (1.0.3)

Detected configuration for your app:
- Framework(s): Static HTML
- App location: artifact
- Output location: .
- API location: 
- App build command: 
- API build command: 
- App dev server command: 
- App dev server URL: 

Configuration successfully saved to swa-cli.config.json.

Get started with the following commands:
- Use swa start to run your app locally.
- Use swa deploy to deploy your app to Azure.

Welcome to Azure Static Web Apps CLI (1.0.3)

Getting config file options from swa-cli.config.json...
Changed directory to /workspaces/ci-deploy-image
Using configuration "ci-deploy-image" from file:
  /workspaces/ci-deploy-image/swa-cli.config.json

Deploying front-end files from folder:
  /workspaces/ci-deploy-image/artifact

Deployment token provided via flag
 - --deployment-token: <hidden>

Deploying to environment: production

Trying to read workflow config with values:
 - appLocation: /workspaces/ci-deploy-image/artifact
 - outputLocation: /workspaces/ci-deploy-image/artifact
 - apiLocation: <undefined>
No workflow config folder found at /workspaces/ci-deploy-image/artifact/.github/workflows
Validating user workflow config (BEFORE):
 - appLocation: /workspaces/ci-deploy-image/artifact
 - outputLocation: /workspaces/ci-deploy-image/artifact
 - apiLocation: <undefined>
Validating user workflow config (AFTER):
 - appLocation: /workspaces/ci-deploy-image/artifact
 - apiLocation: <undefined>
 - outputLocation: /workspaces/ci-deploy-image/artifact
Loading staticwebapp.config.json schema...
Schema loaded successfully from https://json.schemastore.org/staticwebapp.config.json
Compiling schema...
Reading content from staticwebapp.config.json...
Parsing staticwebapp.config.json...
Validating staticwebapp.config.json...
File validated successfully. Continuing with configuration!
Content parsed successfully

Found configuration file:
  /workspaces/ci-deploy-image/artifact/staticwebapp.config.json

Deploying project to Azure Static Web Apps...
Fetching release metadata for version: stable. Please wait...
 - version: stable
 - buildId: 1.0.020981
 - publishDate: 2022-09-29T17:37:34.4094014Z
- files:
 - linux-x64:
   - url: https://swalocaldeploy.azureedge.net/downloads/1.0.020981/linux/StaticSitesClient
   - sha: e55db21d0720a12098804559152303e66846bdd94c13a30b30be29a0fc9ae366
 - win-x64:
   - url: https://swalocaldeploy.azureedge.net/downloads/1.0.020981/windows/StaticSitesClient.exe
   - sha: 4e4eb72aef26641e236c24929c822500e956bda099ca78054112cadf20261107
 - osx-x64:
   - url: https://swalocaldeploy.azureedge.net/downloads/1.0.020981/macOS/StaticSitesClient
   - sha: e0f2ae7ec297510a1b3b9332c0dc0dd962a51adb8ea13cd4f3746d79fc24a7e9
Local client binary is up to date. Skipping download.
Deploying using /root/.swa/deploy/1.0.020981/StaticSitesClient@1.0.020981
Deploying using the following options:
- env:
  - SWA_CLI_DEBUG: silly
  - SWA_RUNTIME_WORKFLOW_LOCATION: <undefined>
  - SWA_RUNTIME_CONFIG_LOCATION: /workspaces/ci-deploy-image/artifact
  - SWA_RUNTIME_CONFIG: /workspaces/ci-deploy-image/artifact/staticwebapp.config.json
  - SWA_CLI_VERSION: 1.0.3
  - SWA_CLI_DEPLOY_DRY_RUN: false
  - SWA_CLI_DEPLOY_BINARY: /root/.swa/deploy/1.0.020981/StaticSitesClient@1.0.020981
  - DEPLOYMENT_ACTION: upload
  - DEPLOYMENT_PROVIDER: SwaCli
  - REPOSITORY_BASE: /workspaces/ci-deploy-image/artifact
  - SKIP_APP_BUILD: true
  - SKIP_API_BUILD: true
  - DEPLOYMENT_TOKEN: <hidden>
  - APP_LOCATION: /workspaces/ci-deploy-image/artifact
  - API_LOCATION: <undefined>
  - CONFIG_FILE_LOCATION: /workspaces/ci-deploy-image/artifact
  - VERBOSE: true
ℹ DeploymentId: aa230ca8-5a63-4791-bc0d-8986db8672ef
ℹ 
ℹ Verbose logging enabled
ℹ 
ℹ For further information, please visit the Azure Static Web Apps documentation at https://docs.microsoft.com/en-us/azure/static-web-apps/

but nothing is updated on azure static web app instance i deploy to and yet i get 0 return code signalizing everything is ok...

Additional context ubuntu 22.04, nodejs v18.12.1, npm 8.19.2 installed with

RUN apt-get install -y nodejs="18.12.1-*" && \
    npm install -g @azure/static-web-apps-cli
RUN apt-get install -y libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb libsecret-1-0

Any help really appreciated...

wldevries commented 1 year ago

I have the same experience on Windows 10 22H2 with node v14.21.1 and npm 9.1.2 with a svelte app and a .net functions api app. Everything builds fine, there are no error messages, but nothing is deployed.

kevin-george-ul commented 1 year ago

Came here having the exact same problem, adding my redacted logs

swa deploy --verbose=silly  --env production

Welcome to Azure Static Web Apps CLI (1.0.3)

Getting config file options from swa-cli.config.json...
Changed directory to C:\Users\xxxxx\Desktop\Project
Using configuration "Project" from file:
  C:\Users\xxxxx\Desktop\Project\swa-cli.config.json

Deploying front-end files from folder:
  C:\Users\xxxxx\Desktop\Project\public

No deployment token found. Trying interactive login...
Checking Azure session...
Executing authenticateWithAzureIdentity
- details:
  - tenantId: xxxxxxxx
  - clientId: <undefined>
  - clientSecret: <undefined>
 - useKeychain: true
Keychain is enabled
Executing swaCliPersistencePlugin
Executing before cache access plugin
Machine ID: <hidden>
Invoking crypto service
Getting credentials
Getting credentials from native keychain
Getting keychain reference
isKeychainEnabled: true
KeychainCache: undefined
Attempting to load native keychain
Got native keychain reference
Got native keychain reference
Got credentials from native keychain: <hidden>
Credentials found in native keychain
Credentials is chunked. Reading all chunks...
Got all chunks successfully
Credentials: <hidden>
Decrypting credentials
Decrypted credentials: <hidden>
Credentials content: <hidden>
Credentials: <hidden>
Before cache access plugin. Done.
Executing after cache access plugin
Machine ID: <hidden>
Invoking crypto service
Did TokenCacheContext cache changed: false
After cache access plugin. Done.
✔ Successfully logged into Azure!
Selected tenant: xxxxxxxx
Selected subscription: my-sub-id
Project credentials:
 - subscriptionId: my-sub-id
 - tenantId: xxxxxxxx
 - clientId: <undefined>
 - clientSecret: <undefined>
Login successful

Checking project "demo-static-website-html-only" settings...
Looking for project "demo-static-website-html-only"...
Static site found!
- staticSite:
  - id: /subscriptions/my-sub-id/resourceGroups/my-rg/providers/Microsoft.Web/staticSites/demo-static-website-html-only
  - name: demo-static-website-html-only
  - location: East US 2
  - type: Microsoft.Web/staticSites
 - tags:
   -  Owner: xxxx-xxxx
   - Environment: Sandbox
   - Owner: xxxx-xxxx
 - sku:
   - name: Free
   - tier: Free
  - defaultHostname: green-forest-xxxxxxxx.2.azurestaticapps.net
  - repositoryUrl:
  - branch:
 - customDomains:
 - privateEndpointConnections:
  - stagingEnvironmentPolicy: Enabled
  - allowConfigFileUpdates: true
  - contentDistributionEndpoint: https://content-eus2.infrastructure.2.azurestaticapps.net
  - keyVaultReferenceIdentity: SystemAssigned
 - userProvidedFunctionApps:
  - provider: None
  - enterpriseGradeCdnStatus: Disabled
Project settings:
 - resourceGroupName: my-rg
 - staticSiteName: demo-static-website-html-only
 - subscriptionId: my-sub-id
✔ Successfully setup project!
Saving project settings to swa-cli.config.json...
Updating configuration file at C:\Users\xxxxx\Desktop\Project\swa-cli.config.json
Loading existing swa-cli.config.json file at C:\Users\xxxxx\Desktop\Project\swa-cli.config.json

Deployment token provided via remote configuration
 - deploymentToken: <hidden>

Deploying to environment: production

Trying to read workflow config with values:
 - appLocation: C:\Users\xxxxx\Desktop\Project
 - outputLocation: C:\Users\xxxxx\Desktop\Project\public
 - apiLocation: <undefined>
No workflow config folder found at C:\Users\xxxxx\Desktop\Project\.github\workflows
Validating user workflow config (BEFORE):
 - appLocation: C:\Users\xxxxx\Desktop\Project
 - outputLocation: C:\Users\xxxxx\Desktop\Project\public
 - apiLocation: <undefined>
Validating user workflow config (AFTER):
 - appLocation: C:\Users\xxxxx\Desktop\Project
 - apiLocation: <undefined>
 - outputLocation: C:\Users\xxxxx\Desktop\Project\public
Writing configuration "Project" to swa-cli.config.json
 - outputLocation: public
 - appName: demo-static-website-html-only
 - resourceGroupName: my-rg
Loading staticwebapp.config.json schema...
Schema loaded successfully from https://json.schemastore.org/staticwebapp.config.json
Compiling schema...
Reading content from staticwebapp.config.json...
Parsing staticwebapp.config.json...
Validating staticwebapp.config.json...
File validated successfully. Continuing with configuration!
Content parsed successfully

Found configuration file:
  C:\Users\xxxxx\Desktop\Project\public\staticwebapp.config.json

Deploying project to Azure Static Web Apps...
Fetching release metadata for version: stable. Please wait...
 - version: stable
 - buildId: 1.0.020981
 - publishDate: 2022-09-29T17:37:34.4094014Z
- files:
 - linux-x64:
   - url: https://swalocaldeploy.azureedge.net/downloads/1.0.020981/linux/StaticSitesClient
   - sha: e55db21d0720a12098804559152303e66846bdd94c13a30b30be29a0fc9ae366
 - win-x64:
   - url: https://swalocaldeploy.azureedge.net/downloads/1.0.020981/windows/StaticSitesClient.exe
   - sha: 4e4eb72aef26641e236c24929c822500e956bda099ca78054112cadf20261107
 - osx-x64:
   - url: https://swalocaldeploy.azureedge.net/downloads/1.0.020981/macOS/StaticSitesClient
   - sha: e0f2ae7ec297510a1b3b9332c0dc0dd962a51adb8ea13cd4f3746d79fc24a7e9
Local client binary is up to date. Skipping download.
Deploying using C:\Users\xxxxx\.swa\deploy\1.0.020981\StaticSitesClient.exe@1.0.020981
Deploying using the following options:
- env:
  - SWA_CLI_DEBUG: silly
  - SWA_RUNTIME_WORKFLOW_LOCATION: <undefined>
  - SWA_RUNTIME_CONFIG_LOCATION: C:\Users\xxxxx\Desktop\Project\public
  - SWA_RUNTIME_CONFIG: C:\Users\xxxxx\Desktop\Project\public\staticwebapp.config.json
  - SWA_CLI_VERSION: 1.0.3
  - SWA_CLI_DEPLOY_DRY_RUN: false
  - SWA_CLI_DEPLOY_BINARY: C:\Users\xxxxx\.swa\deploy\1.0.020981\StaticSitesClient.exe@1.0.020981
  - DEPLOYMENT_ACTION: upload
  - DEPLOYMENT_PROVIDER: SwaCli
  - REPOSITORY_BASE: C:\Users\xxxxx\Desktop\Project
  - SKIP_APP_BUILD: true
  - SKIP_API_BUILD: true
  - DEPLOYMENT_TOKEN: <hidden>
  - APP_LOCATION: C:\Users\xxxxx\Desktop\Project\public
  - API_LOCATION: <undefined>
  - CONFIG_FILE_LOCATION: C:\Users\xxxxx\Desktop\Project\public
  - VERBOSE: true
ℹ DeploymentId: 1f1fd888-448d-442f-a937-c5c068ad1fdb
ℹ
ℹ Verbose logging enabled
ℹ Build timeout not specified, defaulting to 15 minutes
ℹ App Directory Location: 'C:\Users\xxxxx\Desktop\Project\public' was found.
ℹ config_file_location: config file 'C:\Users\xxxxx\Desktop\Project\public\staticwebapp.config.json' was found.
ℹ Looking for event info
ℹ Could not get event info. Proceeding
ℹ Skipping step to build C:\Users\xxxxx\Desktop\Project\public with Oryx
ℹ No Api directory specified. Azure Functions will not be created.
ℹ Didn't find Oryx manifest file under location: C:\Users\xxxxx\Desktop\Project\ss-oryx\app-manifest\oryx-manifest.toml
ℹ Determined default file to be: index.html
ℹ Using 'staticwebapp.config.json' file for configuration information, 'routes.json' will be ignored.
ℹ Either no Api directory was specified, or the specified directory was not found. Azure Functions will not be created.
ℹ 
ℹ For further information, please visit the Azure Static Web Apps documentation at https://docs.microsoft.com/en-us/azure/static-web-apps/
ℹ If you believe this behavior is unexpected, please raise a GitHub issue at https://github.com/azure/static-web-apps/issues/
kevin-george-ul commented 1 year ago

If it helps, I just realized that I have a lot of HTML files (8K) ~ 350MB, would this be a reason the zip file is never generated?

wldevries commented 1 year ago

I have a similar scenario with a lot of .png files. edit: I have around 1500 files, but the total size is closer to 25 MB

kgeorge314 commented 1 year ago

I missed this, but looks like there are limits https://learn.microsoft.com/en-us/azure/static-web-apps/quotas.

image
kevin-george-ul commented 1 year ago

I created a new issue #611 , @wldevries feel free to add your feedback there too.

wldevries commented 1 year ago

I think my problem is unrelated to the maximum app size, I'm not even close to 250 MB.

kgeorge314 commented 1 year ago

Exactly, it's not file size it's volume of files which is why I created #611. It looks like it doesn't get to the zipping stage or fails around there.

ghost commented 1 year ago

I do not think it's related either. @kgeorge314 - your issue produces different log so it may be completely different root cause... While in my case staticSiteClient binary does nothing (nothing functional in log after Verbose logging enabled) in your case log indicates, that some functionality is invoked...

I'd like to investigate it further myself, however staticSiteClient is black-box. Publishing its repository might be helpful...

sgollapudi77 commented 1 year ago

Hey @enudeploy, we recently made changes to StaticSiteClient to generate more error logs, can you please try running the command and check again. Meanwhile please feel free to track the issue at #557 . Thanks.

ghost commented 1 year ago

Hi @sgollapudi77,

output is still the same. However, i also see that version is still the same - SWA_CLI_VERSION: 1.0.3 and SWA_CLI_DEPLOY_BINARY: /root/.swa/deploy/1.0.020981/StaticSitesClient@1.0.020981 as in the original post...

How can i use newer version on staticSitesClient binary (swa cli 1.0.3 seems to be the latest one) to check extended logs?

sgollapudi77 commented 1 year ago

Hey @enudeploy, the changes are deployed to preview version or "latest" StaticSiteClient image as you can see from here. For using the latest image you can set the environment variable SWA_CLI_DEPLOY_BINARY_VERSION to latest or maybe wait a couple of days and these changes will be deployed to stable StaticSiteClient image.

ghost commented 1 year ago

HI @sgollapudi77, thanks. this moved me forward. Now i can see output telling me

✖ deployment_token provided was invalid.
✖ An unknown exception has occurred
✖ Failed to record upload telemtry.

Now it tells me that deployment token is invalid which I do not understand. If you look at the code in the original post, i'm getting the token exactly as in your documentation (https://azure.github.io/static-web-apps-cli/docs/cli/swa-deploy/#deployment-token). I let my script to write it out to console and compared to it to what azure portal shows me (in Manage tokens view) - and it's same. So I do not think this is real root cause, it seems that there' something else causing this. Can you please review the script I'm using - it's in the original post ?

any suggestions?

wldevries commented 1 year ago

Do you have multiple Azure accounts like me? I had trouble signing in and I was wondering if it picked the correct account on all steps. Didn't really get a nice choice to pick the Azure account when setting up, had to log both out.

ghost commented 1 year ago

@wldevries - I have just one service principal for my automation which has all permissions needed - if that's what you meant.

wldevries commented 1 year ago

Ah, I reread your first post and realized you're providing credentials in a different way. Maybe something I should start looking into.. :-)

wldevries commented 1 year ago

I set $env:SWA_CLI_DEPLOY_BINARY_VERSION="latest" and I guess mine is different after all because deploy at silly verbose ends with:

ℹ Cannot deploy to the function app because Function language info isn't provided.
ℹ An unknown exception has occurred

For reference my local.settings.json contains:

{
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
  }
}

Adding a staticwebapp.config.json to the root of my app with contents { "platform": { "apiRuntime": "dotnet-isolated:7.0" } } fixed my problem. Odd thing is that it still ends with the following, even though the app was deployed. It seems the API is missing though. Can't be sure, it returns 404 and I can't check what files were actually deployed.

ℹ Deployment Complete :)
ℹ An unknown exception has occurred
ghost commented 1 year ago

@wldevries -

Ah, I reread your first post and realized you're providing credentials in a different way. Maybe something I should start looking into.. :-)

I'm not sure if this is correct approach or I should use swa login command explicitly...

sgollapudi77 commented 1 year ago

Thanks for reporting this @wldevries , we have made fix for this and it will reflect in the next version of StaticSiteClient.

ghost commented 1 year ago

Hi @sgollapudi77 - any update please?

sgollapudi77 commented 1 year ago

Hey @enudeploy, I'm guessing what might have been wrong here, while deploying using deployment_token, can you try removing the appName, resourceGroupName and just deploy using deployment token like this swa deploy --env production --deployment-token $deploymentToken

ghost commented 1 year ago

ok. so problem solved. there were actually two stupid problems in my case

  1. since i experimented with deploying to static web app from git repo before, my static web app was still linked to this repo, which swa cli obviously does not like, so i had to unlink it.
  2. your documentation at https://azure.github.io/static-web-apps-cli/docs/cli/swa-deploy/#deployment-token shows example for getting the token as az staticwebapp secrets list --name <application-name> --query "properties.apiKey" which doesn't work as it does not remove quotation marks - this leads to invalid token exception... Correct command is az staticwebapp secrets list --name <application-name> --query "properties.apiKey" -o tsv
sgollapudi77 commented 1 year ago

We're glad that you are able to resolve this issue. Thanks @enudeploy for reporting the small change as well. We'll update the documentation.