7

Currently I'm using AWS CodeBuild to deploy my monorepo project and I'm trying to use its cache properties. I want to cache my node_modules folder and my buildspec.yml is:

version: 0.2

phases:
  install:
    commands:
      - echo Entered the install phase...
      - npm install
    finally:
      - echo This always runs even if the update or install command fails
  pre_build:
    commands:
      - echo Entered the pre_build phase...
    finally:
      - echo This always runs even if the login command fails
  build:
    commands:
      - echo Entered the build phase...
      - echo Build started on `date`
      - npm run build
    finally:
      - echo This always runs even if the install command fails
  post_build:
    commands:
      - echo "Entered the post_build phase (deploy)..."
      - npm run deploy
      - echo deploy completed on `date`

cache:
  paths:
    - 'node_modules/**/*'
    - 'packages/lambdas/node_modules/**/*'
    - 'packages/web/node_modules/**/*'

Is there a way to use a wildcard to add all node_modules to path?

My repository structure is:

root
  node_modules
  packages
    lambdas
      node_modules
      ...
    web
      node_modules
      ...
  ...

Thank you!

Update 1 (05/14/16):

I get this error

[Container] 2019/05/14 23:19:24 Symlinking: /codebuild/output/src986466269/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/MYREPOSITORY/*/**/node_modules => /codebuild/local-cache/custom/7bd9b9fb12a6f74162020f29bfde2b34c52fdde87977fb9dda31fcbbb33f01af/*/**/node_modules 
[Container] 2019/05/14 23:19:24 Error mounting /codebuild/output/src986466269/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/MY_REPOSITORY/*/**/node_modules: symlink /codebuild/local-cache/custom/7bd9b9fb12a6f74162020f29bfde2b34c52fdde87977fb9dda31fcbbb33f01af/*/**/node_modules /codebuild/output/src986466269/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/MY_REPOSITORY/*/**/node_modules: no such file or directory 

when I use

cache:
  paths:
    - '*/**/node_modules/**/*'
Pedro Arantes
  • 5,113
  • 5
  • 25
  • 60
  • Does `packages/*/node_modules/**/*` work to cache all node_modules for each of the packages in packages directory for the monorepo? I am similarly trying to setup cache of node_modules for my monorepo project but getting this error during `yarn install` for a build: `error An unexpected error occurred: "EEXIST: file already exists, mkdir '/codebuild/output/src087246803/src/github.com/ChowNow/chownow-web/node_modules/app-dashboard'". ` Seems to be an issue since the cache is set up as a symlink but Yarn sets up symlinks in the node_modules dir for dependencies w/in the monorepo – munsellj Nov 07 '19 at 22:28
  • 1
    @munsellj I had the same issue and I've created another question: https://stackoverflow.com/questions/55890275/aws-codebuild-does-not-work-with-yarn-workspaces – Pedro Arantes Nov 11 '19 at 17:27

0 Answers0