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
320 stars 53 forks source link

Azure/static-web-apps-deploy is very slow? #1025

Open onionhammer opened 1 year ago

onionhammer commented 1 year ago

This is somewhat of an inconvenience, but it reliably takes 40 seconds for github actions to download the ~2 gigabyte static web apps deploy action docker image, let alone run it.

It would be great if a slimmer static file upload option were made available for those who have simpler processes (like npm run build, upload dist).

thomasgauvin commented 1 year ago

Thanks for the feedback @onionhammer , this is something the Oryx team is currently working on, so we're looking forward to seeing that change as well. Here's an issue tracking it in the Oryx repo: https://github.com/microsoft/Oryx/issues/1159

onionhammer commented 1 year ago

Hmm. Last public movement on that is a year ago. Why not support developers using their own build system in addition to an oryx version? I don't need oryx to run npm run build it's pure bloat for my use case.

thomasgauvin commented 1 year ago

We're aware that the Oryx image being large increases the download time, and are working with Oryx to resolve this. You also mention that you don't need oryx to run npm run build, and for this, you should be able to prevent those & just upload your built static assets by setting the skip_app_build or skip_app_build flags in your workflow file depending on your needs

onionhammer commented 1 year ago

@thomasgauvin does that save the minute and 40 seconds of downloading the 2gb SWA + oryx image? If not that doesnt help

thomasgauvin commented 1 year ago

@onionhammer skipping the app build is a param of the SWA + oryx image, so it does not reduce the time that it takes to download those https://github.com/Azure/static-web-apps/issues/1067#issuecomment-1423023871

Right now, we're focusing on working with Oryx to reduce the size of the image that gets downloaded (by doing language downloads dynamically instead), which should reduce download times. After that, we'll assess providing a build-less/Oryx-less deployment option or other options to continue to reduce build & deploy times

onionhammer commented 1 year ago

I would love to see the metrics on Oryx, for what percentage of users would be served well by just "upload these files" (i.e. "build-less/oryx-less" option.

I suspect it is sizeable.. perhaps 90%+ people just want to upload static files, or can easily build their files without oryx

thomasgauvin commented 1 year ago

We're looking into providing a deploy-only image for folks who want to configure their pipelines, the Oryx-based build+deploy image is intended to suit every possible project that gets created with SWA without additional configuration

simkuns commented 8 months ago

It is possible to cut down deployment time at least in half by using @azure/static-web-apps-cli instead of AzureStaticWebApp@0 task.

AzureStaticWebApp@0 @azure/static-web-apps-cli

It can be achieved by creating a dummy repository for @azure/static-web-apps-cli e.g. azure-static-web-apps-cli

Screenshot 2023-11-06 at 21 50 24

package.json in dummy repo

{
  "private": true,
  "dependencies": {
    "@azure/static-web-apps-cli": "^1.1.4"
  }
}

deployment.yml

# ...
resources:
  repositories:
  - repository: AzureStaticWebAppsCliRepo
    type: git
    name: azure-static-web-apps-cli/azure-static-web-apps-cli
    ref: master
# ...
jobs:
  - job: deploy
    steps:
      - checkout: AzureStaticWebAppsCliRepo
      - task: Cache@2
        displayName: Cache Yarn
        inputs:
          key: '"azure-static-web-apps-cli" | "yarn_v1" | "$(Agent.OS)" | "node_modules" | yarn.lock'
          path: node_modules
          cacheHitVar: YARN_CACHE_RESTORED
      - script: yarn install --frozen-lockfile
        displayName: yarn install --frozen-lockfile
        condition: ne(variables.YARN_CACHE_RESTORED, 'true')
      # ... (Download build artifacts steps)
      - script: |
          SWA_CLI_DEPLOYMENT_TOKEN=$(SWA_DEPLOYMENT_TOKEN) \
          $(System.DefaultWorkingDirectory)/node_modules/.bin/swa deploy \
          -w . \
          -a .output/public \
          -i .output/server \
          --api-language=node \
          --api-version=18 \
          --env=production
        displayName: Deploy AzureStaticWebApp
onionhammer commented 8 months ago

It shouldn't be the case, but that is not surprising.