AWS CodeBuild YAML for Angular

Viewed 1916

I'm trying to deploy an angular app from github to elastic beanstalk using code pipeline.

This is my simple yml:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - echo Installing angular cli...
      - npm install -g @angular/cli
build:
  commands:
    - echo Build started...
    - ng build --prod

artifacts:
  files:
    - dist/

And the error stack:

[Container] 2019/06/28 10:44:26 Waiting for agent ping 
[Container] 2019/06/28 10:44:29 Waiting for DOWNLOAD_SOURCE 
[Container] 2019/06/28 10:44:30 Phase is DOWNLOAD_SOURCE 
[Container] 2019/06/28 10:44:30 CODEBUILD_SRC_DIR=/codebuild/output/src628764845/src 
[Container] 2019/06/28 10:44:30 YAML location is /codebuild/output/src628764845/src/buildspec.yml 
[Container] 2019/06/28 10:44:30 Processing environment variables 
[Container] 2019/06/28 10:44:30 Moving to directory /codebuild/output/src628764845/src 
[Container] 2019/06/28 10:44:30 Registering with agent 
[Container] 2019/06/28 10:44:30 Phases found in YAML: 1 
[Container] 2019/06/28 10:44:30  INSTALL: 2 commands 
[Container] 2019/06/28 10:44:30 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED 
[Container] 2019/06/28 10:44:30 Phase context status code:  Message:  
[Container] 2019/06/28 10:44:30 Entering phase INSTALL 
[Container] 2019/06/28 10:44:30 Running command echo "Installing Node.js version 10 ..." 
Installing Node.js version 10 ... 

[Container] 2019/06/28 10:44:30 Running command n 10.16.0 

[Container] 2019/06/28 10:44:31 Running command echo Installing angular cli... 
Installing angular cli... 

[Container] 2019/06/28 10:44:31 Running command npm install -g @angular/cli 
/usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng 

> @angular/cli@8.0.6 postinstall /usr/local/lib/node_modules/@angular/cli 
> node ./bin/postinstall/script.js 

+ @angular/cli@8.0.6 
added 228 packages from 175 contributors in 10.074s 

[Container] 2019/06/28 10:44:42 Phase complete: INSTALL State: SUCCEEDED 
[Container] 2019/06/28 10:44:42 Phase context status code:  Message:  
[Container] 2019/06/28 10:44:42 Entering phase PRE_BUILD 
[Container] 2019/06/28 10:44:42 Phase complete: PRE_BUILD State: SUCCEEDED 
[Container] 2019/06/28 10:44:42 Phase context status code:  Message:  
[Container] 2019/06/28 10:44:42 Entering phase BUILD 
[Container] 2019/06/28 10:44:42 Phase complete: BUILD State: SUCCEEDED 
[Container] 2019/06/28 10:44:42 Phase context status code:  Message:  
[Container] 2019/06/28 10:44:42 Entering phase POST_BUILD 
[Container] 2019/06/28 10:44:42 Phase complete: POST_BUILD State: SUCCEEDED 
[Container] 2019/06/28 10:44:42 Phase context status code:  Message:  
[Container] 2019/06/28 10:44:42 Expanding base directory path: . 
[Container] 2019/06/28 10:44:42 Assembling file list 
[Container] 2019/06/28 10:44:42 Expanding . 
[Container] 2019/06/28 10:44:42 Expanding artifact file paths for base directory . 
[Container] 2019/06/28 10:44:42 Assembling file list 
[Container] 2019/06/28 10:44:42 Expanding dist/ 
[Container] 2019/06/28 10:44:42 Skipping invalid artifact path dist/ 
[Container] 2019/06/28 10:44:42 Phase complete: UPLOAD_ARTIFACTS State: FAILED 
[Container] 2019/06/28 10:44:42 Phase context status code: CLIENT_ERROR Message: no matching artifact paths found 

Supposedly the compiled source is in dist, but it can't seem to find it... Advice?

1 Answers

First, the build phase was not correctly indented so the BUILD commands were never executed.

Also, CodeBuild does not accept dist/ as a valid file path. You can update the artifact files to dist/**/* (Reference: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-syntax you can find valid file syntaxs in the artifacts section )

I was able to build successfully with this YAML:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - echo Installing angular cli...
      - npm install -g @angular/cli
      - yarn add @angular-devkit/build-angular --dev
  build:
    commands:
      - echo Build started...
      - ng build --prod
artifacts:
  files:
    - dist/**/*

Build Log (note this line [Container] 2019/06/29 03:54:46 BUILD: 2 commands):

