Skip to content

Commit

Permalink
Fix Docker setup for macOS ARM64 CI runners
Browse files Browse the repository at this point in the history
- Replace Colima with Rancher Desktop for better CI compatibility
- Add fallback mechanisms for Docker installation on macOS
- Fix terminal-related issues in GitHub Actions environment
- Create reusable Docker setup script for macOS
- Add robust error handling and status reporting
  • Loading branch information
aaronlippold committed Feb 27, 2025
1 parent d9f4747 commit c25f12a
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 32 deletions.
59 changes: 43 additions & 16 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
echo "Architecture: $(uname -m)"
echo "Processor: $(sysctl -n machdep.cpu.brand_string)"
- name: Install Docker with Colima
- name: Install Docker with Rancher Desktop
run: |
# Install Homebrew if needed
if ! command -v brew &> /dev/null; then
Expand All @@ -137,27 +137,54 @@ jobs:
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Install Colima and Docker CLI
brew install colima docker
# Install Docker CLI
brew install docker
# Start Colima with extra resources for container builds
echo "Starting Colima..."
colima start --cpu 4 --memory 8 --disk 50 --arch aarch64
# Install Rancher Desktop for M1/M2 Macs
echo "Installing Rancher Desktop..."
brew install --cask rancher
# Wait for Docker to be fully available
echo "Waiting for Docker to start..."
timeout=30
until docker info &>/dev/null || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
# Set environment variables for Docker to use Rancher's socket
echo "Setting up Docker environment..."
mkdir -p ~/.docker
# Wait for Rancher services to start
echo "Waiting for Rancher Desktop services to start..."
timeout=120
until test -S ~/Library/Application\ Support/rancher-desktop/run/docker.sock || [ $timeout -eq 0 ]; do
echo "Waiting for Docker socket... ($timeout seconds left)"
sleep 5
((timeout-=5))
done
# Link the socket if it exists
if test -S ~/Library/Application\ Support/rancher-desktop/run/docker.sock; then
ln -sf ~/Library/Application\ Support/rancher-desktop/run/docker.sock ~/.docker/run-docker.sock
export DOCKER_HOST=unix://~/.docker/run-docker.sock
echo "DOCKER_HOST=unix://~/.docker/run-docker.sock" >> $GITHUB_ENV
echo "Docker socket linked successfully"
else
# Fallback to Docker Desktop if available
echo "Rancher Desktop failed to start, trying Docker CLI directly..."
brew install --cask docker
open -a Docker
# Wait for Docker to start
echo "Waiting for Docker to start..."
timeout=60
while ! docker info &>/dev/null && [ $timeout -gt 0 ]; do
echo "Waiting for Docker... ($timeout seconds left)"
sleep 2
((timeout-=2))
done
fi
# Verify Docker is running
if docker info &>/dev/null; then
echo "Docker is running"
docker info | grep "Server Version"
echo "Docker is running successfully"
docker info
else
echo "Docker failed to start"
colima status
echo "Docker failed to start after multiple attempts"
exit 1
fi
Expand Down
59 changes: 43 additions & 16 deletions .github/workflows/publish-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Docker with Colima
- name: Install Docker with Rancher Desktop
run: |
# Install Homebrew if needed
if ! command -v brew &> /dev/null; then
Expand All @@ -114,27 +114,54 @@ jobs:
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Install Colima and Docker CLI
brew install colima docker
# Install Docker CLI
brew install docker
# Start Colima with extra resources for container builds
echo "Starting Colima..."
colima start --cpu 4 --memory 8 --disk 50 --arch aarch64
# Install Rancher Desktop for M1/M2 Macs
echo "Installing Rancher Desktop..."
brew install --cask rancher
# Wait for Docker to be fully available
echo "Waiting for Docker to start..."
timeout=30
until docker info &>/dev/null || [ $timeout -eq 0 ]; do
sleep 1
((timeout--))
# Set environment variables for Docker to use Rancher's socket
echo "Setting up Docker environment..."
mkdir -p ~/.docker
# Wait for Rancher services to start
echo "Waiting for Rancher Desktop services to start..."
timeout=120
until test -S ~/Library/Application\ Support/rancher-desktop/run/docker.sock || [ $timeout -eq 0 ]; do
echo "Waiting for Docker socket... ($timeout seconds left)"
sleep 5
((timeout-=5))
done
# Link the socket if it exists
if test -S ~/Library/Application\ Support/rancher-desktop/run/docker.sock; then
ln -sf ~/Library/Application\ Support/rancher-desktop/run/docker.sock ~/.docker/run-docker.sock
export DOCKER_HOST=unix://~/.docker/run-docker.sock
echo "DOCKER_HOST=unix://~/.docker/run-docker.sock" >> $GITHUB_ENV
echo "Docker socket linked successfully"
else
# Fallback to Docker Desktop if available
echo "Rancher Desktop failed to start, trying Docker CLI directly..."
brew install --cask docker
open -a Docker
# Wait for Docker to start
echo "Waiting for Docker to start..."
timeout=60
while ! docker info &>/dev/null && [ $timeout -gt 0 ]; do
echo "Waiting for Docker... ($timeout seconds left)"
sleep 2
((timeout-=2))
done
fi
# Verify Docker is running
if docker info &>/dev/null; then
echo "Docker is running"
docker info | grep "Server Version"
echo "Docker is running successfully"
docker info
else
echo "Docker failed to start"
colima status
echo "Docker failed to start after multiple attempts"
exit 1
fi
Expand Down
106 changes: 106 additions & 0 deletions scripts/docker-setup-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env bash
# Helper script to set up Docker on macOS for both Intel and ARM architectures

