簡體   English   中英

在 AWS CodeBuild 容器中安裝 Linux Homebrew

[英]Installing Linux Homebrew in AWS CodeBuild container

我有一個 AWS CodeBuild 項目,我需要在我的 CodeBuild 容器中調用 SAM CLI。 build階段,我添加了一個命令來安裝 Linux Homebrew,以便我可以根據文檔從 AWS Homebrew Tap 安裝 SAM CLI。

但是,在運行此命令時,我收到以下錯誤。

[Container] 2020/01/20 05:29:26 Running command bash -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
-e:196: warning: Insecure world writable dir /go/bin in PATH, mode 040777
Don't run this as root!

[Container] 2020/01/20 05:29:28 Command did not exit successfully bash -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)" exit status 1
[Container] 2020/01/20 05:29:28 Phase complete: BUILD State: FAILED
[Container] 2020/01/20 05:29:28 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: bash -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)". Reason: exit status 1

我正在使用 AWS 提供的 Ubuntu 標准“3.0”構建環境。

構建規范.yml

version: 0.2
phases:
  install:
    runtime-versions:
      docker: 18
      nodejs: 10
      python: 3.8
  build:
    commands:
      - echo Installing SAM CLI
      - sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
      - brew tap aws/tap
      - brew install aws-sam-cli
      - sam version

問題:如何在 AWS CodeBuild 項目中成功安裝 Linux Homebrew?

第一個也是推薦的選項是使用 CodeBuild 使用您自己的構建映像,例如使用 [1],它是一個包含 aws sam cli 的映像。

第二個也是更困難的選擇是自己安裝 SAM CLI。 由於 brew 不能以任何方式作為 root 使用,並且 CodeBuild 構建容器以 root 身份運行,這變得棘手。 以下是我測試過的構建規范,可以確認將安裝 aws sam cli:

構建規范:

version: 0.2

phases:
    install:
        commands:
            - curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh > /tmp/install.sh
            - cat /tmp/install.sh
            - chmod +x /tmp/install.sh
            - useradd -m brewuser
            - echo "brewuser:brewuser" | chpasswd 
            - adduser brewuser sudo
            - /bin/su -c /tmp/install.sh - brewuser
            - /bin/su -c '/home/brewuser/.linuxbrew/bin/brew tap aws/tap' - brewuser
            - /bin/su -c '/home/brewuser/.linuxbrew/bin/brew install aws-sam-cli' - brewuser

build:
    commands:
        - PATH=/home/brewuser/.linuxbrew/bin:$PATH
        - sam --version

注意:根據我的測試,Python 3.8 不包含 sam cli。

基於@shariqmaws 的回答,我使用了一個包含 AWS SAM 和 Node.js 10 的公共 ECR 映像: public.ecr.aws/sam/build-nodejs10.x:latest 您可以在此處了解更多信息: https : //gallery.ecr.aws/sam/build-nodejs10.x

CloudFormation 模板:

  CodeBuildIntegrationProject:
    Type: AWS::CodeBuild::Project
    Properties:
      Artifacts:
        Type: CODEPIPELINE
      Environment:
        Type: LINUX_CONTAINER
        Image: public.ecr.aws/sam/build-nodejs10.x:latest
        ImagePullCredentialsType: CODEBUILD
        ComputeType: BUILD_GENERAL1_SMALL
      LogsConfig:
        CloudWatchLogs:
          Status: ENABLED
      Name: !Sub ${GitHubRepositoryName}-integration
      ServiceRole: !Sub ${CodeBuildRole.Arn}
      Source:
        Type: CODEPIPELINE

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM