Skip to content
Snippets Groups Projects
run.sh 1.96 KiB
#!/bin/bash
# Default mode
mode="dev"
docker="false"

#
# Run Script for AURA Steering
#
# Call with one of these parameters:
#
# - init
# - dev
# - prod
# - test

# - docker:build
# - docker:push
# - docker:dev
# 

if [[ $* =~ ^(init|dev|prod|test|build|push|serve)$ ]]; then
	mode=$1
fi

if [[ "$1" == *"docker:"* ]]; then
	docker="true"
	mode=${1#*:}
fi


echo "[ Run mode=$mode ]"
echo "[ Docker=$docker ]"



# +++ DEFAULT COMMANDS +++ #

if [[ $docker == "false" ]]; then

	### Initializes the project (Development) ###

	if [[ $mode == "init" ]]; then
		echo "Creating Python VirtualEnvironment"
		python3.8 -m venv python
		echo "Activate Environment"
		source python/bin/activate
        echo "Install dependencies"
        pip3 install -r requirements.txt
        echo "Next you need to create the configuration, run fixtues, migrations and create a superuser."
	fi

	### Runs Steering in development mode (Virtualenv) ###

	if [[ $mode == "dev" ]]; then
		echo "Activating Python Environment"
		source python/bin/activate
        python manage.py runserver
	fi

	### Runs Steering in production mode (WSGI) ###

	if [[ $mode == "prod" ]]; then
		echo "!!! Not yet implemented !!!"
		#gunicorn -c config/gunicorn.conf.py src.app:app
	fi

	### Runs the test-cases ###

	if [[ $mode == "test" ]]; then
		echo "!!! Not yet implemented !!!"
	fi

fi


# +++ DOCKER COMMANDS +++ #

if [[ $docker == "true" ]]; then
	BASE_D=$(realpath "${BASH_SOURCE%/*}/")

	### Runs Steering from Docker ###

	if [[ $mode == "dev" ]]; then
		exec sudo docker run --rm -it \
            -u $UID:$GID \
            -p 127.0.0.1:8000:8000 \
            -v "$BASE_D":/srv autoradio/steering /srv/manage.py \
            runserver 0.0.0.0:8000
	fi

	### Create Docker Image from local project ###

	if [[ $mode == "build" ]]; then
		exec sudo docker build -t autoradio/steering .
	fi

	### Pushes the latest Docker Image to Docker Hub ###

	if [[ $mode == "push" ]]; then
		exec sudo docker push autoradio/steering
	fi
fi