无法使用Azure管道将Remix应用部署到Azure应用服务

uinbv5nw  于 2023-06-30  发布在  其他
关注(0)|答案(1)|浏览(118)

我有一个使用Remix App Server模板构建的混音应用程序。我正在尝试使用Azure应用服务构建它。问题是“build”命令会生成一个.cache文件夹,并且只有在复制该文件夹时才有权限问题。目标是在构建部署之后运行“npm run start”。
这是我的YML。

# Node.js Express Web App to Linux on Azure
# Build a Node.js Express app and deploy it to Azure as a Linux web app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- development

variables:

  # Azure Resource Manager connection created during pipeline creation
  azureSubscription: <subscription_id>

  # Web app name
  webAppName: 'remix'

  # Environment name
  environmentName: 'remix-app'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

  # PNPM Cache Location
  pnpm_config_cache: $(Pipeline.Workspace)/.pnpm-store

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)

    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '18.x'
      displayName: 'Install Node.js'

    - task: Cache@2
      inputs:
        key: 'pnpm | "$(Agent.OS)" | pnpm-lock.yaml'
        path: $(pnpm_config_cache)
      displayName: Cache pnpm

    - script: |
        corepack enable
        corepack prepare pnpm@latest-8 --activate
        pnpm config set store-dir $(pnpm_config_cache)
      displayName: "Setup pnpm"

    - script: |
        pnpm install
        pnpm run build
      displayName: 'pnpm install, build'

    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      artifact: drop

- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: $(environmentName)
    pool:
      vmImage: $(vmImageName)
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureWebApp@1
            displayName: 'Azure Web App Deploy: remix'
            inputs:
              azureSubscription: $(azureSubscription)
              appType: webAppLinux
              appName: $(webAppName)
              runtimeStack: 'NODE|18'
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
              startUpCommand: 'npm run start'

这就是我得到的错误。

cnh2zyt3

cnh2zyt31#

我克隆了这个repository,我使用了Node.js React应用程序和Azure Web应用程序,因为react的remix效果更好。

  • 选择您的Web应用程序并运行yaml管道:-*
trigger:
- main

variables:

 
  azureSubscription: 'azuresubscription-id'

  # Web app name
  webAppName: 'siliconwebapp1'

  # Environment name
  environmentName: 'siliconwebapp1'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)

    steps:
    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      artifact: drop

- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: $(environmentName)
    pool:
      vmImage: $(vmImageName)
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureRmWebAppDeployment@4
            displayName: 'Azure App Service Deploy: siliconwebapp1'
            inputs:
              azureSubscription: $(azureSubscription)
              appType: webAppLinux
              WebAppName: $(webAppName)
              packageForLinux: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
              RuntimeStack: 'NODE|10.10'
              StartupCommand: 'npm run start'
              ScriptType: 'Inline Script'
              InlineScript: |
                npm install
                npm run build --if-present

上述方法不包括任何缓存任务或复制文件。但是在你的任务中你可以添加:-

- script: | 
    pnpm install 
    npm run build
    rm -rf .cache 
 displayName: 'pnpm install, build, and delete .cache folder'

在执行归档任务之前删除该高速缓存文件。

如果您遇到任何与依赖项相关的问题,请确保通过npm命令更新这些包。首先使用npm run setupnpm run dev命令在本地运行代码。如果应用程序在本地运行,请将代码推送到Azure DevOps管道中,然后再次运行。

相关问题