Skip to content

Commit

Permalink
🐛 fix: docker 명령어 앞 sudo 추가 및 컨테이너 종료 명령어 변경 #258
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Joon-Hyeok committed Oct 6, 2024
1 parent 6d58d1e commit 3937d68
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions down-running-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,39 @@ healthcheck() {
down() {
local target=$1

log "Turning off $target container..."
sudo docker compose -p $APPLICATION down "$target"
log "Complete to turn of $target container."
log "Stopping $target container..."
if ! sudo docker stop "$target"; then
log_error "Failed to stop $target container"
return 1
fi

log "Removing $target container..."
if ! sudo docker rm "$target"; then
log_error "Failed to remove $target container"
return 1
fi

log "Successfully stopped and removed $target container."
}

main() {
local is_blue_running=$(docker container inspect blue --format='{{json .State.Status}}' | sed 's/"//g')
local is_green_running=$(docker container inspect green --format='{{json .State.Status}}' | sed 's/"//g')
local blue_start_time=$(docker container inspect blue --format='{{.State.StartedAt}}')
local green_start_time=$(docker container inspect green --format='{{.State.StartedAt}}')
local is_blue_running=$(sudo docker container inspect blue --format='{{json .State.Status}}' | sed 's/"//g')
local is_green_running=$(sudo docker container inspect green --format='{{json .State.Status}}' | sed 's/"//g')
local blue_start_time=$(sudo docker container inspect blue --format='{{.State.StartedAt}}')
local green_start_time=$(sudo docker container inspect green --format='{{.State.StartedAt}}')

if [ "$is_blue_running" = "running" ] && [ "$blue_start_time" "<" "$green_start_time" ]; then
log "Blue container started first."
if healthcheck "$GREEN_CONTAINER/$HEALTHCHECK_API"; then
down blue
down blue || { log_error "Failed to stop blue container. Exiting..."; exit 1; }
else
log_error "Failed to down blue. Exiting..."
exit 1
fi
elif [ "$is_green_running" = "running" ] && [ "$green_start_time" "<" "$blue_start_time" ]; then
log "Green container started first."
if healthcheck "$BLUE_CONTAINER/$HEALTHCHECK_API"; then
down green
down green || { log_error "Failed to stop green container. Exiting..."; exit 1; }
else
log_error "Failed to down green. Exiting..."
exit 1
Expand Down

0 comments on commit 3937d68

Please sign in to comment.