aws-amplify / aws-amplify/amplify-hosting

Monorepo and cache don't work together as expected

Open
#2,673 3 comments 6 reactions 0 assignees View on GitHub
bug monorepo
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

### App Id

arn:aws:amplify:eu-west-1:783638159601:apps/dnyal24enu3r3

### Region

_No response_

### Amplify Hosting feature

Build settings

### Describe the bug

Monorepos and caching doesn't work as expected.

Directory structure requires cache path specification to include the complete path for the node modules caching to work.

### Expected behavior

this cache configuration
```
cache:
paths:
- node_modules/**/*
```
should result in a cache artifact even when AMPLIFY_MONOREPO_APP_ROOT is used and is not the root.
```
# Cache artifact is: 607MB
```

but the result cache artifact is 0MB

### Reproduction steps

AMPLIFY_MONOREPO_APP_ROOT=frontend/my-app
see yaml below

### Build Settings

```yaml
- appRoot: frontend/my-app
frontend:
phases:
preBuild:
commands:
- >
- yarn install
build:
commands:
- yarn run build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
```

### Additional information

while the above yaml doesn't work, this does:
```
- appRoot: frontend/my-app
frontend:
phases:
preBuild:
commands:
- >
- yarn install
build:
commands:
- yarn run build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- frontend/my-app/node_modules/**/*
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the build using AMPLIFY_MONOREPO_APP_ROOT=frontend/my-app and the YAML shown, comparing node_modules/**/* with frontend/my-app/node_modules/**/*; verify the resulting cache artifact size. Read FAQ.md and CONTRIBUTING.md for repository context, then trace the build-settings cache handling until the monorepo app root is accounted for; done means the shorter cache path produces the expected nonzero artifact.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, yaml
Domain
build-system, ci-cd, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.