How to disable Oryx builds for Node.js project in Azure App Service?

Maksym Petrenko 100 Reputation points
2023-10-20T13:38:06.2766667+00:00

Hello. On our project, we are deploying a Next.js app to a F1 Tier Linux instance of an App Service via Github Actions. We create a production-ready build using output: standalone of Next.js, which does not require npm i or npm build steps to be boot up. However, on the Azure side, the Oryx builder takes over the deployment and calls the above-mentioned commands which bloat the instance with ±300mb of unnecessary Node dependencies and increase the build time.

The solution would be to tell Oryx to not build the project, or to disable Oryx altogether. However, neither option is possible as Oryx seems to ignore the Application Settings that are meant to alter its behaviour as per these docs:

https://github.com/microsoft/Oryx/blob/main/doc/configuration.md

https://github.com/microsoft/Oryx/blob/main/doc/hosts/appservice.md

Here are the Settings from our Azure panel. The green ones are available to the application, while the red, Oryx-related ones have no effect (for all of them both 0/1 and true/false values were tried)
Azure Settings

Apparently, this issue is not new, as noted in this question: https://learn.microsoft.com/en-us/answers/questions/757750/azure-function-apps-oryx-build-continues-to-run-ev. However, the solutions that worked for Azure Functions then has no effect in our case.

Could somebody indicate what we are possibly missing with this issue, and how to fix this behaviour? Thank you in advance

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,154 questions
{count} votes

Accepted answer
  1. Maksym Petrenko 100 Reputation points
    2023-10-22T05:25:56.9866667+00:00

    Thanks for the suggestion. However, we did not need to test it out as, fortunately for us, the issue resolved itself after we tried creating a new F1 tier Linux Web App resource without any Settings, where the Kudu build system took over the deployment and worked just fine without any config by unpacking the zip artifact and running it.

    I'd like to note some other features of our setup that might have affected the behaviour of Oryx (might be useful for people that encounter similar problem, or for Azure maintainers who will look into the issue of Oryx being ignorant to env variables):

    • The service was first created as a B1 tier instance
    • Subsequently, the pipeline settings (Github Actions) were set at service creation time, and we used the .yml config file for actions that Azure has automatically created for us.

    Also, I want to share our Github Action responsible for deployment in case somebody finds it useful, as it allows to fit a simple Next.js app into a F1 Tier instance regardless of whether an excessive npm i + npm run build step occurs or not (i.e. whether it is Oryx or Kudu that deploys the code):

    name: Build and deploy Node.js app to Azure Web App - ***
    
    on:
      push:
        branches:
          - main
      workflow_dispatch:
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - uses: actions/checkout@v4
          
          - name: Set up Node.js version
            uses: actions/setup-node@v1
            with:
              node-version: '>=18.12.0' # Requirement in our case, may be different in yours
    
          - name: Build in standalone mode
            working-directory: ./<work_dir_name>
            env: # Github repo secrets
              NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
              NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
            run: |
              CI=true npm install
              npm run build
          
          - name: Copy non-source files into the standalone build folder
            working-directory: ./<work_dir_name>
            run: |
              cp -r public .next/standalone/public
              cp -r .next/static .next/standalone/.next/static
          # AS it is currently impossible to alter the behaviour of Web App builder, it is necessary to remove Dev- and build-time-specific scripts as they will crash in CI, and remove devDeps to make the final release slimmer.     
          - name: Modify standalone build package.json 
            working-directory: ./<work_dir_name>/.next/standalone
            run: |
              npm pkg delete scripts.postinstall scripts.prepare devDependencies
              npm pkg set scripts.start="node server.js" scripts.build="echo \"Using results of a pipeline build\" "
      
          - name: Zip standalone folder into a deployment artifact
            working-directory: ./<work_dir_name>  
            run: cd .next/standalone && zip ../../release.zip * .next -qr
    
          - name: Upload artifact for deployment job
            uses: actions/upload-artifact@v3
            with:
              name: node-app
              path: ./<work_dir_name>/release.zip
    
      deploy:
        runs-on: ubuntu-latest
        needs: build
        environment:
          name: 'Production'
          url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    
        steps:
          - name: Download artifact from build job
            uses: actions/download-artifact@v3
            with:
              name: node-app
    
          - name: 'Deploy to Azure Web App'
            id: deploy-to-webapp
            uses: azure/webapps-deploy@v2
            with:
              app-name: *** # Your app name in Azure
              slot-name: *** # Most likely 'Production'
              publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_*** }}
              package: release.zip
          
          - name: Artifact cleanup
            run: rm release.zip
    
    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Thanng PQ 0 Reputation points
    2024-01-04T02:52:36.75+00:00

    You can set "CUSTOM_BUILD_COMMAND" to something else to replace default npm run build command. E.g. just change it to echo "Not doing anything"

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.