Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) colima: fix return code handling (followup to #3097) #3106

Merged
merged 20 commits into from
Jul 25, 2024
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,47 +75,56 @@ jobs:
- name: Install & Start Docker
if: env.INSTALL_DOCKER == '1'
run: |
# Uninstall colima to upgrade to the latest version
if brew list colima &>/dev/null; then
brew uninstall colima
# unlinking colima dependency: go
brew uninstall go@1.21
fi
rm -rf ~/.colima ~/.lima
brew install --HEAD colima
brew install docker

export DOCKER_CONTEXT="colima-$GITHUB_RUN_ID"
docker context create $DOCKER_CONTEXT --docker host=unix:///var/run/docker.sock
IP_BASE="192.168.172."

start_colima() {
# Find a free port
RANDOM_PORT=$((RANDOM % 16384 + 49152))
# Change IP address between attempts
local IP_SUFFIX=$1
local IP_ADDRESS="${IP_BASE}${IP_SUFFIX}"

echo "Using random port: $RANDOM_PORT for SSH"
# Find a free port in the range 10000-20000
RANDOM_PORT=$((RANDOM % 10001 + 10000))

colima start --network-address --arch x86_64 --cpu=1 --memory=1 --ssh-port $RANDOM_PORT
docker context use $DOCKER_CONTEXT
# Create Lima instance with the specific IP address
limactl create colima-${IP_ADDRESS}

if ! colima start --network-address $IP_ADDRESS --arch x86_64 --cpu=1 --memory=1 --verbose --ssh-port $RANDOM_PORT; then
tobitege marked this conversation as resolved.
Show resolved Hide resolved
echo "Failed to start Colima."
return 1
fi
}

# Attempt to start Colima
ATTEMPT_LIMIT=3
# Attempt to start Colima; 4 retries:
tobitege marked this conversation as resolved.
Show resolved Hide resolved
ATTEMPT_LIMIT=5
for ((i=1; i<=ATTEMPT_LIMIT; i++)); do
if start_colima; then

# Uninstall colima to upgrade to the latest version
if brew list colima &>/dev/null; then
brew uninstall colima
# unlinking colima dependency: go
brew uninstall go@1.21
fi
rm -rf ~/.colima ~/.lima
brew install --HEAD colima
brew install docker

IP_SUFFIX=$((100 + i)) # Increment the last IP block

if start_colima $IP_SUFFIX; then
echo "Colima started successfully."
break
else
echo "Failed to start Colima. Attempt $i/$ATTEMPT_LIMIT."
colima stop -f
colima delete
if [ $i -eq $ATTEMPT_LIMIT ]; then
colima delete
exit 1
else
colima stop -f
sleep 10
fi
fi
done

if [ $i -gt $ATTEMPT_LIMIT ]; then
echo "Failed to start Colima after $ATTEMPT_LIMIT attempts."
if [ $i -ge $ATTEMPT_LIMIT ]; then
exit 1
fi

Expand Down