-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployment.sh
49 lines (42 loc) · 2.36 KB
/
deployment.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
USAGE="Usage: bash deployment.sh [production] [up|down|build|logs|rm]"
environment=$1
cmd=$2
if [[ ${cmd} == "up" ]]; then
cmd="up -d"
fi
if [[ ${cmd} == "rm" ]]; then
cmd="rm -f"
fi
if [[ ${cmd} == "logs" ]]; then
cmd="logs -f"
fi
if [[ ${cmd} == "build" ]]; then
cmd="up -d --build"
fi
## Production
if [[ "$environment" == "production" ]] && [[ "$2" == "down" ]]; then
docker-compose -f docker-compose.production.yml ${cmd}
elif [[ "$environment" == "production" ]] && [[ "$2" == "up" ]]; then
docker-compose -f docker-compose.production.yml ${cmd}
elif [[ "$environment" == "production" ]] && [[ "$2" == "build" ]]; then
docker-compose -f docker-compose.production.yml ${cmd}
elif [[ "$environment" == "production" ]] && [[ "$2" == "logs" ]]; then
docker-compose -f docker-compose.production.yml ${cmd}
elif [[ "$environment" == "production" ]] && [[ "$2" == "rm" ]]; then
docker ps -q --filter "name=carp_client-fastapi" | grep -q . && docker stop carp_client-fastapi || "CARP Client API Fastapi could not be stopped." && docker rm -f carp_client-fastapi > /dev/null 2>&1 && echo 'removed container' || echo 'nothing to remove' && docker rmi -f carp_client-fastapi || echo "There is no carp_client-fastapi container to purge." && docker volume rm -f carp_client-fastapi || echo "The carp_client-fastapi does not exist in volume."
## Local
elif [[ "$environment" == "local" ]] && [[ "$2" == "down" ]]; then
docker-compose -f docker-compose.local.yml ${cmd}
elif [[ "$environment" == "local" ]] && [[ "$2" == "up" ]]; then
docker-compose -f docker-compose.local.yml ${cmd}
elif [[ "$environment" == "local" ]] && [[ "$2" == "build" ]]; then
docker-compose -f docker-compose.local.yml ${cmd}
elif [[ "$environment" == "local" ]] && [[ "$2" == "logs" ]]; then
docker-compose -f docker-compose.local.yml ${cmd}
elif [[ "$environment" == "local" ]] && [[ "$2" == "rm" ]]; then
docker ps -q --filter "name=carp_client-fastapi" | grep -q . && docker stop carp_client-fastapi || "CARP Client API Fastapi could not be stopped." && docker rm -f carp_client-fastapi > /dev/null 2>&1 && echo 'removed container' || echo 'nothing to remove' && docker rmi -f carp_client-fastapi || echo "There is no carp_client-fastapi container to purge." && docker volume rm -f carp_client-fastapi || echo "The carp_client-fastapi does not exist in volume."
## Echo USAGE
else
echo "${USAGE}"
fi