Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build angular project using AWS CodeBuild

We have an Angular project and we are trying to use AWS CodePipeline to deploy the project.

We have pushed our project to a CodeCommit repository.

Now we are facing challenge to generate the build using AWS CodeBuild. In CodeBuild the build definition is

phases:
  build:
    commands:
      - npm install && ng build-prod

We get an error ng: not found

We also tried the following build definition:

phases:
      build:
        commands:
          - npm install && run build-prod

Error we get is run: not found

Also we are not sure about what we have to enter in "Output files" field.

Please Help..!!

like image 796
ujjwal garg Avatar asked Mar 31 '18 09:03

ujjwal garg


People also ask

Which programming frameworks does CodeBuild support?

Q: Which programming frameworks does CodeBuild support? CodeBuild provides preconfigured environments for supported versions of Java, Ruby, Python, Go, Node. js, Android, . NET Core, PHP, and Docker.

Where would you use AWS CodeBuild?

Customers. Recruiterbox, an applicant tracking software, runs its continuous integration infrastructure on AWS, which handles approximately 300 builds per week and uses AWS CodeBuild to run tests before deploying software changes to production.

Does CodeBuild deploy?

AWS CodeBuild – A fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy, on a dynamically created build server. This solution uses CodeBuild to build and test the code, which we deploy later.


1 Answers

The Node.js container from CodeBuild doesn't have the angular-cli installed. Just Node.js and npm. You must install angular-cli before build your project. Above there are a buildspec.yml example for a angular project to be deployed in S3 bucket:

version: 0.2
env:
    variables:
        CACHE_CONTROL: "86400"
        S3_BUCKET: {-INSERT BUCKET NAME FOR STATIC WEBSITE HERE-}
        BUILD_FOLDER: {-INSERT THE NAME OF THE BUILD FOLDER HERE-}
        BUILD_ENV: "prod"
phases:
    install:
        commands:
            - echo Installing source NPM dependencies...
            - npm install
            - npm install -g @angular/cli
    build:
        commands:
            - echo Build started on `date`
            - ng build --${BUILD_ENV}
    post_build:
         commands:
            - aws s3 cp ${BUILD_FOLDER} s3://${S3_BUCKET} --recursive --acl public-read --cache-control "max-age=${CACHE_CONTROL}"
            - echo Build completed on `date`
artifacts:
    files:
        - '**/*'
    base-directory: 'dist*'
    discard-paths: yes
like image 58
Gustavo Tavares Avatar answered Oct 07 '22 17:10

Gustavo Tavares