Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monorepo spec provided without "applications" key #1995

Closed
4 tasks done
arledesma opened this issue Jun 24, 2021 · 13 comments
Closed
4 tasks done

Monorepo spec provided without "applications" key #1995

arledesma opened this issue Jun 24, 2021 · 13 comments
Labels
archived This issue has been locked. monorepo

Comments

@arledesma
Copy link

arledesma commented Jun 24, 2021

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

14.16.1

Amplify CLI Version

5.0.1

What operating system are you using?

Ubuntu

Amplify Categories

Not applicable

Amplify Commands

Not applicable

Describe the bug

  1. I have multiple apps configured in a monorepo.
  2. I have each of these apps staged with an environment connected to our master branch
  3. I have preview enabled on each of the apps, targeting the master branch
  4. I do not yet have an amplify.yml in the master branch
  5. Within my pull request I have added the amplify.yml to the root of the repository
  6. Each preview build fails to find the amplify.yml that is included in the pull request

Expected behavior

The monorepo configuration will read the /amplify.yml within the pull request and apply it to the preview build

Reproduction steps

  1. Create a new monorepo repository
  2. Add multiple applications into the monorepo
  3. Use terraform to create the Amplify applications, branch per app, backend environment per branch, domain association per branch, enable previews on the branch
  4. Create a new branch to adds amplify to each of the applications
  5. Use amplify cli to initialize the applications by passing the appId along with the typical initialization parameters
  6. Commit the changes
  7. Open a pull request to the branch that has previews enabled

GraphQL schema(s)

n/a

Log output

AppId: d3127if6i267u2
2021-06-24T02:40:22.407Z [INFO]: Git SSH Key acquired
2021-06-24T02:40:22.485Z [INFO]: # Cloning repository: [email protected]:quantum-sec/platform.git
2021-06-24T02:40:22.528Z [INFO]: Agent pid 132
2021-06-24T02:40:22.553Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2021-06-24T02:40:22.754Z [INFO]: Cloning into 'platform'...
2021-06-24T02:40:23.735Z [INFO]: Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts.
2021-06-24T02:40:27.642Z [WARNING]: !Error: ENOENT: no such file or directory, open '/codebuild/output/src673194686/src/platform/amplify.yml'
2021-06-24T02:40:27.645Z [INFO]: Agent pid 145
2021-06-24T02:40:27.649Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2021-06-24T02:40:27.732Z [INFO]: # Retrieving environment cache...
2021-06-24T02:40:27.775Z [INFO]: # Retrieved environment cache
2021-06-24T02:40:27.775Z [WARNING]: !Cannot read property 'split' of undefined
2021-06-24T02:40:27.786Z [ERROR]: !!!Monorepo spec provided without "applications" key
2021-06-24T02:40:27.786Z [INFO]: # Starting environment caching...
2021-06-24T02:40:27.786Z [INFO]: # Environment caching completed
Terminating logging...
AppId: d3jyfteqrhguhk
2021-06-24T02:40:26.048Z [INFO]: Git SSH Key acquired
2021-06-24T02:40:26.123Z [INFO]: # Cloning repository: [email protected]:quantum-sec/platform.git
2021-06-24T02:40:26.157Z [INFO]: Agent pid 134
2021-06-24T02:40:26.192Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2021-06-24T02:40:26.460Z [INFO]: Cloning into 'platform'...
2021-06-24T02:40:27.447Z [INFO]: Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
2021-06-24T02:40:31.115Z [WARNING]: !Error: ENOENT: no such file or directory, open '/codebuild/output/src149936278/src/platform/amplify.yml'
2021-06-24T02:40:31.118Z [INFO]: Agent pid 147
2021-06-24T02:40:31.122Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2021-06-24T02:40:31.234Z [INFO]: # Retrieving environment cache...
2021-06-24T02:40:31.274Z [INFO]: # Retrieved environment cache
2021-06-24T02:40:31.275Z [WARNING]: !Cannot read property 'split' of undefined
2021-06-24T02:40:31.283Z [ERROR]: !!!Monorepo spec provided without "applications" key
2021-06-24T02:40:31.284Z [INFO]: # Starting environment caching...
2021-06-24T02:40:31.284Z [INFO]: # Environment caching completed
Terminating logging...
AppId: d1d91c9119qjjz
2021-06-24T02:40:18.197Z [INFO]: Git SSH Key acquired
2021-06-24T02:40:18.269Z [INFO]: # Cloning repository: [email protected]:quantum-sec/platform.git
2021-06-24T02:40:18.303Z [INFO]: Agent pid 131
2021-06-24T02:40:18.329Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2021-06-24T02:40:18.572Z [INFO]: Cloning into 'platform'...
2021-06-24T02:40:19.530Z [INFO]: Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
2021-06-24T02:40:23.378Z [WARNING]: !Error: ENOENT: no such file or directory, open '/codebuild/output/src345629935/src/platform/amplify.yml'
2021-06-24T02:40:23.382Z [INFO]: Agent pid 144
2021-06-24T02:40:23.385Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2021-06-24T02:40:23.467Z [INFO]: # Retrieving environment cache...
2021-06-24T02:40:23.500Z [INFO]: # Retrieved environment cache
2021-06-24T02:40:23.500Z [WARNING]: !Cannot read property 'split' of undefined
2021-06-24T02:40:23.510Z [ERROR]: !!!Monorepo spec provided without "applications" key
2021-06-24T02:40:23.510Z [INFO]: # Starting environment caching...
2021-06-24T02:40:23.511Z [INFO]: # Environment caching completed
Terminating logging...