set -e

# ANSI colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m' # No Color

echo -e "${BLUE}${BOLD}Setting up Docker for macOS${NC}"

# Check architecture
ARCH=$(uname -m)
echo "Detected architecture: $ARCH"

# Install Homebrew if needed
if ! command -v brew &> /dev/null; then
echo -e "${YELLOW}Installing Homebrew...${NC}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi

# Install Docker CLI
echo -e "${YELLOW}Installing Docker CLI...${NC}"
brew install docker

if [ "$ARCH" == "arm64" ]; then
# For Apple Silicon M1/M2 Macs
echo -e "${YELLOW}Detected Apple Silicon, installing Rancher Desktop...${NC}"
brew install --cask rancher

# Give Rancher time to start
echo "Waiting for Rancher Desktop services to start..."
timeout=120

# First try to use Rancher's Docker socket
until test -S ~/Library/Application\ Support/rancher-desktop/run/docker.sock || [ $timeout -eq 0 ]; do
if [ $(($timeout % 10)) -eq 0 ]; then
echo "Waiting for Docker socket... ($timeout seconds left)"
fi
sleep 1
((timeout--))
done

# Set up the Docker socket
if test -S ~/Library/Application\ Support/rancher-desktop/run/docker.sock; then
mkdir -p ~/.docker
ln -sf ~/Library/Application\ Support/rancher-desktop/run/docker.sock ~/.docker/run-docker.sock
export DOCKER_HOST=unix://~/.docker/run-docker.sock
echo "export DOCKER_HOST=unix://~/.docker/run-docker.sock" >> ~/.zshrc
echo -e "${GREEN}Rancher Desktop Docker socket linked successfully${NC}"
else
echo -e "${RED}Rancher Desktop did not start properly${NC}"
echo -e "${YELLOW}Trying Docker Desktop as fallback...${NC}"
brew install --cask docker

# Open Docker Desktop
open -a Docker

# Wait for Docker to start
echo "Waiting for Docker Desktop to start..."
timeout=60
while ! docker info &>/dev/null && [ $timeout -gt 0 ]; do
sleep 2
if [ $(($timeout % 10)) -eq 0 ]; then
echo "Waiting for Docker... ($timeout seconds left)"
fi
((timeout-=2))
done
fi
else
# For Intel Macs
echo -e "${YELLOW}Detected Intel Mac, installing Docker Desktop...${NC}"
brew install --cask docker

# Start Docker
open -a Docker

# Wait for Docker to start
echo "Waiting for Docker to start..."
timeout=60
while ! docker info &>/dev/null && [ $timeout -gt 0 ]; do
sleep 2
if [ $(($timeout % 10)) -eq 0 ]; then
echo "Waiting for Docker... ($timeout seconds left)"
fi
((timeout-=2))
done
fi

# Verify Docker is running
if docker info &>/dev/null; then
echo -e "${GREEN}${BOLD}Docker is running successfully!${NC}"
docker info | grep "Server Version"
else
echo -e "${RED}${BOLD}Docker failed to start after multiple attempts${NC}"
exit 1
fi

echo -e "${GREEN}${BOLD}Docker setup completed!${NC}"
echo "You can now use Docker commands normally."

0 comments on commit c25f12a

Please sign in to comment.