fids/run.sh

252 lines
14 KiB
Bash
Executable File

#!/usr/bin/env bash
usage() {
printf "$0 usage: \n -x: down\n -d \$DOMAIN: domain\n -t: tests\n -i integration\n" $0
exit 0
}
domain=
down=
tests=
integration=
while getopts ":hd:xti" arg; do
case $arg in
x) down=Y ;;
d) domain=${OPTARG} ;;
t) tests=Y ;;
i) integration=Y ;;
h | *) usage ;;
esac
done
if [ -n "$domain" ] && [ -n "$down" ]; then
case "$domain" in
'auth')
if [ -n "$tests" ]; then
export API_IMAGE=$USER/user-manager:test
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev down
else
export API_IMAGE=$USER/user-manager:prod
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod down
fi
;;
'flights')
if [ -n "$tests" ]; then
export API_IMAGE=$USER/flights-information:test
docker compose -f flights-domain/docker-compose.dev.yml --env-file flights-domain/.env.dev down
else
export API_IMAGE=$USER/flights-information:prod
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.prod down
fi
;;
'gateway')
if [ -n "$tests" ]; then
export API_IMAGE=$USER/gateway:test
docker compose -f gateway/docker-compose.dev.yml --env-file gateway/.env.dev down
else
export API_IMAGE=$USER/gateway:prod
docker compose -f gateway/docker-compose.yml --env-file gateway/.env.prod down
fi
;;
'screen')
if [ -n "$tests" ]; then
export CLIENT_IMAGE=$USER/screen-client:test
docker compose -f screen-domain/docker-compose.dev.yml down
else
export CLIENT_IMAGE=$USER/screen-client:prod
docker compose -f screen-domain/docker-compose.yml down
fi
;;
'browser')
if [ -n "$tests" ]; then
export CLIENT_IMAGE=$USER/browser-client:test
docker compose -f browser-domain/docker-compose.dev.yml down
else
export CLIENT_IMAGE=$USER/browser-client:prod
docker compose -f browser-domain/docker-compose.yml down
fi
;;
'elk')
export ELASTICSEARCH_IMAGE=$USER/elasticsearch:prod
export ELK_SETUP_IMAGE=$USER/elk-setup:prod
export LOGSTASH_IMAGE=$USER/logstash:prod
export KIBANA_IMAGE=$USER/kibana:prod
export CURATOR_IMAGE=$USER/curator:prod
export HEARTBEAT_IMAGE=$USER/heartbeat:prod
docker compose -f observability/docker-compose.yml -f observability/elk/extensions/curator/curator-compose.yml -f observability/elk/extensions/heartbeat/heartbeat-compose.yml --env-file observability/.env.prod down
;;
'subscription')
if [ -n "$tests" ]; then
export API_IMAGE=$USER/subs-manager:test
docker compose -f subscription-domain/docker-compose.dev.yml --env-file subscription-domain/.env.dev down
else
export API_IMAGE=$USER/subs-manager:prod
docker compose -f subscription-domain/docker-compose.yml --env-file subscription-domain/.env.prod down
fi
;;
*) 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 -t $USER/user-manager:test
export API_IMAGE=$USER/user-manager:test
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev down
if [ -n "$integration" ]; then
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev up -d
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev exec auth-api python manage.py recreate_db
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev exec auth-api python manage.py seed_db
else
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev up --abort-on-container-exit
fi
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 auth-api python manage.py recreate_db
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod exec auth-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 -t $USER/flights-information:test
export API_IMAGE=$USER/flights-information:test
docker compose -f flights-domain/docker-compose.dev.yml --env-file flights-domain/.env.dev down
docker compose -f flights-domain/docker-compose.dev.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
;;
'subscription')
export SUBSCRIPTION_MANAGER=subscription-domain/subscription-manager
docker build $SUBSCRIPTION_MANAGER -f $SUBSCRIPTION_MANAGER/Dockerfile.prod -t $USER/subs-manager:prod
if [ -n "$tests" ]; then
docker build $SUBSCRIPTION_MANAGER -f $SUBSCRIPTION_MANAGER/Dockerfile.test -t $USER/subs-manager:test
export API_IMAGE=$USER/subs-manager:test
docker compose -f subscription-domain/docker-compose.dev.yml --env-file subscription-domain/.env.dev down
docker compose -f subscription-domain/docker-compose.dev.yml --env-file subscription-domain/.env.dev up --abort-on-container-exit
else
export API_IMAGE=$USER/subs-manager:prod
docker compose -f subscription-domain/docker-compose.yml --env-file subscription-domain/.env.prod down
docker compose -f subscription-domain/docker-compose.yml --env-file subscription-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 -t $USER/gateway:test
export API_IMAGE=$USER/gateway:test
docker compose -f gateway/docker-compose.dev.yml --env-file gateway/.env.dev down
docker compose -f gateway/docker-compose.dev.yml --env-file gateway/.env.dev up -d
else
export API_IMAGE=$USER/gateway:prod
docker compose -f gateway/docker-compose.yml --env-file gateway/.env.prod down
docker compose -f gateway/docker-compose.yml --env-file gateway/.env.prod up -d
fi
;;
'screen')
if [ -n "$tests" ]; then
docker build screen-domain -f screen-domain/Dockerfile.test -t $USER/screen-client:test
export CLIENT_IMAGE=$USER/screen-client:test
docker compose -f screen-domain/docker-compose.dev.yml down
docker compose -f screen-domain/docker-compose.dev.yml up -d
else
docker build screen-domain -f screen-domain/Dockerfile.prod --build-arg "REACT_APP_ORIGIN=$REACT_APP_ORIGIN" -t $USER/screen-client:prod
export CLIENT_IMAGE=$USER/screen-client:prod
docker compose -f screen-domain/docker-compose.yml down
docker compose -f screen-domain/docker-compose.yml up -d
fi
;;
'browser')
if [ -n "$tests" ]; then
docker build browser-domain -f browser-domain/Dockerfile.test -t $USER/browser-client:test
export CLIENT_IMAGE=$USER/browser-client:test
docker compose -f browser-domain/docker-compose.dev.yml down
docker compose -f browser-domain/docker-compose.dev.yml up -d
else
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 down
docker compose -f browser-domain/docker-compose.yml up -d
fi
;;
'elk')
export ELK=observability/elk
export ELK_VERSION=8.7.1
export ELASTICSEARCH_IMAGE=$USER/elasticsearch:prod
export ELK_SETUP_IMAGE=$USER/elk-setup:prod
export LOGSTASH_IMAGE=$USER/logstash:prod
export KIBANA_IMAGE=$USER/kibana:prod
export CURATOR_IMAGE=$USER/curator:prod
export HEARTBEAT_IMAGE=$USER/heartbeat:prod
docker build $ELK/elasticsearch -f $ELK/elasticsearch/Dockerfile --build-arg "ELASTIC_VERSION=$ELK_VERSION" -t $ELASTICSEARCH_IMAGE
docker build $ELK/setup -f $ELK/setup/Dockerfile --build-arg "ELASTIC_VERSION=$ELK_VERSION" -t $ELK_SETUP_IMAGE
docker build $ELK/logstash -f $ELK/logstash/Dockerfile --build-arg "ELASTIC_VERSION=$ELK_VERSION" -t $LOGSTASH_IMAGE
docker build $ELK/kibana -f $ELK/kibana/Dockerfile --build-arg "ELASTIC_VERSION=$ELK_VERSION" -t $KIBANA_IMAGE
docker build $ELK/extensions/curator -f $ELK/extensions/curator/Dockerfile -t $CURATOR_IMAGE
docker build $ELK/extensions/heartbeat -f $ELK/extensions/heartbeat/Dockerfile --build-arg "ELASTIC_VERSION=$ELK_VERSION" -t $HEARTBEAT_IMAGE
docker compose -f observability/docker-compose.yml --env-file observability/.env.prod --profile setup up -d
docker compose -f observability/docker-compose.yml -f $ELK/extensions/curator/curator-compose.yml -f $ELK/extensions/heartbeat/heartbeat-compose.yml --env-file observability/.env.prod 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/subs-manager:prod
docker compose -f subscription-domain/docker-compose.yml --env-file subscription-domain/.env.prod down
export API_IMAGE=$USER/gateway:prod
docker compose -f gateway/docker-compose.yml --env-file gateway/.env.prod 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
export SUBSCRIPTION_MANAGER=subscription-domain/subscription-manager
docker build $SUBSCRIPTION_MANAGER -f $SUBSCRIPTION_MANAGER/Dockerfile.prod -t $USER/subs-manager:prod
export REACT_APP_ORIGIN=Frankfurt
docker build screen-domain -f screen-domain/Dockerfile.prod --build-arg "REACT_APP_ORIGIN=$REACT_APP_ORIGIN" -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 auth-api python manage.py recreate_db
docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod exec auth-api python manage.py seed_db
export API_IMAGE=$USER/subs-manager:prod
docker compose -f subscription-domain/docker-compose.yml --env-file subscription-domain/.env.prod down
docker compose -f subscription-domain/docker-compose.yml --env-file subscription-domain/.env.prod up -d
export API_IMAGE=$USER/gateway:prod
docker compose -f gateway/docker-compose.yml --env-file gateway/.env.prod down
docker compose -f gateway/docker-compose.yml --env-file gateway/.env.prod 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