Additional information

region appId
ap-southeast-1 d3127if6i267u2
ap-southeast-1 d3jyfteqrhguhk
ap-southeast-1 d1d91c9119qjjz

No amplify.yml in the target branch. This is the initial deployment and we would like to validate the previews are working as expected with the ability to update amplify.yml in the pull request, prior to being merged.

The following amplify.yml is being added in the pull request where the preview build fails. Application names have been changed to example, otherwise each appRoot matches the AMPLIFY_MONOREPO_APP_ROOT that is set in each of the amplify apps.

/amplify.yml
version: 1
applications:
  - appRoot: apps/ngx-example1
    backend:
      phases:
        build:
          commands:
            - '# Execute Amplify CLI with the helper script'
            - amplifyPush --simple
    frontend:
      phases:
        preBuild:
          commands:
            - '# everything should be performed from the base of the monorepo'
            - cd ../../
            - npm config set cache --global .npm
            - bash .tools/build/update-nvm.sh
            - nvm exec npm ci
        build:
          commands:
            - nvm exec npm run build:prod --workspace apps/ngx-example1
      artifacts:
        baseDirectory: ../../dist/apps/ngx-example1/
        files:
          - '**/*'
      cache:
        paths:
          - .npm

    test:
      phases:
        preTest:
          commands:
            - cd ../../
            - npm config set cache --global .npm
            - bash .tools/build/update-nvm.sh || true
            - nvm exec npm ci
        test:
          commands:
            - nvm exec npx --yes --package='nx@^12.4.0' -- nx run ngx-example1-e2e:e2e
        postTest:
          commands:
            - nvm exec npx --yes --package='mochawesome-merge@^4.2.0' -- mochawesome-merge -o dist/cypress/apps/ngx-example1-e2e/mochawesome-report/mochawesome.json dist/cypress/apps/ngx-example1-e2e/mochawesome-report/mochawesome*.json
      artifacts:
        baseDirectory: ../../dist/cypress/apps/ngx-example1-e2e
        configFilePath: '**/mochawesome.json'
        files:
          - '**/*.png'
          - '**/*.mp4'
          - '**/*.html'
  - appRoot: apps/ngx-example2
    backend:
      phases:
        build:
          commands:
            - '# Execute Amplify CLI with the helper script'
            - amplifyPush --simple
    frontend:
      phases:
        preBuild:
          commands:
            - '# everything should be performed from the base of the monorepo'
            - cd ../../
            - npm config set cache --global .npm
            - bash .tools/build/update-nvm.sh
            - nvm exec npm ci
        build:
          commands:
            - nvm exec npm run build:prod --workspace apps/ngx-example2
      artifacts:
        baseDirectory: ../../dist/apps/ngx-example2/
        files:
          - '**/*'
      cache:
        paths:
          - .npm

    test:
      phases:
        preTest:
          commands:
            - cd ../../
            - npm config set cache --global .npm
            - bash .tools/build/update-nvm.sh || true
            - nvm exec npm ci
        test:
          commands:
            - nvm exec npx --yes --package='nx@^12.4.0' -- nx run ngx-example2-e2e:e2e
        postTest:
          commands:
            - nvm exec npx --yes --package='mochawesome-merge@^4.2.0' -- mochawesome-merge -o dist/cypress/apps/ngx-example2-e2e/mochawesome-report/mochawesome.json dist/cypress/apps/ngx-example2-e2e/mochawesome-report/mochawesome*.json
      artifacts:
        baseDirectory: ../../dist/cypress/apps/ngx-example2-e2e
        configFilePath: '**/mochawesome.json'
        files:
          - '**/*.png'
          - '**/*.mp4'
          - '**/*.html'
  - appRoot: apps/ngx-example3
    backend:
      phases:
        build:
          commands:
            - '# Execute Amplify CLI with the helper script'
            - amplifyPush --simple
    frontend:
      phases:
        preBuild:
          commands:
            - '# everything should be performed from the base of the monorepo'
            - cd ../../
            - npm config set cache --global .npm
            - bash .tools/build/update-nvm.sh
            - nvm exec npm ci
        build:
          commands:
            - nvm exec npm run build:prod --workspace apps/ngx-example3
      artifacts:
        baseDirectory: ../../dist/apps/ngx-example3/
        files:
          - '**/*'
      cache:
        paths:
          - .npm

    test:
      phases:
        preTest:
          commands:
            - cd ../../
            - npm config set cache --global .npm
            - bash .tools/build/update-nvm.sh || true
            - nvm exec npm ci
        test:
          commands:
            - nvm exec npx --yes --package='nx@^12.4.0' -- nx run ngx-example3-e2e:e2e
        postTest:
          commands:
            - nvm exec npx --yes --package='mochawesome-merge@^4.2.0' -- mochawesome-merge -o dist/cypress/apps/ngx-example3-e2e/mochawesome-report/mochawesome.json dist/cypress/apps/ngx-example3-e2e/mochawesome-report/mochawesome*.json
      artifacts:
        baseDirectory: ../../dist/cypress/apps/ngx-example3-e2e
        configFilePath: '**/mochawesome.json'
        files:
          - '**/*.png'
          - '**/*.mp4'
          - '**/*.html'
