Skip to content
Snippets Groups Projects
Select Git revision
  • fb29a210d8e5888d734ebef0cc5064b032b076b8
  • main default protected
  • open_tool_for_self_hosting
  • add-sonar-integration
4 results

infra

Blame
  • infra 1.29 KiB
    #!/usr/bin/env sh
    
    ############################################################### Usage Check ###############################################################
    # Check number of arguments
    if [ "$#" -ne 1 ]; then
        echo "Illegal number of parameters. use --run or --stop" >&2
        exit 2
    fi
    
    # Check if argument is --run or --stop
    if [ "$1" != "--run" ] && [ "$1" != "--stop" ]; then
        echo "Illegal argument. use --run or --stop" >&2
        exit 2
    fi
    ###########################################################################################################################################
    
    ENV_FILE=".env"
    DOCKER_COMPOSE_COMMAND="docker compose"
    
    # verify result of docker compose version command
    ${DOCKER_COMPOSE_COMMAND} version
    if [ $? -ne 0 ]; then
        DOCKER_COMPOSE_COMMAND="docker-compose"
    fi
    
    CPU_LIMIT=$(($(nproc)-1))
    CPU_LIMIT=$(($CPU_LIMIT <= 0 ? 1 : $CPU_LIMIT))
    
    CPU_LIMIT=${CPU_LIMIT} ${DOCKER_COMPOSE_COMMAND} kill
    
    # If argument is --run, run the docker compose file
    if [ "$1" = "--run" ]; then
        # Check if .env file exists
        if [ -f $ENV_FILE ]; then
            cp -f $ENV_FILE API/$ENV_FILE
            CPU_LIMIT=${CPU_LIMIT} ${DOCKER_COMPOSE_COMMAND} --env-file ${ENV_FILE} up --build -d
        else
            echo "Need a file named ${ENV_FILE} providing environment variables."
            exit 2
        fi
    fi
    
    exit 0