I have an AWS CodeBuild project, and I need to call the SAM CLI inside my CodeBuild container. In the build phase, I added a command to install Linux Homebrew, so that I can install the SAM CLI from the AWS Homebrew tap, per the documentation.
However, upon running this command, I am receiving the error below.
[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
I'm using the Ubuntu Standard "3.0" build environment, that AWS provides.
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
Question: How can I successfully install Linux Homebrew inside an AWS CodeBuild project?
First and recommended option is to bring your own build image with CodeBuild, e.g. use [1] which is an image that includes aws sam cli.
Second and more difficult option is to install the SAM CLI yourself. Since brew cannot be used as root in any way and the CodeBuild build container is running as root, this gets tricky. Following is a buildspec I have tested and can confirm will install the 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
Note: As per my tests, Python 3.8 does not include sam cli.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With