简体   繁体   English

使用代码管道在 AWS S3 上部署 Angular 7 应用程序时出错

[英]Error while deploying Angular 7 app on AWS S3 using codepipeline

I want to deploy Angular 7 app(as static website) on S3 automatically using AWS Code pipeline.我想使用 AWS 代码管道在 S3 上自动部署 Angular 7 应用程序(作为静态网站)。 I have created Angular app and pushed to my git repo.我已经创建了 Angular 应用程序并推送到我的 git 仓库。 I have created new AWS S3 bucket and created AWS Codepipline and integrated git repo我创建了新的 AWS S3 存储桶并创建了 AWS Codepipline 和集成的 git repo

I am getting below error when aws code-pipelineb uilds the app: COMMAND_EXECUTION_ERROR: Error while executing command: ng build.当 aws 代码管道构建应用程序时,我遇到以下错误: COMMAND_EXECUTION_ERROR:执行命令时出错:ng build。 Reason: exit status 1原因:退出状态 1

在此处输入图片说明

I am using buildspect.yml file我正在使用 buildspect.yml 文件

version: 0.2

env:
    variables:
        S3_BUCKET: "<bucket name>"
        BUILD_ENV : "prod"

phases:
    install:
        runtime-versions:
            nodejs: 10
        commands:
            # install dependencies
            - echo Installng source NPM dependencies...
            - npm install npm@latest -g
            - npm install -g @angular/cli

    pre_build:
        commands:
            - echo Prebuild steps
            - npm install

    build:
        commands:
            # Builds Angular application. You can also build using custom environment here like mock or staging
            - echo Build started on `date`
            - ng build

    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 s3://${S3_BUCKET} --recursive
            - echo Build completed on `date`

artifacts:
    files:
        - '/'
    discard-paths: yes
    base-directory: 'dist*'

I feel that code-build environment is not properly configured.我觉得代码构建环境没有正确配置。 I mean Nodejs and npm is not installed correctly.我的意思是 Nodejs 和 npm 没有正确安装。 Please go through above yml file and help me identify if I am missing anything.请查看上面的 yml 文件并帮助我确定我是否遗漏了任何内容。

You are missing the build environment in your Buildspec.yml file.您的 Buildspec.yml 文件中缺少构建环境。

Add this piece in and check if this helps -添加这件作品并检查这是否有帮助 -

build:
    commands:
        # Builds Angular application. You can also build using custom environment here like mock or staging
        - echo Build started on `date`
        - ng build --${BUILD_ENV}

This works for me perfectly!这对我来说完美无缺!

This yml file worked perfectly fine for me :这个 yml 文件对我来说非常好:

version: 0.2

env:
    variables:
        S3_BUCKET: "pratik-portfolio"
phases:
install:
    runtime-versions:
        nodejs: 10
    commands:
    - echo $CODEBUILD_SRC_DIR
    - npm install -y npm@latest
    - npm install -g @angular/cli
    - rm package-lock.json
pre_build:
    commands:
    - npm install
build:
    commands:
    - echo build started on `date`
    - ng build
    - ls -l -F
post_build:
    commands:
            # Clear S3 bucket.
            - aws s3 rm s3://${S3_BUCKET} --recursive
            - echo S3 bucket is cleared.
            - aws s3 cp dist/{Your app name} s3://${S3_BUCKET} --recursive
            - echo Build completed on `date`
artifacts:
    files:
        - '/'
    discard-paths: yes
    base-directory: 'dist*'
cache:
paths:
    - node_modules/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM