标签: aws-codebuild

推送到 ECR 的 buildspec.yml 会引发此错误“命令未成功退出 $(aws ecr get-login --no-include-email --region us-east-1)”

我正在学习 codepipeline,以使用 CodeBuild 将构建推送到 ECR。下面是我的 buildspec.yml 文件和 Codebuild 日志中的错误。谁能阐明我做错了什么?提前致谢。

构建规范.yml

版本:0.2

阶段:

预构建:

commands:
  - echo Logging in to Amazon ECR.....
  - aws --version
  - $(aws ecr get-login --no-include-email --region us-east-1)
  - REPOSITORY_URI=989066xxxxxx.dkr.ecr.us-east-1.amazonaws.com/ecs-cicd-nginx
  - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
Run Code Online (Sandbox Code Playgroud)

建造:

commands:
  - echo Build started on `date`
  - echo Building the Docker image...
  - docker build -t $REPOSITORY_URI:$IMAGE_TAG .
Run Code Online (Sandbox Code Playgroud)

构建后:

commands:
  - echo Build completed on `date`
  - echo Pushing the Docker images...
  - docker push $REPOSITORY_URI:$IMAGE_TAG
  - echo …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-codepipeline amazon-ecr aws-codebuild buildspec

4
推荐指数
1
解决办法
1万
查看次数

在 CodeBuild 中从 AWS Secrets Manager 检索 RSA 密钥会损坏密钥“格式无效”

在 CodeBuild 运行期间,我从 SecretsManager 检索 rsa 密钥,这是用于访问 BitBucket 中的私有源的私钥。为此,我已将私钥复制到秘密中,然后在我的 buildspec 文件中包含以下代码片段:

  "env": {
    "secrets-manager": {
      "LOCAL_RSA_VAR": "name-of-secret"
    }
  },
Run Code Online (Sandbox Code Playgroud)

在构建规范的安装部分:

"install": {
  "commands": [
    "echo $LOCAL_RSA_VAR" > ~/.ssh/id_rsa,
    "chmod 600 ~/.ssh/id_rsa",
    "yarn install"
  ]
},
Run Code Online (Sandbox Code Playgroud)

然而,这总是会出现错误:

Load key "/root/.ssh/id_rsa": invalid format
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.
Run Code Online (Sandbox Code Playgroud)

为了确定密钥是否错误,我尝试将 rsa_id 文件上传到 S3,然后从那里下载它并使用以下命令来使用它:

"install": {
  "commands": [
    "aws s3 cp s3://the-bucket-name/id_rsa ~/.ssh/id_rsa",
    "chmod 600 ~/.ssh/id_rsa",
    "yarn install"
  ]
},
Run Code Online (Sandbox Code Playgroud)

这很好用。

所以我想问题是...有人尝试过这个并且取得了更好的成功吗?你能想到我有什么做得不对的地方吗?

environment-variables ssh-keys aws-codepipeline aws-codebuild aws-secrets-manager

4
推荐指数
1
解决办法
1925
查看次数

AWS CDK CodePipeline 在源代码和构建之间添加一个阶段

我遵循使用 CDK Pipelines 的持续集成和交付 (CI/CD)指南来实现 CodePipeline。我想知道如何在 CDK 中的管道中添加一个阶段,该阶段将在Source阶段之后但Build阶段之前运行。

这是我的管道代码:

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { Repository } from 'aws-cdk-lib/aws-codecommit';
import { CodePipeline, CodePipelineSource, ShellStep } from 'aws-cdk-lib/pipelines';

