-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole
More file actions
executable file
·217 lines (192 loc) · 4.94 KB
/
console
File metadata and controls
executable file
·217 lines (192 loc) · 4.94 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
if [ ! -f .env ];then
echo "dot env file is required."
exit
fi
export CPU=$(uname -m)
source .env
source .functions.sh
export PHPENV=$(dirname $0)
SHELL="${SH:-bash}"
if [[ "$1" = 'info' && "$2" = 'all' ]];then
shift 2
. ./all
exit
fi
if [[ "$1" = 'info' && "$2" = 'ports' ]];then
shift 2
./ports
exit
fi
if [[ "$1" == '-V' || "$1" == '--v' ]];then
cat ${PHPENV}/etc/phpenv-release
exit 0
fi
if [[ "$1" = 'commit' ]];then
if [[ "$2" != "" ]];then
docker ps -f name=$2|grep -vE '^CONTAINER'|awk '{print "CONTAINER ID:"$1," IMAGE:"$2," NAME:" $NF}'
NAMES_NUMBER=$(docker ps -f name=$2|grep -vE '^CONTAINER'|awk '{print $1,$NF}'|wc -l)
if [ $NAMES_NUMBER -eq 1 ];then
CONTAINER_NAME=$(docker ps -f name=$2|grep -vE '^CONTAINER'|awk '{print $NF}')
COMMIT_ARG=$(docker ps|grep $CONTAINER_NAME|awk '{print $1,$2}')
echo $COMMIT_ARG
echo "docker commit $COMMIT_ARG"
IMAGE_NAME=$(docker ps -f name=$2|grep -vE '^CONTAINER'|awk '{print $2}')
echo "Do you wish to run above command to change for this image ${IMAGE_NAME}?"
select yn in "Yes" "No"; do
case $yn in
Yes ) docker commit $COMMIT_ARG; break;;
No ) exit;;
esac
done
exit
fi
if [ $NAMES_NUMBER -gt 1 ];then
echo "Unable commit by multiple names."
else
echo "container name not found."
fi
exit
else
console ps
echo "You have a running container, please select one to commit."
echo "./console commit <Name>"
exit
fi
fi
if [[ "$1" = 'help' ]];then
echo "Usage: $0 [all|info|start|stop|link|reload|secret|commit|drive|stats|<project>]"
echo " all: show all projects running status"
echo " info: show .env file"
echo " start: start .env project"
echo " stop: stop .env project"
echo " stats: view all projects stats"
echo " secret: show or generate Redis password in services/redis.yml"
echo " commit: commit image for running container"
echo " drive: run bash for drive.yml defualt service name"
echo " help: $0"
exit;
fi
if [[ "$1" = 'all' ]];then
shift 1
. ./all
exit
fi
if [ "$1" = 'info' ];then
shift 1
./info
exit
fi
if [ "$1" = 'stop' ];then
console $@
exit
fi
if [ "$1" = 'start' ];then
shift 1
console up -d $@
exit
fi
if [ "$1" = 'restart' ];then
shift 1
console restart $@
exit
fi
if [ "$1" = 'down' ];then
shift 1
console down $@
exit
fi
if [ "$1" = 'up' ];then
shift 1
console up $@
exit
fi
if [ "$1" = 'stats' ];then
shift 1
./stats
exit
fi
if [ "$1" = 'link' ];then
shift 1
./link $1
exit
fi
#reload nginx
if [ "$1" = 'reload' ];then
. ./reload
exit
fi
# Redis requirepass: show current secret, or replace default with random and print
if [ "$1" = 'secret' ]; then
print_or_rotate_redis_yml_secret
exit $?
fi
#執行容器內的命令
if [ "$1" = 'artisan' ];then
docker-compose -p ${PROJECT} exec php php $@
exit 0
fi
#Default Workspace
if [ "$1" = '' ];then
exec_bash $(get_workspace)
exit
fi
#進入ssh容器
if [ "$1" = 'ssh' ];then
exec_bash $1
fi
#進入Drive容器
if [ "$1" = 'drive' ];then
exec_bash $1 public
fi
#Check Project Image
if [ "$1" = 'build' ];then
sync_php_fpm_www_conf_from_env
if [ $? -eq 0 ];then
args=$(get_args)
#echo "docker-compose -p ${PROJECT} ${args} build --no-cache"
IMAGE_IDS=$(docker-compose -p ${PROJECT} ${args} images $2|sed 1d|awk '{print $2}')
echo $IMAGE_IDS
FOUND=0
for i in ${IMAGE_IDS}
do
if [ $FOUND -eq 0 ];then
echo "List images used by the created containers"
fi
FOUND=1
done
if [ $FOUND -eq 1 ];then
docker-compose -p ${PROJECT} ${args} images $2|sed 1d
echo
read -p "Press (\"y\") to build, or any other key to quit:" -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit;
fi
docker-compose -p ${PROJECT} ${args} $1 $2
exit
else
docker-compose -p ${PROJECT} ${args} $1 $2
exit
fi
fi
fi
#檢測是否為.env名稱,如果是就進入
if [ "$1" ];then
if [ -f envs/$1 ];then
#重新連結並進入容器
ln -sf envs/${1} .env
PROJECT=$(get_project)
echo "Link to Project of "${PROJECT}
shift 1
echo "Entering service $(get_workspace) as workspace"
console exec $(get_workspace) ${SHELL}
exit
fi
fi
if [[ "$3" != "mysqldump" ]];then
echo $CPU
echo Project: $PROJECT
fi
console $@