diff --git a/docker-compose.yml b/docker-compose.yml index 5a17168..c2b83a5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,9 @@ +x-logging: &default-logging + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + services: nginx: image: nginx:stable-alpine @@ -15,6 +21,7 @@ services: image: ${APP_IMAGE} container_name: routee-app-blue restart: unless-stopped + logging: *default-logging expose: - "8080" environment: @@ -51,6 +58,7 @@ services: image: ${APP_IMAGE} container_name: routee-app-green restart: unless-stopped + logging: *default-logging expose: - "8080" environment: @@ -116,6 +124,7 @@ services: image: grafana/tempo:latest container_name: routee-tempo restart: unless-stopped + logging: *default-logging user: "0" command: [ "-config.file=/etc/tempo.yaml" ] volumes: diff --git a/scripts/deploy.sh b/scripts/deploy.sh index ef49cb9..0a54c87 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -101,6 +101,23 @@ echo "Step 4: Removing old container ($OLD)..." docker compose -f docker-compose.yml stop $OLD || true docker compose -f docker-compose.yml rm -f $OLD || true +echo "Step 5: Cleaning up old application images..." + +PREVIOUS_IMAGE="" +if [ -f .last-deployed-tag ]; then + PREVIOUS_IMAGE=$(cat .last-deployed-tag) +fi + +APP_REPOSITORY="${APP_IMAGE%:*}" + +docker images "$APP_REPOSITORY" --format '{{.Repository}}:{{.Tag}}' | +while read -r IMAGE; do + if [ "$IMAGE" != "$APP_IMAGE" ] && + [ "$IMAGE" != "$PREVIOUS_IMAGE" ]; then + docker image rm "$IMAGE" || true + fi +done + docker image prune -f echo "$APP_IMAGE" > .last-deployed-tag