Skip to content

Commit

Permalink
chore(install-dev): block until DB container stabilizes (#2378)
Browse files Browse the repository at this point in the history
Co-authored-by: Joongi Kim <joongi@lablup.com>
Backported-from: main (24.09)
Backported-to: 23.09
Backport-of: 2378
  • Loading branch information
Yaminyam and achimnol committed Sep 30, 2024
1 parent 863ae5c commit 68b3b97
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
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 @@ -183,9 +183,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 @@ -691,7 +691,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 @@ -837,8 +861,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 @@ -944,7 +969,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

0 comments on commit 68b3b97

Please sign in to comment.