[Container] 2019/06/29 03:54:43 Waiting for agent ping 
[Container] 2019/06/29 03:54:45 Waiting for DOWNLOAD_SOURCE 
[Container] 2019/06/29 03:54:46 Phase is DOWNLOAD_SOURCE 
[Container] 2019/06/29 03:54:46 CODEBUILD_SRC_DIR=/codebuild/output/src432990035/src/github.com/taoyong-ty/CodeBuildAngularJS 
[Container] 2019/06/29 03:54:46 YAML location is /codebuild/readonly/buildspec.yml 
[Container] 2019/06/29 03:54:46 Processing environment variables 
[Container] 2019/06/29 03:54:46 Moving to directory /codebuild/output/src432990035/src/github.com/taoyong-ty/CodeBuildAngularJS 
[Container] 2019/06/29 03:54:46 Registering with agent 
[Container] 2019/06/29 03:54:46 Phases found in YAML: 2 
[Container] 2019/06/29 03:54:46  INSTALL: 3 commands 
[Container] 2019/06/29 03:54:46  BUILD: 2 commands 
[Container] 2019/06/29 03:54:46 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED 
[Container] 2019/06/29 03:54:46 Phase context status code:  Message:  
[Container] 2019/06/29 03:54:46 Entering phase INSTALL 
[Container] 2019/06/29 03:54:46 Running command echo "Installing Node.js version 10 ..." 
Installing Node.js version 10 ... 

[Container] 2019/06/29 03:54:46 Running command n 10.16.0 

[Container] 2019/06/29 03:54:50 Running command echo Installing angular cli... 
Installing angular cli... 

[Container] 2019/06/29 03:54:50 Running command npm install -g @angular/cli 
/usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng 

> @angular/cli@8.0.6 postinstall /usr/local/lib/node_modules/@angular/cli 
> node ./bin/postinstall/script.js 

+ @angular/cli@8.0.6 
added 228 packages from 175 contributors in 8.003s 

[Container] 2019/06/29 03:55:00 Running command yarn add @angular-devkit/build-angular --dev

 ...

[Container] 2019/06/29 03:55:27 Phase complete: INSTALL State: SUCCEEDED 
[Container] 2019/06/29 03:55:27 Phase context status code:  Message:  
[Container] 2019/06/29 03:55:27 Entering phase PRE_BUILD 
[Container] 2019/06/29 03:55:27 Phase complete: PRE_BUILD State: SUCCEEDED 
[Container] 2019/06/29 03:55:27 Phase context status code:  Message:  
[Container] 2019/06/29 03:55:27 Entering phase BUILD 
[Container] 2019/06/29 03:55:27 Running command echo Build started... 
Build started... 

[Container] 2019/06/29 03:55:27 Running command ng build --prod 

Date: 2019-06-29T03:55:53.941Z 
Hash: 1c706bd9139214c9249a 
Time: 23138ms 
chunk {0} runtime-es5.741402d1d47331ce975c.js (runtime) 1.41 kB [entry] [rendered] 
chunk {1} main-es5.e3ebb85443beec4e9e43.js (main) 242 kB [initial] [rendered] 
chunk {2} polyfills-es5.3c7a89c465e3c36435bf.js (polyfills) 111 kB [initial] [rendered] 

Date: 2019-06-29T03:56:11.506Z 
Hash: 6942a0134cd3414197f9 
Time: 17532ms 
chunk {0} runtime-es2015.858f8dd898b75fe86926.js (runtime) 1.41 kB [entry] [rendered] 
chunk {1} main-es2015.0e84a207334269c68b86.js (main) 209 kB [initial] [rendered] 
chunk {2} polyfills-es2015.5728f680576ca47e99fe.js (polyfills) 36.4 kB [initial] [rendered] 
chunk {3} styles.3ff695c00d717f2d2a11.css (styles) 0 bytes [initial] [rendered] 

[Container] 2019/06/29 03:56:11 Phase complete: BUILD State: SUCCEEDED 
[Container] 2019/06/29 03:56:11 Phase context status code:  Message:  
[Container] 2019/06/29 03:56:11 Entering phase POST_BUILD 
[Container] 2019/06/29 03:56:11 Phase complete: POST_BUILD State: SUCCEEDED 
[Container] 2019/06/29 03:56:11 Phase context status code:  Message:  
[Container] 2019/06/29 03:56:11 Expanding base directory path: . 
[Container] 2019/06/29 03:56:11 Assembling file list 
[Container] 2019/06/29 03:56:11 Expanding . 
[Container] 2019/06/29 03:56:11 Expanding artifact file paths for base directory . 
[Container] 2019/06/29 03:56:11 Assembling file list 
[Container] 2019/06/29 03:56:11 Expanding dist/**/* 
[Container] 2019/06/29 03:56:11 Found 10 file(s) 
[Container] 2019/06/29 03:56:11 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED 
[Container] 2019/06/29 03:56:11 Phase context status code:  Message: 
Related