fids/run.sh

144 lines
7.0 KiB
Bash
Executable File

#!/usr/bin/env bash
usage() {
printf "$0 usage: \n -x: down\n -d \$DOMAIN: domain\n -t: tests\n" $0
exit 0
}
domain=
down=
tests=
while getopts ":hd:xt" arg; do
case $arg in
x) down=Y ;;
d) domain=${OPTARG} ;;
t) tests=Y ;;
h | *) usage ;;
esac
done
if [ -n "$domain" ] && [ -n "$down" ]; then
case "$domain" in
'auth')
export API_IMAGE=$USER/user-manager:prod
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod down
;;
'flights')
export API_IMAGE=$USER/flights-information:prod
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.prod down
;;
'gateway')
export API_IMAGE=$USER/gateway:prod
docker compose -f gateway/docker-compose.yml down
;;
'screen')
export CLIENT_IMAGE=$USER/screen-client:prod
docker compose -f screen-domain/docker-compose.yml down
;;
'browser')
export CLIENT_IMAGE=$USER/browser-client:prod
docker compose -f browser-domain/docker-compose.yml down
;;
*) exit 1 ;;
esac
elif [ -n "$domain" ] && [ -z "$down" ]; then
case "$domain" in
'auth')
export USER_MANAGER=auth-domain/user-manager
docker build $USER_MANAGER -f $USER_MANAGER/Dockerfile.prod -t $USER/user-manager:prod
if [ -n "$tests" ]; then
docker build $USER_MANAGER -f $USER_MANAGER/Dockerfile.test --build-arg "BASE_IMAGE=$USER/user-manager:prod" -t $USER/user-manager:test
export API_IMAGE=$USER/user-manager:test
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod down
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.dev up --abort-on-container-exit
else
export API_IMAGE=$USER/user-manager:prod
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod down
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod up -d
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod exec usermanager-api python manage.py recreate_db
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod exec usermanager-api python manage.py seed_db
fi
;;
'flights')
export FLIGHTS_INFORMATION=flights-domain/flights-information
docker build $FLIGHTS_INFORMATION -f $FLIGHTS_INFORMATION/Dockerfile.prod -t $USER/flights-information:prod
if [ -n "$tests" ]; then
docker build $FLIGHTS_INFORMATION -f $FLIGHTS_INFORMATION/Dockerfile.test --build-arg "BASE_IMAGE=$USER/flights-information:prod" -t $USER/flights-information:test
export API_IMAGE=$USER/flights-information:test
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.dev down
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.dev up --abort-on-container-exit
else
export API_IMAGE=$USER/flights-information:prod
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.prod down
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.prod up -d
fi
;;
'gateway')
docker build gateway -f gateway/Dockerfile.prod -t $USER/gateway:prod
if [ -n "$tests" ]; then
docker build gateway -f gateway/Dockerfile.test --build-arg "BASE_IMAGE=$USER/gateway:prod" -t $USER/gateway:test
export API_IMAGE=$USER/gateway:test
docker compose -f gateway/docker-compose.yml down
docker compose -f gateway/docker-compose.yml up -d
else
export API_IMAGE=$USER/gateway:prod
docker compose -f gateway/docker-compose.yml down
docker compose -f gateway/docker-compose.yml up -d
fi
;;
'screen')
docker build screen-domain -f screen-domain/Dockerfile.prod -t $USER/screen-client:prod
export CLIENT_IMAGE=$USER/screen-client:prod
docker compose -f screen-domain/docker-compose.yml up -d
;;
'browser')
docker build browser-domain -f browser-domain/Dockerfile.prod -t $USER/browser-client:prod
export CLIENT_IMAGE=$USER/browser-client:prod
docker compose -f browser-domain/docker-compose.yml up -d
;;
*) exit 1 ;;
esac
elif [ -n "$down" ]; then
export API_IMAGE=$USER/flights-information:prod
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.prod down
export API_IMAGE=$USER/user-manager:prod
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod down
export API_IMAGE=$USER/gateway:prod
docker compose -f gateway/docker-compose.yml down
export CLIENT_IMAGE=$USER/screen-client:prod
docker compose -f screen-domain/docker-compose.yml down
export CLIENT_IMAGE=$USER/browser-client:prod
docker compose -f browser-domain/docker-compose.yml down
else
export USER_MANAGER=auth-domain/user-manager
docker build $USER_MANAGER -f $USER_MANAGER/Dockerfile.prod -t $USER/user-manager:prod
export FLIGHTS_INFORMATION=flights-domain/flights-information
docker build $FLIGHTS_INFORMATION -f $FLIGHTS_INFORMATION/Dockerfile.prod -t $USER/flights-information:prod
docker build gateway -f gateway/Dockerfile.prod -t $USER/gateway:prod
docker build screen-domain -f screen-domain/Dockerfile.prod -t $USER/screen-client:prod
docker build browser-domain -f browser-domain/Dockerfile.prod -t $USER/browser-client:prod
export API_IMAGE=$USER/flights-information:prod
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.prod down
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.prod up -d
export API_IMAGE=$USER/user-manager:prod
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod down
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod up -d
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod exec usermanager-api python manage.py recreate_db
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod exec usermanager-api python manage.py seed_db
export API_IMAGE=$USER/gateway:prod
docker compose -f gateway/docker-compose.yml down
docker compose -f gateway/docker-compose.yml up -d
export CLIENT_IMAGE=$USER/screen-client:prod
docker compose -f screen-domain/docker-compose.yml up -d
export CLIENT_IMAGE=$USER/browser-client:prod
docker compose -f browser-domain/docker-compose.yml up -d
fi