将Turborepo Next.js应用部署到Azure静态Web应用

w1e3prcc  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(94)

我正在尝试使用GitHub操作和自定义构建步骤将Turborepo monorepo中的Next.js站点部署到Azure Static Web App。Next.js站点配置为使用standalone输出,但在其他方面遵循预设配置。部署作业失败,并出现以下错误:

Failed to find a default file in the app artifacts folder (apps/web/.next). Valid default files: index.html,Index.html.
If your application contains purely static content, please verify that the variable 'app_location' in your workflow file points to the root of your application.

字符串
生成和部署作业配置如下所示:

build_and_deploy_job:
  if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
  runs-on: ubuntu-latest
  name: Build and Deploy Job
  steps:
    - uses: actions/checkout@v3
      with:
        submodules: true
    - run: |
        npm install turbo -g
        npm i
        turbo run build --filter=web
        cp apps/web/staticwebapp.config.json apps/web/.next
    - name: Build And Deploy
      id: builddeploy
      uses: Azure/static-web-apps-deploy@v1
      with:
        azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_HAPPY_WAVE_0A47E7A0F }}
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        action: "upload"
        skip_app_build: true
        app_location: "apps/web/.next"
        api_location: ""
        output_location: ""


将Turborepo monorepo中的Next.js应用部署到Azure静态Web应用需要哪些配置或其他步骤?我确认可以成功部署monorepo上下文之外的相同应用 *,但这可以在没有自定义构建步骤的情况下完成。
回购:https://github.com/westonsankey/turbo-demo

goqiplq2

goqiplq21#

我发现app_location应该指向apps/web
如果您建置应用程序,应该会在下列目录结构中看到.next输出:

.
├── apps
│   └── web
│       ├── .next
│       │   └── standalone
│       │       ├── apps
│       │       │   └── web
│       │       │       └── server.js
│       │       └── package.json
│       ├── package.json
│       └── staticwebapp.config.json
├── .github
│   └── workflows
│       └── azure-static-web-apps.yml
├── package.json
└── turbo.json

字符串
必须将apps/web/.next/standalone/apps/web/的内容移至apps/web/.next/standalone/
请尝试以下生成配置:

build_and_deploy_job:
  if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
  runs-on: ubuntu-latest
  name: Build and Deploy Job
  steps:
    - uses: actions/checkout@v3
      with:
        submodules: true
    - run: |
        npm install turbo -g
        npm i
        turbo run build --filter=web
        cp -r apps/web/.next/standalone/apps/web/. apps/web/.next/standalone
        cp apps/web/staticwebapp.config.json apps/web/.next
    - name: Build And Deploy
      id: builddeploy
      uses: Azure/static-web-apps-deploy@v1
      with:
        azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_HAPPY_WAVE_0A47E7A0F }}
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        action: "upload"
        skip_app_build: true
        app_location: "apps/web"
        api_location: ""
        output_location: ""


下面是一个使用turborepo和pnpm工作空间的有用的示例repo(我不是作者):
https://github.com/vivekjilla/pnpm-nextjs-sample/

相关问题