Mac Local Development - Enterprise-CMCS/macpro-mako GitHub Wiki

Workspace Setup

Before you begin development, it's important to configure your workstation properly. This section will give you an overview of what tools are installed and get you bootstrapped.

Installation

Install XCode Command Line Tools by following the installation guide.

Installing via the setup.sh Script

The tools can all be installed using this script.

  • Download the following code and save it in a file called setup.sh.
set -e

# Check that we're on a mac.
if [ ! "$OSTYPE" =~ ^darwin ](/Enterprise-CMCS/macpro-mako/wiki/-!-"$OSTYPE"-=~-^darwin-); then
  echo "ERROR:  This script is intended only for MacOS." && exit 1
fi

# Check that XCode Command Line Tools are installed.
if ! xcode-select -p > /dev/null; then
  echo "ERROR:  XCode Command Line Tools must be installed on this machine before running this script, but were not found." && exit 1
fi

# Determine what shell and rc file we might want to modify
shell=""
shellprofile=""
macprorcfile=""
if [ "$CI" != "true" ]; then
  echo "Which terminal shell do you want to configure?  Please input a number and hit Enter:"
  select selectedshell in zsh bash
  do
    case $selectedshell in
      "zsh")
        shell=$selectedshell
        shellprofile="$HOME/.zshenv"
        macprorcfile="$HOME/.macprorc"
        ;;

      "bash")
        shell=$selectedshell
        macprorcfile="$HOME/.macprorc"
        if test -f "$HOME/.bash_profile"; then
          shellprofile="$HOME/.bash_profile"
        else
          shellprofile="$HOME/.bashrc"
        fi
        ;;
      *)
        echo "ERROR:  Invalid input.  Exiting."
        exit 1
        ;;
    esac
    break
  done
else
  shell="bash"
  shellprofile="/tmp/.profile"
  macprorcfile="/tmp/.macprorc"
fi
touch $macprorcfile
touch $shellprofile

# Set some things based on chip architecture
arch=`uname -m`
homebrewprefix=""
if [ "$arch" == "arm64" ]; then
  # If we're on Apple Silicon, check that Rosetta 2 has already been installed and is running.
  if ! /usr/bin/pgrep -q oahd; then
    echo "ERROR:  Rosetta must be installed on this machine before running this script, but was not found." && exit 1
  fi
  homebrewprefix="/opt/homebrew"
else
  homebrewprefix="/usr/local"
fi

# Install HomeBrew, an OSX package manager
if ! which brew > /dev/null ; then
  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

export PATH="$homebrewprefix:$PATH"

# Install the AWS CLI, used to interact with any/all AWS services
if ! which aws > /dev/null ; then
	brew install awscli session-manager-plugin
fi

# Install jq, a command line utility for parsing JSON.
if ! which jq > /dev/null ; then
	brew install jq
fi

# Install nvm, a version manager for Node, allowing multiple versions of Node to be installed and used
if [ "$CI" != "true" ]; then
  if [ ! -f ~/.nvm/nvm.sh ]; then
    brew install nvm
  fi
else
  brew install nvm
fi
mkdir -p ~/.nvm

# Install awslogs, a utility for streaming CloudWatch logs
if ! which awslogs > /dev/null ; then
  brew install awslogs
fi

# Install bun, a super fast package manager for node
if ! which bun > /dev/null ; then
  brew install oven-sh/bun/bun
fi

# Install git, our version control system 
if ! which git > /dev/null ; then
  brew install git
fi

# Install docker, our container engine of choice 
if ! which docker > /dev/null ; then
  brew install docker
fi

# Install colima, a container runtime in which we can run Docker images
if ! which colima > /dev/null ; then
  brew install colima
fi

# Install and configure direnv, a tool for automatically setting environment variables
if ! which direnv > /dev/null ; then
  brew install direnv
fi

# Install kion-cli, a go package used to authenticate to Kion and access AWS
if ! which kion > /dev/null ; then
  brew install kionsoftware/tap/kion-cli
fi
touch ~/.kion.yml

touch $macprorcfile
echo """
### MANAGED BY MACPRO Workspace Setup - (DO NOT EDIT THIS FILE)

export NVM_DIR="$HOME/.nvm"
  [ -s "$homebrewprefix/opt/nvm/nvm.sh" ] && \. "$homebrewprefix/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "$homebrewprefix/opt/nvm/etc/bash_completion.d/nvm" ] && \. "$homebrewprefix/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

export PATH="$homebrewprefix/bin:\$PATH"
eval \"\$($homebrewprefix/bin/brew shellenv)\"

eval \"\$(direnv hook $shell)\"
""" > $macprorcfile

if ! cat $shellprofile | grep -q '### MANAGED BY MACPRO Workspace Setup - source - (DO NOT EDIT)'; then
  echo """
### MANAGED BY MACPRO Workspace Setup - source - (DO NOT EDIT)
if [ -f $macprorcfile ]; then
  source $macprorcfile
fi
### MANAGED BY MACPRO Workspace Setup - source - (DO NOT EDIT)
""" >> $shellprofile
fi
  • Open a terminal and go to the path where you saved the script

  • Change the permissions on the script to allow it to run

chmod 755 setup.sh
  • Run the script
sh setup.sh

[!note] Please note that you may be prompted to input your OS user's password, as some installation steps require higher privileges.

The script adds PATH modifications to your shell configuration file, .zshrc or .bashrc. The modifications will only take affect when you start a new terminal session or execute the configuration file by running

source ~/.zshrc 

or

source ~/.bashrc

Installing Manually

If you prefer to install things manually here is what you need to do.

Install Homebrew

Install Homebrew (if not already installed).

Run this command to see where your Homebrew is installed

which brew

Open your shell configuration file (~/.zshrc, ~/.bashrc, etc) and set the Homebrew path.

# Add homebrew to PATH
export BREW_HOME=/opt/homebrew # or the value that came back from the command above
export PATH=$BREW_HOME/bin:$BREW_HOME/sbin:$PATH
export HOMEBREW_AUTO_UPDATE_SECS="86400"

Install Packages

Install the following packages (if not already installed):

  • Install git (a version control system)
brew install git
  • Install jq (a command line utility for parsing JSON)
brew install jq
  • Install nvm (a version manager for Node that allows multiple versions of Node to be installed) and create a directory for it
brew install nvm
mkdir -p ~/.nvm
  • Install bun (a super fast package manager for node)
brew install oven-sh/bun/bun
  • Install AWS CLI (a command line tool to interact with AWS services)
brew install awscli session-manager-plugin
  • Install awslogs (a command line tool for streaming CloudWatch logs)
brew install awslogs
  • Install kion-cli (a go package used to authenticate to Kion and access AWS) and create a config file
brew install kionsoftware/tap/kion-cli
touch ~/.kion.yml
  • Install direnv (a tool for automatically setting environment variables)
brew install direnv
  • Install docker (a container engine)
brew install docker
  • Install colima (a container runtime in which you can run the Docker images)
brew install colima

Setting Environment Variables

Open your shell configuration file (~/.zshrc, ~/.bashrc, etc) and add the following values

# Add NVM to PATH for scripting. Make sure this is the last PATH variable change.
export NVM_DIR=$HOME/.nvm
  [ -s "$BREW_HOME/opt/nvm/nvm.sh" ] && \. "$BREW_HOME/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "$BREW_HOME/opt/nvm/etc/bash_completion.d/nvm" ] && \. "$BREW_HOME/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion