buildkite / elastic-ci-stack-for-ec2-mac

CloudFormation template for Auto Scaling AWS EC2 Mac based Buildkite Agents
MIT License
9 stars 5 forks source link

Homebrew missing from path in install script on ARM based Macs #9

Closed meyer9 closed 2 years ago

meyer9 commented 2 years ago

The setup instructions and script for OSX seem like they could be improved for ARM-based Macs.

In the install script, there are a few commands that invoke brew. On ARM-based Macs, Homebrew is installed to a different location (/opt/homebrew) and isn't accessible without running the user's zshrc file.

I'm not sure what the preferred way of clarifying this is. I wrote a small wrapper script to just invoke /opt/homebrew/bin/brew with the same arguments, but it seems like the script should just run the brew commands from the user's shell. su - ec2-user -c seems to run commands with a stripped down path.

Also, since brew is required, maybe it should be added as a step to the docs when building the AMI: https://buildkite.com/docs/agent/v3/elastic-ci-stack-for-ec2-mac/autoscaling-mac-metal#step-2-build-an-ami.

Logs from /var/log/amazon/ec2/ec2-macos-init.log:

zsh:1: command not found: brew
sed: /opt/homebrew/etc/buildkite-agent/buildkite-agent.cfg: No such file or directory
/usr/local/aws/ec2-macos-init/instances/i-013645d279fef9d93/userdata: line 11: /opt/homebrew/etc/buildkite-agent/buildkite-agent.cfg: No such file or directory
/usr/local/aws/ec2-macos-init/instances/i-013645d279fef9d93/userdata: line 12: /opt/homebrew/etc/buildkite-agent/buildkite-agent.cfg: No such file or directory
zsh:1: command not found: brew
] and err: exit status 127
2022/09/23 05:28:23.597571 Successfully completed processing of priority level 5
2022/09/23 05:28:23.597603 Writing instance history for instance i-013645d279fef9d93...
2022/09/23 05:28:23.603565 Successfully wrote instance history
2022/09/23 05:28:23.603628 EC2 macOS Init completed in 2m4.431552917s

My workaround (added to /usr/local/bin/brew):

#!/bin/bash

/opt/homebrew/bin/brew $@
meyer9 commented 2 years ago

looks like this is resolved on the macos docs

dylanandersenhs commented 1 year ago

@meyer9 , where did you see this added in the docs? For context, I also ran into this and was about to file an issue when I saw this one already created. My workaround was to add -i to the UserData commands so it loaded the path correctly so the brew command was found. So su - "${user}" -c 'brew install buildkite/buildkite/buildkite-agent' became su - "${user}" -i -c 'brew install buildkite/buildkite/buildkite-agent' for the two su commands.