Skip to content

Commit

Permalink
OZ-627: 'start.sh' dynamically sets the project name and suffix (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliouzbett authored Oct 2, 2024
1 parent 3441afb commit f712761
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
11 changes: 8 additions & 3 deletions scripts/destroy-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ setupDirs
# Export more environment variables
exportPaths

# Read PROJECT_NAME from the temporary file
PROJECT_NAME=$(cat /tmp/project_name.txt)

echo "$INFO Destroying $PROJECT_NAME project..."

INSTALLED_DOCKER_VERSION=$(docker version -f "{{.Server.Version}}")
MINIMUM_REQUIRED_DOCKER_VERSION_REGEX="^((([2-9][1-9]|[3-9][0]|[0-9]{3,}).*)|(20\.([0-9]{3,}|[1-9][1-9]|[2-9][0]).*)|(20\.10\.([0-9]{3,}|[2-9][0-9]|[1][3-9])))"
if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; then
echo "$INFO Destroying demo service..."
docker compose -p ozone $dockerComposeDemoCLIOptions down -v
docker compose -p $PROJECT_NAME $dockerComposeDemoCLIOptions down -v
echo "$INFO Destroying proxy service..."
docker compose -p ozone $dockerComposeProxyCLIOptions down -v
docker compose -p $PROJECT_NAME $dockerComposeProxyCLIOptions down -v
echo "$INFO Destroying Ozone services..."
docker compose -p ozone $dockerComposeOzoneCLIOptions down -v --remove-orphans
docker compose -p $PROJECT_NAME $dockerComposeOzoneCLIOptions down -v --remove-orphans
else
echo "$ERROR Docker versions < 20.10.13 are not supported"
fi
31 changes: 27 additions & 4 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ if [ "$DEMO" == "true" ]; then
echo "→ NUMBER_OF_DEMO_PATIENTS=$NUMBER_OF_DEMO_PATIENTS"
fi

# Check if ozone-info.json exists and read project name from it
ozoneInfo="../$DISTRO_PATH/ozone-info.json"
if [ -f "$ozoneInfo" ]; then
export PROJECT_NAME=$(grep -o '"name":\s*"[^\"]*"' "$ozoneInfo" | cut -d'"' -f4)
else
export PROJECT_NAME="ozone"
fi
echo "$PROJECT_NAME" > /tmp/project_name.txt

if ! isOzoneRunning "$PROJECT_NAME"; then
echo "$INFO Starting Ozone project with name: $PROJECT_NAME"
fi

# Check if an instance of Ozone is already running
suffix=0
while isOzoneRunning "$PROJECT_NAME"; do
echo "$WARN An instance of Ozone is already running with the name: $PROJECT_NAME"
suffix=$((suffix + 1))
export PROJECT_NAME="$PROJECT_NAME-$suffix"
echo "$INFO Starting a new instance of Ozone with name: $PROJECT_NAME"
echo "$PROJECT_NAME" > /tmp/project_name.txt
done

INSTALLED_DOCKER_VERSION=$(docker version -f "{{.Server.Version}}")
MINIMUM_REQUIRED_DOCKER_VERSION_REGEX="^((([2-9][1-9]|[3-9][0]|[0-9]{3,}).*)|(20\.([0-9]{3,}|[1-9][1-9]|[2-9][0]).*)|(20\.10\.([0-9]{3,}|[2-9][0-9]|[1][3-9])))"
if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; then
Expand All @@ -40,10 +63,10 @@ if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; th

# Pull Ozone Docker images
echo "$INFO Pulling ${OZONE_LABEL:-Ozone FOSS} images..."
docker compose -p ozone $dockerComposeOzoneCLIOptions pull
docker compose -p $PROJECT_NAME $dockerComposeOzoneCLIOptions pull

# Set the Docker Compose command for Ozone
dockerComposeOzoneCommand="docker compose -p ozone $dockerComposeOzoneCLIOptions up -d --build"
dockerComposeOzoneCommand="docker compose -p $PROJECT_NAME $dockerComposeOzoneCLIOptions up -d --build"
echo "$INFO Running ${OZONE_LABEL:-Ozone FOSS}..."
echo ""
echo "$dockerComposeOzoneCommand"
Expand All @@ -57,7 +80,7 @@ if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; th

# Run the Nginx Proxy service, if $TRAEFIK!=true
if [ "$TRAEFIK" != "true" ]; then
dockerComposeProxyCommand="docker compose -p ozone $dockerComposeProxyCLIOptions up -d --build"
dockerComposeProxyCommand="docker compose -p $PROJECT_NAME $dockerComposeProxyCLIOptions up -d --build"
echo "$INFO Running Nginx proxy service (\$TRAEFIK!=true)..."
echo ""
echo "$dockerComposeProxyCommand"
Expand All @@ -69,7 +92,7 @@ if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; th

# Run the Demo service
if [ "$DEMO" == "true" ]; then
dockerComposeDemoCommand="docker compose -p ozone $dockerComposeDemoCLIOptions up -d"
dockerComposeDemoCommand="docker compose -p $PROJECT_NAME $dockerComposeDemoCLIOptions up -d"
echo "$INFO Running demo service..."
echo ""
echo "$dockerComposeDemoCommand"
Expand Down
12 changes: 12 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

export TEXT_BLUE=`tput setaf 4`
export TEXT_RED=`tput setaf 1`
export TEXT_YELLOW=`tput setaf 3`
export BOLD=`tput bold`
export RESET_FORMATTING=`tput sgr0`
INFO="$TEXT_BLUE$BOLD[INFO]$RESET_FORMATTING"
ERROR="$TEXT_RED$BOLD[ERROR]$RESET_FORMATTING"
WARN="$TEXT_YELLOW$BOLD[WARN]$RESET_FORMATTING"

function setupDirs () {
# Create the Ozone directory
Expand Down Expand Up @@ -127,6 +129,16 @@ function setNginxHostnames {

}

function isOzoneRunning {
local projectName=$1
runningContainers=$(docker ps --filter "name=${projectName}" --format "{{.Names}}")
if [ -n "$runningContainers" ]; then
return 0 # true
else
return 1 # false
fi
}

function displayAccessURLsWithCredentials {
services=()
is_defined=()
Expand Down

0 comments on commit f712761

Please sign in to comment.