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

* colima: fix return code handling; added delay before retry; 4 retries

* moved docker context outside of function

* changed delete occurence; added logs output

* removed delete; trying to add more logging

* fix typo

* changed logging to github-style. maybe this finally shows up.

* reverted context; loop now with install+delete and alternating IP

* fix local keyword

* try limactl for creating an instance for IP

* revert IP change attempts

* actually return 0 in start_colima

* moved install out of loop again

* another to avoid duplicate start of colima via limactl

* added --init call for lima.yaml file creation

* dont trust an LLM to give you flags...

* Update run-unit-tests.yml
This commit is contained in:
tobitege
2024-07-25 21:16:02 +02:00
committed by GitHub
parent d0217b84ef
commit 22c7bca556

View File

@@ -75,50 +75,48 @@ jobs:
- name: Install & Start Docker
if: env.INSTALL_DOCKER == '1'
run: |
INSTANCE_NAME="colima-${GITHUB_RUN_ID}"
# 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
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
start_colima() {
# Find a free port
RANDOM_PORT=$((RANDOM % 16384 + 49152))
# Find a free port in the range 10000-20000
RANDOM_PORT=$((RANDOM % 10001 + 10000))
echo "Using random port: $RANDOM_PORT for SSH"
colima start --network-address --arch x86_64 --cpu=1 --memory=1 --ssh-port $RANDOM_PORT
docker context use $DOCKER_CONTEXT
# Original line:
if ! colima start --network-address --arch x86_64 --cpu=1 --memory=1 --verbose --ssh-port $RANDOM_PORT; then
echo "Failed to start Colima."
return 1
fi
return 0
}
# Attempt to start Colima
ATTEMPT_LIMIT=3
# Attempt to start Colima for 5 total attempts:
ATTEMPT_LIMIT=5
for ((i=1; i<=ATTEMPT_LIMIT; i++)); do
if start_colima; then
echo "Colima started successfully."
break
else
echo "Failed to start Colima. Attempt $i/$ATTEMPT_LIMIT."
colima stop -f
sleep 10
colima delete -f
if [ $i -eq $ATTEMPT_LIMIT ]; then
colima delete
else
colima stop -f
exit 1
fi
sleep 10
fi
done
if [ $i -gt $ATTEMPT_LIMIT ]; then
echo "Failed to start Colima after $ATTEMPT_LIMIT attempts."
exit 1
fi
# For testcontainers to find the Colima socket
# https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock