AWS CodeBuild 不适用于 Yarn 工作区 [英] AWS CodeBuild does not work with Yarn Workspaces

查看:26
本文介绍了AWS CodeBuild 不适用于 Yarn 工作区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的存储库中使用 Yarn Workspaces 并使用 AWS CodeBuild 来构建我的包.构建开始时,CodeBuild 需要 60 秒来安装所有软件包,我想避免这次缓存 node_modules 文件夹.

I'm using Yarn Workspaces in my repository and also using AWS CodeBuild to build my packages. When build starts, CodeBuild takes 60 seconds to install all packages and I'd want to avoid this time caching node_modules folder.

当我添加:

cache:
  paths:
    - 'node_modules/**/*'

到我的 buildspec 文件并启用 LOCAL_CUSTOM_CACHE,我收到此错误:

to my buildspec file and enable LOCAL_CUSTOM_CACHE, I receive this error:

error 发生意外错误:EEXIST:文件已存在,mkdir '/codebuild/output/src637134264/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/MY_REPOSITORY/node_modules/@包/配置'".

error An unexpected error occurred: "EEXIST: file already exists, mkdir '/codebuild/output/src637134264/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/MY_REPOSITORY/node_modules/@packages/configs'".

有没有办法消除配置 AWS CodeBuild 或 Yarn 的这个错误?

Is there a way to remove this error configuring AWS CodeBuild or Yarn?

我的构建规范文件:

version: 0.2
phases:
  install:
    commands:
      - npm install -g yarn
      - git config --global credential.helper '!aws codecommit credential-helper $@'
      - git config --global credential.UseHttpPath true
      - yarn
  pre_build:
    commands:
      - git rev-parse HEAD
      - git pull origin master
  build:
    commands:
      - yarn run build
      - yarn run deploy
  post_build:
    commands:
      - echo 'Finished.'
cache:
  paths:
    - 'node_modules/**/*'

谢谢!

更新 1:

正在尝试文件夹 /codebuild/output/src637134264/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/MY_REPOSITORY/node_modules/@packages/configs由 Yarn 创建,在 install 阶段使用命令 - yarn.该文件夹是我的存储库包之一,名为 @packages/config.当我在我的计算机上运行 yarn 时,Yarn 会按照 这里.我的 node_modules 结构如何在我的计算机上的示例:

The folder /codebuild/output/src637134264/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/MY_REPOSITORY/node_modules/@packages/configs was being attempted to be created by Yarn, with the command - yarn at install phase. This folder is one of my repository packages, called @packages/config. When I run yarn on my computer, Yarn creates folders linking my packages as described here. An example of how my node_modules structure is on my computer:

node_modules/
|-- ...
|-- @packages/
|   |-- configs/
|   |-- myPackageA/
|   |-- myPackageB/
|-- ...

推荐答案

我遇到了完全相同的问题(EEXIST:文件已经存在,mkdir"),我最终使用了 S3缓存,它工作得很好.注意:由于某种原因,第一次上传到 S3 的时间太长了(10 分钟),其他的都很好.

I was having the exact same issue ("EEXIST: file already exists, mkdir"), I ended up using S3 cache and it worked pretty well. Note: for some reason the first upload to S3 took way (10 minutes) too long, the others went fine.

之前:

[5/5] Building fresh packages...
--
Done in 60.28s.

之后:

[5/5] Building fresh packages...
--
Done in 6.64s.

如果您已经配置了您的项目,您可以编辑访问该项目的缓存 ->编辑 ->文物 ->额外的配置.

If you already have your project configured you can edit the cache accessing the Project -> Edit -> Artifacts -> Additional configuration.

我的buildspec.yml如下:

My buildspec.yml is as follows:

version: 0.2

phases:
  install:
    runtime-versions:
       nodejs: 14
  build:
    commands:
      - yarn config set cache-folder /root/.yarn-cache
      - yarn install --frozen-lockfile
      - ...other build commands go here

cache:
  paths:
    - '/root/.yarn-cache/**/*'
    - 'node_modules/**/*'
    # This third entry is only if you're using monorepos (under the packages folder)
    # - 'packages/**/node_modules/**/*'

如果您使用 NPM,您会执行类似的操作,但命令略有不同:

If you use NPM you'd do something similar, with slightly different commands:

version: 0.2

phases:
  install:
    runtime-versions:
       nodejs: 14
  build:
    commands:
      - npm config -g set prefer-offline true
      - npm config -g set cache /root/.npm
      - npm ci
      - ...other build commands go here

cache:
  paths:
    - '/root/.npm-cache/**/*'
    - 'node_modules/**/*'
    # This third entry is only if you're using monorepos (under the packages folder)
    # - 'packages/**/node_modules/**/*'

感谢:https://mechanicalrock.github.io/2019/02/03/monorepos-aws-codebuild.html

这篇关于AWS CodeBuild 不适用于 Yarn 工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