Skip to content

Commit

Permalink
Move container cleanup step
Browse files Browse the repository at this point in the history
There should be no interim commands between taking down the system and
running it again because they increase downtime and may even fail,
blocking deployment while the system is down. This moves all cleanup
commands to the end.

It might fail and then it will block deployment. Also it shouldn't run
at this point because it increases downtime even if it doesn't fail.
  • Loading branch information
demccormack committed May 14, 2023
1 parent a85f62c commit ce70ebd
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions build_and_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ build $FRONTEND_IMAGE

! [[ "$(docker ps | grep piplayer)" ]] || docker-compose --env-file $ENV down

# Clear out old containers
CONTAINERS=$(docker ps -aq) || true
! [[ "$CONTAINERS" ]] || docker rm $CONTAINERS

docker-compose --env-file="$ENV" ${DOCKER_COMPOSE_FILES:-} up --force-recreate -d

docker ps

# Clear out old images
# Clear out old containers and images
CONTAINERS=$(docker ps -a | grep -v 'piplayer.*latest' | tail +2 | awk '{print $1}') || true
if [[ "$CONTAINERS" ]]
then
docker stop $CONTAINERS
docker rm $CONTAINERS
fi
IMAGES=$(docker images | grep '<none>' | awk '{print $3}') || true
! [[ "$IMAGES" ]] || docker rmi $IMAGES

# Report results
[[ "${PROXY_WAS:-}" == "$(image_of proxy)" ]] && echo "Proxy unchanged" || echo "Proxy has new image"
[[ "${BACKEND_WAS:-}" == "$(image_of backend)" ]] && echo "Backend unchanged" || echo "Backend has new image"
[[ "${FRONTEND_WAS:-}" == "$(image_of $FRONTEND_IMAGE)" ]] && echo "Frontend unchanged" || echo "Frontend has new image"
docker ps
echo "Done"

0 comments on commit ce70ebd

Please sign in to comment.