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

chore(install-dev): block until DB container stabilizes #2378

Merged
merged 13 commits into from
Sep 30, 2024
1 change: 1 addition & 0 deletions changes/2378.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Explicitly wait for readiness of the Docker daemon and the compose stack before pouring database fixtures in `install-dev.sh` for when installing at the provisioning stage of Codespaces and integration tests in CI.
33 changes: 29 additions & 4 deletions scripts/install-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ show_guide() {
echo " > ${WHITE}./backend.ai run python -c \"print('Hello World\\!')\"${NC}"
show_info "How to run docker-compose:"
if [ ! -z "$docker_sudo" ]; then
echo " > ${WHITE}${docker_sudo} docker compose -f docker-compose.halfstack.current.yml up -d ...${NC}"
echo " > ${WHITE}${docker_sudo} docker compose -f docker-compose.halfstack.current.yml up -d --wait ...${NC}"
else
echo " > ${WHITE}docker compose -f docker-compose.halfstack.current.yml up -d ...${NC}"
echo " > ${WHITE}docker compose -f docker-compose.halfstack.current.yml up -d --wait ...${NC}"
fi
if [ $EDITABLE_WEBUI -eq 1 ]; then
show_info "How to run the editable checkout of webui:"
Expand Down Expand Up @@ -695,7 +695,31 @@ eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
EOS

wait_for_docker() {
# Wait for Docker to start
max_wait=60
count=0

if ! command -v docker &> /dev/null
then
echo "Docker could not be found. Exiting."
exit 1
fi

until docker info >/dev/null 2>&1
do
count=$((count+1))
if [ "$count" -ge "$max_wait" ]; then
echo "Timeout waiting for Docker to start. Exiting."
exit 1
fi
echo "Waiting for Docker to launch..."
sleep 1
done
}

setup_environment() {
wait_for_docker
# Install pyenv
if ! type "pyenv" >/dev/null 2>&1; then
if [ -d "$HOME/.pyenv" ]; then
Expand Down Expand Up @@ -838,8 +862,9 @@ setup_environment() {
}

configure_backendai() {
wait_for_docker
show_info "Creating docker compose \"halfstack\"..."
$docker_sudo docker compose -f "docker-compose.halfstack.current.yml" up -d
$docker_sudo docker compose -f "docker-compose.halfstack.current.yml" up -d --wait
$docker_sudo docker compose -f "docker-compose.halfstack.current.yml" ps # You should see three containers here.

if [ $ENABLE_CUDA_MOCK -eq 1 ]; then
Expand Down Expand Up @@ -959,7 +984,7 @@ configure_backendai() {
if [ "${CODESPACES}" = "true" ]; then
$docker_sudo docker stop $($docker_sudo docker ps -q)
$docker_sudo docker compose -f "docker-compose.halfstack.current.yml" down
$docker_sudo docker compose -f "docker-compose.halfstack.current.yml" up -d
$docker_sudo docker compose -f "docker-compose.halfstack.current.yml" up -d --wait
fi

# initialize the DB schema
Expand Down