@attilah
Copy link

attilah commented Jun 24, 2021

It looks like an issue related to Amplify Console, transferring it to their repository.

@litwicki litwicki transferred this issue from aws-amplify/amplify-cli Jun 24, 2021
@arledesma
Copy link
Author

arledesma commented Jun 24, 2021

Looks to be related to #1880 #1955 and possibly #1981

  1. Should I set the buildSpec on the Amplify App (or even the Amplify App Branch) in order to get around this behavior?
    1. If so then should it be in the monorepo format or the basic format?
  2. Is the amplify.yml from the target branch of the pull request being used for the preview build instead of the amplify.yml from the source branch?
    1. Is this expected behavior?
    2. Is this behavior documented publicly?
    3. If the buildSpec is defined directly on the Amplify App will it use it for the build if there is not an amplify.yml in the target branch?
    4. If the buildSpec is defined directly on the Amplify App Branch will it use it if there is not an amplify.yml in the target branch?
    5. If the buildSpec is defined directly on the Amplify App, on the Amplify App Branch, and there is an amplify.yml in the source branch without an amplify.yml on the target branch will it use the buildSpec that is defined on the Amplify App, the buildSpec defined on the Amplify App Branch or the amplify.yml in the source branch?
    6. If the buildSpec is defined directly on the Amplify App, on the Amplify App Branch, there is an amplify.yml in the source branch, and there is an amplify.yml on the target branch will it use the buildSpec that is defined on the Amplify App, the buildSpec defined on the Amplify App Branch the amplify.yml in the source branch or the amplify.yml in the target branch?

@victorccccc
Copy link
Contributor

victorccccc commented Jun 28, 2021

Hi @arledesma , we are sorry to see this. Regarding to your issue, workaround now is adding amplify.yml directly to your master branch. Our team has noticed and are working on the fix of the issue that PR build doesn't pick up correct buildSpec, it always takes target branch's buildSpec.

For your question, rule of thumb is amplify.yml file in your root folder overrides your App build specification setting in Amplify console. You can have different amplify.yml file for each branch, but if you determine to just use App build specification in console, you will have only one buildSpec for all branches. We recommend to keepamplify.yml file in your root folder.

