forked from ledgersmb/ledgersmb-dev-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsmb-dev
executable file
·187 lines (154 loc) · 5.71 KB
/
lsmb-dev
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
#!/bin/bash
# set -x
scriptdir=$(dirname "$(readlink -f "$0")")
scriptname=$(readlink -f "$0")
if [[ -n "$(which docker-compose)" ]];
then
DOCKER_COMPOSE=docker-compose
else
if docker compose >/dev/null 2>/dev/null
then
DOCKER_COMPOSE="docker compose"
else
echo "Error: Missing 'docker compose' or 'docker-compose'" 1>&2
exit 1
fi
fi
[[ -d $HOME/bin ]] && [[ ! -e $HOME/bin/lsmb-dev ]] && ln -s $scriptname $HOME/bin/lsmb-dev
if [ -f $scriptdir/.local/.env ]; then
source $scriptdir/.local/.env
fi
export COMPOSE_PROJECT_NAME=ld$1
shift
_CWD=$(dirname $(perl -e "use Cwd qw(realpath); print realpath '$0'"))
BROWSER=${BROWSER:-chrome}
BROWSERS_COUNT=${BROWSERS_COUNT:-5}
export HOME_DEV=${HOME_DEV:-$PWD/.local}
# Make sure that $HOME_DEV exists
if [ ! -d $HOME_DEV ]; then
mkdir $HOME_DEV
fi
if [ ! -f $scriptdir/selenium/docker-compose-${BROWSER}.yml ]; then
echo "Unconfigured browser $BROWSER. Please define $_CWD/selenium/docker-compose-${BROWSER}.yml"
exit
fi
# define a log output function
show_logs() { # shows the last 5 minutes of logs for the lsmb container
cat <<-EOF
======================================
EOF
sleep 5; # need a little time for the logs to get updated unfortunately
docker logs --since $(( `date "+%s"` - (5*60) )) "${COMPOSE_PROJECT_NAME}_lsmb";
cat <<-EOF
======================================
EOF
}
is_container_running() {
local z;
z=`docker ps --filter "status=running" --filter="name=${COMPOSE_PROJECT_NAME}_lsmb" --quiet 2>/dev/null`;
test -n "$z";
}
show_result() {
local DBPort
local HostPort
local IpAddr_db
local IpAddr_host
local IpAddr_mailhog
local IpAddr_lsmb
local IpAddr_proxy
# report the IP address in the form of URLs
DBPort=`docker inspect --format='{{(index (index .NetworkSettings.Ports "5432/tcp") 0).HostPort}}' "${COMPOSE_PROJECT_NAME}_db"`
HostPort=`docker inspect --format='{{(index (index .NetworkSettings.Ports "80/tcp") 0).HostPort}}' "${COMPOSE_PROJECT_NAME}_proxy"`
IpAddr_host=`hostname`
IpAddr_db=`docker inspect -f "{{.NetworkSettings.Networks.${COMPOSE_PROJECT_NAME}_default.IPAddress}}" "${COMPOSE_PROJECT_NAME}_db"`
IpAddr_mailhog=`docker inspect -f "{{.NetworkSettings.Networks.${COMPOSE_PROJECT_NAME}_default.IPAddress}}" "${COMPOSE_PROJECT_NAME}_mailhog"`
Port_mailhog=`docker inspect --format='{{(index (index .NetworkSettings.Ports "8025/tcp") 0).HostPort}}' "${COMPOSE_PROJECT_NAME}_mailhog"`
IpAddr_proxy=`docker inspect -f "{{.NetworkSettings.Networks.${COMPOSE_PROJECT_NAME}_default.IPAddress}}" "${COMPOSE_PROJECT_NAME}_proxy"`
IpAddr_lsmb=`docker inspect -f "{{.NetworkSettings.Networks.${COMPOSE_PROJECT_NAME}_default.IPAddress}}" "${COMPOSE_PROJECT_NAME}_lsmb"`
Port_lsmb=`docker inspect --format='{{(index (index .NetworkSettings.Ports "9000/tcp") 0).HostPort}}' "${COMPOSE_PROJECT_NAME}_lsmb"`
cat <<-EOF
======================================
== LedgerSMB '$CurrentBranch'
== should be available at
======================================
host : http://${IpAddr_host}:${HostPort}
mailhog : http://${IpAddr_host}:${Port_mailhog}
dev (login)* : http://${IpAddr_host}:${Port_lsmb}/login.pl
dev (setup)* : http://${IpAddr_host}:${Port_lsmb}/setup.pl
db : postgresql://${IpAddr_host}:${DBPort}
mailhog : http://${IpAddr_mailhog}:8025
psgi : http://${IpAddr_lsmb}:5762
proxy (login): http://${IpAddr_proxy}/login.pl
proxy (setup): http://${IpAddr_proxy}/setup.pl
dev (login)* : http://${IpAddr_lsmb}:9000/login.pl
dev (setup)* : http://${IpAddr_lsmb}:9000/setup.pl
db : postgresql://${IpAddr_db}:5432
======================================
* Only available if 'make serve' is running.
EOF
}
# Check we are actually in a LedgerSMB repo
DirName=`git rev-parse --show-toplevel`; # retrieve the git toplevel dir
CurrentBranch=`git rev-parse --abbrev-ref HEAD`
if ! test -r "${DirName}/lib/LedgerSMB.pm"; then
cat <<-EOF
========================================
== ERROR ERROR ERROR ERROR ERROR ==
========================================
== You don't appear to be running me ==
== from a valid LedgerSMB repository ==
========================================
EOF
exit 9
fi
# Check for a local (non repo) version of the yml file
if test -r $_CWD/docker-compose-local.yml; then
F="$_CWD/docker-compose-local.yml"
else
F="$_CWD/docker-compose.yml"
fi
SCALE=""
if test "$1" = "up" ; then
SCALE="--scale $BROWSER=$BROWSERS_COUNT"
elif test "$1" = "status" ; then
if is_container_running ; then
show_result
exit 0
else
echo "No container running"
exit 1
fi
fi
# generate and start the containers
USER="$(id -u):$(id -g)" $DOCKER_COMPOSE \
-f "$F" \
-f $_CWD/selenium/docker-compose.yml \
-f $_CWD/selenium/docker-compose-$BROWSER.yml \
"$@" $SCALE
if test "$1" = "start" -o "$1" = "restart" -o "$1" = "up" ; then
# don't try to report the ip and url if the command is one of
# pull, rm, stop,
if is_container_running; then
show_result
else
show_logs
fi
elif test "$1" = "rm"; then
# Remove networks
docker network rm ${COMPOSE_PROJECT_NAME}_default
docker network rm ${COMPOSE_PROJECT_NAME}_grid
docker network rm ${COMPOSE_PROJECT_NAME}_internal
fi
if ! test -e Makefile.local ; then
cat >Makefile.local <<-EOF
CONTAINER=${COMPOSE_PROJECT_NAME}_lsmb
#PHERKIN_EXTRA_OPTS=--theme=light
#DOCKER_CMD=
#PHERKIN_OPTS=
EOF
echo "Created Makefile.local causing e.g. 'make test' to run in the container"
else
if test -z "`grep ${COMPOSE_PROJECT_NAME}_lsmb Makefile.local`" ; then
echo "'Makefile.local' missing reference to container '${COMPOSE_PROJECT_NAME}_lsmb\nplease update it manually"
fi
fi