3

After the CodeBuild is complete and I ssh into my environment, I can see that the server app's dependencies are installed and found in its node_modules. However in the client directory, there is no node_modules nor build directory. In the build logs, npm install --prefix client --production appears to run fine.

My question is almost exactly like this one, except it is both the node_modules and the build folder.

Is there a problem with the buildspec file? Here it is (EDIT 4: updated)

version: 0.2

phases:
  install:
    commands:
      # upgrade AWS CLI
      - pip install --upgrade awscli
      # install Node 12
      - curl -sL https://deb.nodesource.com/setup_12.x | bash -
      - apt install nodejs

  pre_build:
    commands:
      # install server dependencies
      - npm install
  build:
    commands:
      # install client dependencies and build static files
      - npm install --prefix client && npm run build --prefix client

  post_build:
    commands:
      - ls -la
      - ls client -la

artifacts:
  files:
    - '**/*'

EDIT 1: here's an example of what the codebuild logs show for the npm install --prefix client:

Running command npm install --prefix client --production



> [email protected] postinstall /codebuild/output/src133125934/src/client/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

And for the npm run build -prefix client:

[Container] 2020/07/02 00:24:06 Entering phase BUILD
[Container] 2020/07/02 00:24:06 Running command npm run build --prefix client



> [email protected] build /codebuild/output/src133125934/src/client
> react-scripts build



Creating an optimized production build...
Compiled successfully.



File sizes after gzip:



  144.95 KB  build/static/js/2.d25271aa.chunk.js
  23.22 KB   build/static/css/main.fe6e5073.chunk.css
  6.38 KB    build/static/js/main.8e99a285.chunk.js
  774 B      build/static/js/runtime-main.f63e6028.js

EDIT 2: Using ls to see the directories after the build:

[Container] 2020/07/02 01:11:24 Entering phase POST_BUILD
[Container] 2020/07/02 01:11:24 Running command ls -la
total 136
drwxr-xr-x  12 root root  4096 Jul  2 01:09 .
drwxr-xr-x   3 root root  4096 Jul  2 01:09 ..
drwxr-xr-x   2 root root  4096 Jul  2 01:09 .ebextensions
-rw-rw-r--   1 root root   130 Jul  2 01:08 .gitignore
-rw-rw-r--   1 root root    16 Jul  2 01:08 .npmrc
-rw-rw-r--   1 root root    34 Jul  2 01:08 README.md
-rw-rw-r--   1 root root  1737 Jul  2 01:08 app.js
drwxr-xr-x   2 root root  4096 Jul  2 01:09 bin
-rw-rw-r--   1 root root   566 Jul  2 01:08 buildspec.yml
drwxr-xr-x   6 root root  4096 Jul  2 01:10 client
drwxr-xr-x   2 root root  4096 Jul  2 01:09 config
drwxr-xr-x   2 root root  4096 Jul  2 01:09 graphql
drwxr-xr-x   2 root root  4096 Jul  2 01:09 models
drwxr-xr-x 197 root root  4096 Jul  2 01:10 node_modules
-rw-rw-r--   1 root root 63888 Jul  2 01:08 package-lock.json
-rw-rw-r--   1 root root   814 Jul  2 01:08 package.json
drwxr-xr-x   2 root root  4096 Jul  2 01:09 routes
drwxr-xr-x   2 root root  4096 Jul  2 01:09 services
drwxr-xr-x   2 root root  4096 Jul  2 01:09 views




[Container] 2020/07/02 01:11:24 Running command ls client -la
total 748
drwxr-xr-x    6 root root   4096 Jul  2 01:10 .
drwxr-xr-x   12 root root   4096 Jul  2 01:09 ..
drwxr-xr-x    3 root root   4096 Jul  2 01:11 build
drwxr-xr-x 1081 root root  36864 Jul  2 01:10 node_modules
-rw-rw-r--    1 root root 699332 Jul  2 01:08 package-lock.json
-rw-rw-r--    1 root root   1212 Jul  2 01:08 package.json
drwxr-xr-x    2 root root   4096 Jul  2 01:09 public
drwxr-xr-x    8 root root   4096 Jul  2 01:09 src

EDIT 3: After verifying the directories are made, I ssh into the beanstalk (ec2) instance to check if they have been deployed but this is what I get:

$ cd /var/app/current
$ ls
app.js
bin
buildspec.yml
client
config
graphql
models
node_modules
package.json
package-lock.json
Procfile
README.md
routes
services
views

$ cd client
$ ls
package.json 
package-lock.json 
public 
src

The build and modules directory are not deployed into beanstalk.

22
  • Are you sure that all the files you need are in client/build? With the base-directory, **/* will apply to client/build. Also you can go to S3 and download the artifact in zip and inspect its structure to see in detail what it has. Commented Jul 1, 2020 at 22:38
  • @Marcin This is my first project using aws so correct me if I'm wrong, but shouldn't the files in the base-directory be static files for the website on Elastic Beanstalk? Or is it supposed to be the entire project? Commented Jul 1, 2020 at 22:50
  • I assume you use CodePipeline and CP deploys to EB? Then it should be entire project, just like you would upload the zip file yourself though EB console. Commented Jul 1, 2020 at 23:51
  • @Marcin thank you for the clarification! I checked the structures after removing the base-directory and the client/node_modules and the client/build directories are still not there. I don't know which stage causes this error; when looking at the logs, the commands npm install --prefix client and npm run build --prefix client are being run so I assume the directories are being made somewhere Commented Jul 1, 2020 at 23:57
  • Just remove ` base-directory: 'client/build'` for testing and troubleshooting. This will allow you to download the entire folder and inspect it. Maybe npm install is installing in system folders, not your local working directly? Commented Jul 2, 2020 at 0:09

1 Answer 1

2

The problem is that the Deploy stage of the CodePipeline was taking in the Source output, not the Build output. Setting the Deploy input as the Build output fixed it!

Sign up to request clarification or add additional context in comments.

1 Comment

Could you please add the code as part of this solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.