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

huangapple go评论68阅读模式
英文:

Unable to deploy a Remix App to Azure App service using Azure Pipelines

问题

我使用 Remix App Server 模板构建了一个 Remix 应用程序。我正在尝试使用 Azure App Service 构建它。问题在于 "build" 命令生成了一个 .cache 文件夹,而在复制它时出现了权限问题。目标是在部署后运行 "npm run start"。

这是我的 YAML 文件:

# 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'

这是我收到的错误信息。

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

英文:

I have a remix app built using the Remix App Server template. I am trying to build it using Azure App Service. The issue is that "build" command generates a .cache folder and there are issues with permissioning only while copying that. The goal is to run "npm run start" after the build is deployed.

This is my 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: &lt;subscription_id&gt;
# Web app name
webAppName: &#39;remix&#39;
# Environment name
environmentName: &#39;remix-app&#39;
# Agent VM image name
vmImageName: &#39;ubuntu-latest&#39;
# 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: &#39;18.x&#39;
displayName: &#39;Install Node.js&#39;
- task: Cache@2
inputs:
key: &#39;pnpm | &quot;$(Agent.OS)&quot; | pnpm-lock.yaml&#39;
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: &quot;Setup pnpm&quot;
- script: |
pnpm install
pnpm run build
displayName: &#39;pnpm install, build&#39;
- task: ArchiveFiles@2
displayName: &#39;Archive files&#39;
inputs:
rootFolderOrFile: &#39;$(System.DefaultWorkingDirectory)&#39;
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: &#39;Azure Web App Deploy: remix&#39;
inputs:
azureSubscription: $(azureSubscription)
appType: webAppLinux
appName: $(webAppName)
runtimeStack: &#39;NODE|18&#39;
package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
startUpCommand: &#39;npm run start&#39;

This is the error I get.

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

答案1

得分: 1

我克隆了这个存储库,我使用了 Node.js React 应用程序,并将 Azure Web 应用程序作为 remix 与 react 更好地配合使用。

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

选择您的 Web 应用程序并运行 yaml 管道:

trigger:
- main

variables:

 
  azureSubscription: &#39;azuresubscription-id&#39;

  # Web 应用程序名称
  webAppName: &#39;siliconwebapp1&#39;

  # 环境名称
  environmentName: &#39;siliconwebapp1&#39;

  # 代理 VM 映像名称
  vmImageName: &#39;ubuntu-latest&#39;

stages:
- stage: Build
  displayName: 构建阶段
  jobs:
  - job: Build
    displayName: 构建
    pool:
      vmImage: $(vmImageName)

    steps:
    - task: ArchiveFiles@2
      displayName: &#39;归档文件&#39;
      inputs:
        rootFolderOrFile: &#39;$(System.DefaultWorkingDirectory)&#39;
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

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

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

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

- script: | 
    pnpm install 
    npm run build
    rm -rf .cache 
 displayName: &#39;pnpm 安装,构建和删除 .cache 文件夹&#39;

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

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

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

英文:

I cloned this repository I used Node.js React app with Azure Web app as remix works better with react.

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

Select your Web app and run the yaml pipeline:-

trigger:
- main

variables:

 
  azureSubscription: &#39;azuresubscription-id&#39;

  # Web app name
  webAppName: &#39;siliconwebapp1&#39;

  # Environment name
  environmentName: &#39;siliconwebapp1&#39;

  # Agent VM image name
  vmImageName: &#39;ubuntu-latest&#39;

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

    steps:
    - task: ArchiveFiles@2
      displayName: &#39;Archive files&#39;
      inputs:
        rootFolderOrFile: &#39;$(System.DefaultWorkingDirectory)&#39;
        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: &#39;Azure App Service Deploy: siliconwebapp1&#39;
            inputs:
              azureSubscription: $(azureSubscription)
              appType: webAppLinux
              WebAppName: $(webAppName)
              packageForLinux: &#39;$(Pipeline.Workspace)/drop/$(Build.BuildId).zip&#39;
              RuntimeStack: &#39;NODE|10.10&#39;
              StartupCommand: &#39;npm run start&#39;
              ScriptType: &#39;Inline Script&#39;
              InlineScript: |
                npm install
                npm run build --if-present                

Above method does not include any cache task or copy files. But in your task you can add:-

- script: | 
    pnpm install 
    npm run build
    rm -rf .cache 
 displayName: &#39;pnpm install, build, and delete .cache folder&#39;

To remove the cache files before archive task.

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

If you face any issues related to the dependencies make sure you update those packages via npm commands. First run the code locally with npm run setup and npm run dev command. If the app runs locally, Push the code in your Azure DevOps pipeline and run again.

huangapple
  • 本文由 发表于 2023年6月16日 00:53:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483901.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定