static-web-apps-cli icon indicating copy to clipboard operation
static-web-apps-cli copied to clipboard

Default proxy setting is not working for SWA CLI and still download metadata for StaticSitesClient from internet after downloaded & manually configured StaticSitesClient.json

Open JaydeepUniverse opened this issue 1 year ago • 3 comments

swa --version 2.0.2

Are you accessing the CLI from the default port :4280 ?

  • [ ] No, I am using a different port number (--port) and accessing the CLI from that port
  • [Yes ] Yes, I am accessing the CLI from port :4280

Make sure you are accessing the URL printed in the console when running swa start!

swa start

Welcome to Azure Static Web Apps CLI (2.0.2)

***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

Serving static content:
  /home/aaaa

Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.

ℹ️ NOTE: Make sure to enable debug logs when running any swa commands using --verbose=silly Yes

Describe the bug We are trying to deploy static web app from azure vm acting as azure devops agent. Thus, from azure pipeline we are running swa deploy command. Our vm is behind proxy,

hence when running swa cli command its not able to download StaticSitesClient directly. As per https://azure.github.io/static-web-apps-cli/docs/contribute/Troubleshooting#unable-to-download-staticsitesclient-binary-file-not-found-404---403 we have downloaded manually, kept under user home dir. as per suggested path and along with created .json file

pwd
/home/aaaa/.swa/deploy

total 4
drwx------. 2 aaaa  domain users   31 Jan  6 11:34 53b7d0e07fe5c34bf68929fab92f87ce910288dc
-rw-------. 1 aaaa  domain users 1154 Jan  6 11:59 StaticSitesClient.json

ls -l 53b7d0e07fe5c34bf68929fab92f87ce910288dc/
total 69552
-rwx------. 1 aaaa  domain users 71217367 Jan  6 11:34 StaticSitesClient

cat StaticSitesClient.json
{
   "metadata": {
    "version": "stable",
    "buildId": "53b7d0e07fe5c34bf68929fab92f87ce910288dc",
    "publishDate": "2024-10-24T20:43:23.5850191Z",
    "files": {
      "linux-x64": {
        "url": "https://swalocaldeployv2-bndtgugjgqc3dhdx.b01.azurefd.net/downloads/53b7d0e07fe5c34bf68929fab92f87ce910288dc/linux/StaticSitesClient",
        "sha": "66fca4b42cbc64d451097931ca4ed75649233bd818f97f0c3f6d1d75cff61413"
      },
      "win-x64": {
        "url": "https://swalocaldeployv2-bndtgugjgqc3dhdx.b01.azurefd.net/downloads/53b7d0e07fe5c34bf68929fab92f87ce910288dc/windows/StaticSitesClient.exe",
        "sha": "fc949fb19d29cce1e8b74cf1e2c31706426d46b3e03d830d601524cee63faa0b"
      },
      "osx-x64": {
        "url": "https://swalocaldeployv2-bndtgugjgqc3dhdx.b01.azurefd.net/downloads/53b7d0e07fe5c34bf68929fab92f87ce910288dc/macOS/StaticSitesClient",
        "sha": "89ec4fe61217325e89ed849a564ffe4cc51b61c325abdca82e8e441a4959ec92"
      }
    }
  },
   "binary":"/home/aaaa/.swa/deploy/53b7d0e07fe5c34bf68929fab92f87ce910288dc/StaticSitesClient",
   "checksum": "66fca4b42cbc64d451097931ca4ed75649233bd818f97f0c3f6d1d75cff61413"
}

However when running swa deploy command its still going to download metadata and failing while deployment

2025-01-06T12:14:18.8438630Z Fetching release metadata for version: stable. Please wait...
2025-01-06T12:14:18.8442385Z GET https://aka.ms/swalocaldeploy
2025-01-06T12:14:18.9487549Z Could not find release metadata; returning undefined
2025-01-06T12:14:18.9494834Z ✖ 
2025-01-06T12:14:18.9499827Z ✖ Deployment Failed :(
2025-01-06T12:14:18.9504798Z ✖ Deployment Failure Reason: Could not load StaticSitesClient metadata from remote. Please check your internet connection.
2025-01-06T12:14:18.9507266Z ✖ For further information, please visit the Azure Static Web Apps documentation at https://docs.microsoft.com/azure/static-web-apps/
2025-01-06T12:14:18.9510175Z 

We have setup HTTP_PROXY & HTTPS_PROXY as well before running SWA cli commands. But somehow it seems SWA commands are not considering these proxy settings. Because, manually directly from machine when getting from this url using curl command then able to download. ex.

curl -x http://10.10.10.10.:443 -L aka.ms/swalocaldeploy
[
  {
    "version": "latest",
    "buildId": "53b7d0e07fe5c34bf68929fab92f87ce910288dc",
    "publishDate": "2024-10-24T20:43:23.5850191Z",
    "files": {
      "linux-x64": {
        "url": "https://swalocaldeployv2-bndtgugjgqc3dhdx.b01.azurefd.net/downloads/53b7d0e07fe5c34bf68929fab92f87ce910288dc/linux/StaticSitesClient",
        "sha": "66fca4b42cbc64d451097931ca4ed75649233bd818f97f0c3f6d1d75cff61413"
      },
      "win-x64": {
        "url": "https://swalocaldeployv2-bndtgugjgqc3dhdx.b01.azurefd.net/downloads/53b7d0e07fe5c34bf68929fab92f87ce910288dc/windows/StaticSitesClient.exe",
        "sha": "fc949fb19d29cce1e8b74cf1e2c31706426d46b3e03d830d601524cee63faa0b"
      },
      "osx-x64": {
        "url": "https://swalocaldeployv2-bndtgugjgqc3dhdx.b01.azurefd.net/downloads/53b7d0e07fe5c34bf68929fab92f87ce910288dc/macOS/StaticSitesClient",
        "sha": "89ec4fe61217325e89ed849a564ffe4cc51b61c325abdca82e8e441a4959ec92"
      }
    }

Expected behavior

  • Option for SWA commands to consider Proxy configurations
  • After manually downloaded StaticSitesClient and validated configured checksum, then direct deployment should work

JaydeepUniverse avatar Jan 06 '25 13:01 JaydeepUniverse

@JaydeepUniverse I had the same issue. I tried the workaround in 881 but it was still trying to download the metadata from the remote source. I adapted the workaround to just return the local metadata sooner, after line 15 rather than line 30. So, line 15 was:

const localClientMetadata = getLocalClientMetadata();`

Then it becomes:

const localClientMetadata = getLocalClientMetadata();
return {
    binary: localClientMetadata.binary,
    buildId: localClientMetadata.metadata.buildId,
};

It's not a permanent solution but a temporary workaround to allow me to do a test deployment.

jseddon2 avatar May 02 '25 09:05 jseddon2

I can also confirm that I am having the same issue, I suspect that the system CA certificate settings are not being read in by whatever swa is using to fetch the StaticSitesClient.

Similarly the troubleshooting solution presented with placing the binary directly into ~/.swa/deploy/VERSION/ does not work.

SRooke avatar Jun 24 '25 18:06 SRooke

Fixed the issue with :

export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt

SRooke avatar Jun 25 '25 09:06 SRooke