export class MyPipelineStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const repo = Repository.fromRepositoryName(this, 'CogClientRepo', 'cog-client');

    const pipeline = new CodePipeline(this, 'Pipeline', {
      pipelineName: 'MyPipeline',
      synth: new ShellStep('Synth', {
        input: CodePipelineSource.codeCommit(repo, 'main'),
        commands: …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services typescript aws-codepipeline aws-codebuild aws-cdk

4
推荐指数
1
解决办法
3544
查看次数

Rails 的 AWS CodeBuild 进程无法安装 pg gem

我正在尝试使用简单的 3 步 CodePipeline 流程将 Rails 部署到 Elastic Beanstalk。步骤 1 从 GitHub 获取源代码,将其提供给 CodeBuild,然后 CodeBuild 应创建构建并将其传递给 EB。

由于某种原因,当 CodeBuild 进程到达pggem 时,它失败并出现以下错误:

Fetching pg 1.3.5
Installing pg 1.3.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/root/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pg-1.3.5/ext
/root/.rbenv/versions/2.7.2/bin/ruby -I
/root/.rbenv/versions/2.7.2/lib/ruby/2.7.0 -r ./siteconf20220419-56-10cqcfm.rb
extconf.rb
Calling libpq with GVL unlocked
checking for pg_config... yes
Using config values from /usr/bin/pg_config
Using libpq from /usr/lib64
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking …
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails amazon-web-services aws-codepipeline aws-codebuild

4
推荐指数
1
解决办法
1242
查看次数

unhandledRejection ReferenceError:未定义标头 - 使用 AWS codebuild 构建 Next.js 14 应用程序

我有一个 Next.js 应用程序,多年来我一直使用 AWS codebuild 构建该应用程序,没有出现任何问题。

我最近将项目更新到 Next.js 14(从 13 开始),现在构建失败并出现以下错误:

unhandledRejection ReferenceError: Headers is not defined
    at Object.<anonymous> (/codebuild/output/src3629032198/src/node_modules/next/dist/server/web/spec-extension/adapters/headers.js:32:30)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at Module.require (node:internal/modules/cjs/loader:1100:19)
    at Module.mod.require (/codebuild/output/src3629032198/src/node_modules/next/dist/server/require-hook.js:64:28)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/codebuild/output/src3629032198/src/node_modules/next/dist/server/api-utils/index.js:63:18)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
Run Code Online (Sandbox Code Playgroud)

这似乎是 Next.js 代码库本身的错误。

我自己的代码在任何地方都没有引用“标题”。

还有其他人遇到过这个问题吗?有人可以提出任何解决方案吗?

可能有用的信息

我的 package.json NPM 构建脚本是:

"build": "NEXT_PUBLIC_VERSION=$npm_package_version NEXT_PUBLIC_DATE=$(date +%s) next build",
Run Code Online (Sandbox Code Playgroud)

我的 buildspec.yml 文件是:

version: 0.2
phases:
  pre_build:
    commands:
      - npm install
  build:
    commands:
      - npm run build …
Run Code Online (Sandbox Code Playgroud)

javascript amazon-web-services aws-codebuild next.js

4
推荐指数
1
解决办法
782
查看次数

为什么我的AWS CodeBuild命令没有运行?

我正在尝试将AWS CodeBuild用于我的项目.我的构建正在运行aws/codebuild/docker:1.12.1图像.这是我的buildspec.yml,它来自AWS Docker Sample

version: 0.1

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION)
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...          
      - docker build -t $IMAGE_REPO_NAME .
  post-build:
    commands:
      - echo Build completed on `date`
      - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
      - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
Run Code Online (Sandbox Code Playgroud)

所有环境变量都在构建配置中定义.但这是我的CodeBuild日志输出:

[Container] 2017/02/16 22:04:24 Waiting for agent
[Container] 2017/02/16 22:04:33 Phase is DOWNLOAD_SOURCE
[Container] 2017/02/16 22:04:34 …
Run Code Online (Sandbox Code Playgroud)

docker aws-codebuild

3
推荐指数
1
解决办法
1993
查看次数

CodeBuild 源阶段的 terraform AWS CodePipeline 配置

我正在尝试使用 terraform 创建 CodePipeline 作业。我已经有一个可用的 CodeBuild 项目。这是我的资源:

resource "aws_codepipeline" "my-project" {
  name     = "my-project"
  role_arn = "${aws_iam_role.my-project-codepipeline.arn}"

  artifact_store {
    location = "${aws_s3_bucket.my-artifacts.bucket}"
    type     = "S3"
  }

  stage {
    name = "Source"

    action {
      name     = "Source"
      category = "Source"
      owner    = "AWS"
      provider = "CodeCommit"
      version  = "1"

      configuration {
        ProjectName = "my-project"
        Branch      = "master"
      }
    }
  }

  stage {
    name = "Build"

    action {
      name     = "Build"
      category = "Build"
      owner    = "AWS"
      provider = "CodeBuild"
      version  = …
Run Code Online (Sandbox Code Playgroud)

terraform aws-codepipeline aws-codebuild

3
推荐指数
1
解决办法
2670
查看次数

使用AWS CodeBuild构建角度项目

我们有一个Angular项目,我们正在尝试使用AWS CodePipeline来部署项目.

我们已将项目推送到CodeCommit存储库.

现在,我们面临着使用AWS CodeBuild生成构建的挑战.在CodeBuild中,构建定义是

phases:
  build:
    commands:
      - npm install && ng build-prod
Run Code Online (Sandbox Code Playgroud)

我们收到错误 ng: not found

我们还尝试了以下构建定义:

phases:
      build:
        commands:
          - npm install && run build-prod
Run Code Online (Sandbox Code Playgroud)

我们得到的错误是 run: not found

此外,我们不确定我们必须在"输出文件"字段中输入什么.

请帮忙..!!

continuous-integration node.js aws-codecommit aws-codepipeline aws-codebuild

3
推荐指数
2
解决办法
4284
查看次数

YAML_FILE_ERROR消息:容器标签的数量错误,预期为1

我是AWS CodePipeline的新手,并且在AWS CodeBuild上遇到此错误

“ YAML_FILE_ERROR消息:容器标签的数量错误,预期为1”

我为aspnet core 2.1项目设置了带有CodeBuild和CloudFormation的AWS CodePipeline。这是我的buildspec.yml

 {
  "name": "Utility",
  "source": {
    "type": "S3",
     "location": "<location>/windows-dotnetcore.zip"
 },
    "artifacts": {
    "type": "S3",
    "location": "<location>",
    "packaging": "ZIP",
    "name": "Utility.zip"
  },
  "environment": {
  "type": "LINUX_CONTAINER",
  "image": "aws/codebuild/dot-net:core-2.1",
  "computeType": "BUILD_GENERAL1_SMALL"
 },
 "serviceRole": "<value>",
 "encryptionKey": "<value>"
 }
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-codebuild

3
推荐指数
2
解决办法
1696
查看次数

上传 CodeBuild 工件 *如果* 它们存在

我有一个简单的 CodeBuild 规范,它定义了测试运行后要上传的工件:

artifacts:
  files:
    - cypress/**/*.png
  discard-paths: yes
Run Code Online (Sandbox Code Playgroud)

仅当测试操作失败(捕获失败测试屏幕的屏幕截图)并成功上传到 S3 时才会生成这些工件。

在测试成功的情况下,不会.png生成任何文件并且 CodeBuild 操作失败:

[Container] 2018/09/21 20:06:34 Expanding cypress/**/*.png
[Container] 2018/09/21 20:06:34 Phase complete: UPLOAD_ARTIFACTS Success: false
[Container] 2018/09/21 20:06:34 Phase context status code: CLIENT_ERROR Message: no matching artifact paths found
Run Code Online (Sandbox Code Playgroud)

如果构建规范中存在文件,是否可以有条件地上传文件?

或者,我可以使用s3 cli-- 在这种情况下,我需要一种方法来轻松访问存储桶名称和工件键。

amazon-web-services aws-codepipeline aws-codebuild

3
推荐指数
1
解决办法
2291
查看次数