-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.bash
executable file
·130 lines (90 loc) · 2.96 KB
/
deploy.bash
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
WHITE='\033[1;37m'
NC='\033[0m'
# Define environment variables...
export APP_PORT=${APP_PORT:-8888}
export APP_SERVICE=${APP_SERVICE:-"phensim"}
export WWWUSER=${WWWUSER:-$UID}
export WWWGROUP=${WWWGROUP:-$(id -g)}
RANDOM_PASSWORD=$(date +%s | sha256sum | base64 | head -c 20)
if [ ! -d ./database/mysql ]; then
mkdir -p ./database/mysql
fi
if [ ! -d ./database/redis ]; then
mkdir -p ./database/redis
fi
# Ensure that Docker is running...
if ! docker info >/dev/null 2>&1; then
echo -e "${WHITE}Docker is not running.${NC}" >&2
exit 1
fi
if [ $# -gt 0 ]; then
# Source .env file
if [ -f ./www/phensim/.env ]; then
source ./www/phensim/.env
export DB_PASSWORD
export DB_DATABASE
export DB_USERNAME
fi
if [ "$1" == "up" ]; then
shift 1
if [ ! -f ./.deployed ]; then
source ./deploy.conf
sed "s/%PHENSIM_DOMAIN%/${PHENSIM_DOMAIN}/" ./www/phensim/.env.deploy | sed "s/%THREADS%/${THREADS}/" | sed "s/%DB_PASSWORD%/${RANDOM_PASSWORD}/" >./www/phensim/.env
if [ ! -f ./www/phensim/.env ]; then
echo -e "${WHITE}Unable to create .env file${NC}" >&2
exit 1
else
source ./www/phensim/.env
export DB_PASSWORD
export DB_DATABASE
export DB_USERNAME
fi
fi
if ! docker-compose up -d; then
echo -e "${WHITE}Unable to start all containers${NC}" >&2
exit 1
fi
elif [ "$1" == "deploy" ]; then
echo -e "${WHITE}Deploying PHENSIM${NC}" >&2
if ! docker-compose exec -u phensim "$APP_SERVICE" composer install --no-dev; then
echo -e "${WHITE}Unable to install PHP dependencies${NC}" >&2
exit 1
fi
if ! docker-compose exec -u phensim "$APP_SERVICE" php artisan key:generate --force; then
echo -e "${WHITE}Unable to generate secret key${NC}" >&2
exit 1
fi
if ! docker-compose exec -u phensim "$APP_SERVICE" php artisan migrate:fresh --seed --force; then
echo -e "${WHITE}Unable to migrate database${NC}" >&2
exit 1
fi
if ! docker-compose exec -u phensim "$APP_SERVICE" php artisan import:database; then
echo -e "${WHITE}Unable to import PHENSIM database${NC}" >&2
exit 1
fi
touch ./.deployed
elif [ "$1" == "composer" ]; then
shift 1
docker-compose exec -u phensim "$APP_SERVICE" composer "$@"
elif [ "$1" == "artisan" ] || [ "$1" == "art" ]; then
shift 1
docker-compose exec -u phensim "$APP_SERVICE" php artisan "$@"
elif [ "$1" == "tinker" ]; then
shift 1
docker-compose exec -u phensim "$APP_SERVICE" php artisan tinker
elif [ "$1" == "shell" ] || [ "$1" == "bash" ]; then
shift 1
docker-compose exec -u phensim "$APP_SERVICE" bash
elif [ "$1" == "root-shell" ]; then
shift 1
docker-compose exec "$APP_SERVICE" bash
elif [ "$1" == "schedule" ]; then
shift 1
docker-compose exec -u phensim "$APP_SERVICE" php artisan schedule:run
else
docker-compose "$@"
fi
else
docker-compose ps
fi