#!/bin/bash

# Check if we are in the right place
if [ ! -d ./services ]; then
    echo "You must run this command from the project's root folder."
    exit 1
fi

if [[ $# -eq 0 ]] ; then
    docker-compose down
    docker-compose up -d
else
    UPDATE_OUT=$(docker-compose up -d --no-deps $@ 2>&1)
    if [[ $UPDATE_OUT == *"is up-to-date"* ]]; then
        echo "Image is up to date, only restarting the service..."
        docker-compose restart $@
    else
        echo "Updated image and restarted the the service."
    fi
fi
