-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo
executable file
·94 lines (78 loc) · 2.91 KB
/
demo
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
ENV_FILE='demo.env'
BASE_YML_FILE='base.yml' #replace with base_unbuilt.yml to build yourself
DEV_YML_FILE='demo.yml' #replace with demo_unbuilt.yml to build yourself
DOCKER_TAG='demo'
DOCKER_COMPOSE_COMMAND="docker-compose -f $BASE_YML_FILE -f $DEV_YML_FILE --env-file"
POSTGRES_USER='ptr'
POSTGRES_DB='ptr_api'
LOCALSTACK_COMMAND="./mock_aws.sh 4566 3080 demoinspections.com inspector@demoinspections.com"
DB_DUMP_BACKUP_LOCATION="./db/demo_entrypoint/dump"
#create resources on localstack, it's difficult to start localstack initialized with data, so we do this manually
function aws_init() {
echo "Initializing localstack with AWS resources"
$DOCKER_COMPOSE_COMMAND $ENV_FILE exec --workdir="/opt/code/localstack/aws" \
localstack sh -c "${LOCALSTACK_COMMAND}"
echo "When container stops, data will not persist!"
echo "AWS resources have been processed!"
}
function help_init() {
echo "navigate to http://app.localhost for the frontend dashboard"
echo "username is: demo@demo.com"
echo "password is: password"
# echo "http://localhost is the public facing frontend used by clients"
}
# used to copy files from localstack to local directory
function aws_copy() {
$DOCKER_COMPOSE_COMMAND $ENV_FILE exec --workdir="/opt/code/localstack/aws" \
localstack sh -c "aws --endpoint-url=http://localhost:4566 s3 cp s3://dev-ptr-shareable ./test --recursive"
}
if [ $# -gt 0 ]; then
if [ "$1" == "start" ]; then
$DOCKER_COMPOSE_COMMAND $ENV_FILE up -d
aws_init
help_init
elif [ "$1" == "stop" ]; then
$DOCKER_COMPOSE_COMMAND $ENV_FILE down
elif [ "$1" == "reset" ]; then
$DOCKER_COMPOSE_COMMAND $ENV_FILE down -v
elif [ "$1" == "enter" ]; then
shift 1
docker exec -it $@ sh
elif [ "$1" == "log" ]; then
shift 1
docker logs --follow $@
elif [ "$1" == "destroy" ]; then
$DOCKER_COMPOSE_COMMAND $ENV_FILE down -v
docker system prune --volume --all
# docker image prune --all -f
# docker container prune
elif [ "$1" == "clean" ]; then
shift 1
$DOCKER_COMPOSE_COMMAND $ENV_FILE down
docker image rm ptr-"$@":$DOCKER_TAG -f
$DOCKER_COMPOSE_COMMAND $ENV_FILE up --no-cache -d
elif
[ "$1" == "db-backup" ]
then
$DOCKER_COMPOSE_COMMAND $ENV_FILE exec \
db pg_dump -U ${POSTGRES_USER} ${POSTGRES_DB} >"${DB_DUMP_BACKUP_LOCATION}"
elif
[ "$1" == "db-login" ]
then
$DOCKER_COMPOSE_COMMAND $ENV_FILE exec \
db sh -c \
"psql -d ${POSTGRES_DB} -U ${POSTGRES_USER}"
elif
[ "$1" == "aws-init" ]
then
aws_init
elif [ "$1" == "reload-nginx" ]; then
$DOCKER_COMPOSE_COMMAND $ENV_FILE exec \
proxy nginx -s reload
else
$DOCKER_COMPOSE_COMMAND $ENV_FILE "$@"
fi
else
$DOCKER_COMPOSE_COMMAND $ENV_FILE ps
fi