Rajneesh
Rajneesh

Reputation: 33

Using codepipeline to create a build and deploy it in aws s3

I have created a codepipeline in aws that creates the build and copies the dist folder in my aws s3. I am able to save all the files inside the dist folder but assets folder is not saving. What should be the buildspec.yml file to copy assets folder in s3.

version: 0.2

env:
    variables:
        S3_BUCKET: bucketName
        APP_NAME: "Walter"
        BUILD_ENV : "prod"

phases:
    install:
        commands:
        - echo Installing source NPM dependencies...
        - npm install
        - npm install -g @angular/cli

build:
        commands:
        # Builds Angular application. You can also build using custom environment here like mock or staging
        - echo Build change this started on this  fg date `date`
        - ng build  --${BUILD_ENV}
post_build:
        commands:
        # Clear S3 bucket.
        - aws s3 rm s3://${S3_BUCKET} --recursive
        - echo S3 bucket is cleared.
        # Copy dist folder to S3 bucket, As of Angular 6, builds are stored inside an app folder in distribution and not at the root of the dist folder
        - aws s3 cp dist/walter s3://${S3_BUCKET}/${APP_NAME} --recursive
        - echo Build completed on `date`
artifacts:
    files:

        - '**/*'
    discard-paths: yes
    base-directory: 'dist/Walter'

Upvotes: 1

Views: 1078

Answers (1)

Rajneesh
Rajneesh

Reputation: 33

For someone looking to achieve this. I solved it by changing the 'discard-paths' value to 'no'. Setting its value to 'yes' neglects the folder structure and copies all the files to the specified location. With setting it to 'no', it maintains the folder structure.

Upvotes: 2

Related Questions