gpt4 book ai didi

amazon-web-services - 在 AWS CodeBuild 容器中安装 Linux Homebrew

转载 作者:行者123 更新时间:2023-12-04 04:19:13 37 4
gpt4 key购买 nike

我有一个 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。

关于amazon-web-services - 在 AWS CodeBuild 容器中安装 Linux Homebrew,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59817534/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com