@arledesma
Copy link
Author

@victorccccc

Our team has noticed and are working on the fix of the issue that PR build doesn't pick up correct buildSpec, it always takes target branch's buildSpec.

I'm glad to hear that the issue has been acknowledged.

Could we get any type of insights as to when we may see the behavior corrected (is the issue in the backlog, scheduled for a future sprint, actively being worked?). I don't need any specifics; I just want to be able to set expectations.

@aws-amplify aws-amplify deleted a comment from github-actions bot Jun 29, 2021
@victorccccc
Copy link
Contributor

Fix is deployed to ap-southeast-1, please verify the fix.

Feel free to re-open this if issue persists

@garysm
Copy link

garysm commented Aug 25, 2021

@victorccccc I am receiving this error in us-east-1. I have also tried your workaround of including amplify.yaml in the master branch.

Error: !!!Monorepo spec provided without "applications" key

@victorccccc
Copy link
Contributor

@victorccccc I am receiving this error in us-east-1. I have also tried your workaround of including amplify.yaml in the master branch.

Error: !!!Monorepo spec provided without "applications" key

Hi Gary, could you try to follow this instruction: https://docs.aws.amazon.com/amplify/latest/userguide/monorepo-configuration.html and add applications in your build spec? Thanks

@garysm
Copy link

garysm commented Aug 25, 2021

@victorccccc I am receiving this error in us-east-1. I have also tried your workaround of including amplify.yaml in the master branch.
Error: !!!Monorepo spec provided without "applications" key

Hi Gary, could you try to follow this instruction: https://docs.aws.amazon.com/amplify/latest/userguide/monorepo-configuration.html and add applications in your build spec? Thanks

Here is the build spec that I've been using:

version: 1
applications:
  - appRoot: web_app_build/
    frontend:
      phases:
        build:
          commands: []
      artifacts:
        baseDirectory: /
        files:
          - '**/*'
      cache:
        paths: []

This same build spec was used for previous builds without any issues.

@victorccccc
Copy link
Contributor

@victorccccc I am receiving this error in us-east-1. I have also tried your workaround of including amplify.yaml in the master branch.
Error: !!!Monorepo spec provided without "applications" key

Hi Gary, could you try to follow this instruction: https://docs.aws.amazon.com/amplify/latest/userguide/monorepo-configuration.html and add applications in your build spec? Thanks

Here is the build spec that I've been using:

version: 1
applications:
  - appRoot: web_app_build/
    frontend:
      phases:
        build:
          commands: []
      artifacts:
        baseDirectory: /
        files:
          - '**/*'
      cache:
        paths: []

This same build spec was used for previous builds without any issues.

Hi, can you share your AppId?

@garysm
Copy link

garysm commented Aug 25, 2021

@victorccccc I am receiving this error in us-east-1. I have also tried your workaround of including amplify.yaml in the master branch.
Error: !!!Monorepo spec provided without "applications" key

Hi Gary, could you try to follow this instruction: https://docs.aws.amazon.com/amplify/latest/userguide/monorepo-configuration.html and add applications in your build spec? Thanks

Here is the build spec that I've been using:

version: 1
applications:
  - appRoot: web_app_build/
    frontend:
      phases:
        build:
          commands: []
      artifacts:
        baseDirectory: /
        files:
          - '**/*'
      cache:
        paths: []

This same build spec was used for previous builds without any issues.

Hi, can you share your AppId?

d313d3b5r9k86x

@victorccccc
Copy link
Contributor

Hi @garysm , I noticed you are using customHttp.yml. Can you also try to add applications and appRoot by following this instruction: https://docs.aws.amazon.com/amplify/latest/userguide/custom-headers.html#custom-header-YAML-format ? thanks

@garysm
Copy link

garysm commented Aug 25, 2021

Hi @garysm , I noticed you are using customHttp.yml. Can you also try to add applications and appRoot by following this instruction: https://docs.aws.amazon.com/amplify/latest/userguide/custom-headers.html#custom-header-YAML-format ? thanks

That fixed it. Thanks for your help and quick response @victorccccc.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot added the archived This issue has been locked. label Oct 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived This issue has been locked. monorepo
Projects
None yet
Development

No branches or pull requests

5 participants