2015-11-02 10:33:08 +08:00
|
|
|
#!/bin/bash
|
2017-12-14 15:02:42 +08:00
|
|
|
set -e
|
|
|
|
|
2017-12-15 07:11:00 +08:00
|
|
|
SCRIPTPATH=$(cd "$(dirname "$0")" > /dev/null; pwd -P)
|
|
|
|
SOURCE_DIR=$(cd "$SCRIPTPATH" > /dev/null; cd ../.. > /dev/null; pwd -P)
|
2017-05-18 23:36:12 +08:00
|
|
|
DATA_DIR="$SOURCE_DIR/data/postgres"
|
2015-11-02 10:33:08 +08:00
|
|
|
|
2016-09-21 06:35:50 +08:00
|
|
|
show_help() {
|
|
|
|
cat <<EOF
|
2018-08-01 14:44:27 +08:00
|
|
|
Usage: ${0##*/} [-e VAR=VAL] [--env VAR=VAL] [--env-file filename] [-h] [--init]
|
2015-11-02 10:33:08 +08:00
|
|
|
|
2018-08-01 14:44:27 +08:00
|
|
|
-e, --env set environment variables
|
|
|
|
--env-file pass in a file containing a list of environment variable assignments
|
|
|
|
--init perform first-time initialization
|
2016-09-21 06:35:50 +08:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize=""
|
2018-08-01 14:44:27 +08:00
|
|
|
ENV_ARGS=""
|
2016-09-21 06:35:50 +08:00
|
|
|
|
|
|
|
while [ "${#@}" -ne "0" ]; do
|
|
|
|
case "$1" in
|
|
|
|
-h | --help)
|
|
|
|
show_help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-i | --init)
|
|
|
|
initialize="initialize"
|
|
|
|
;;
|
2018-08-01 14:44:27 +08:00
|
|
|
-e | --env)
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
show_help
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
ENV_ARGS+=" -e $2"
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--env-file)
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
show_help
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
ENV_ARGS="--env-file=$2"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
;;
|
2016-09-21 06:35:50 +08:00
|
|
|
*)
|
|
|
|
echo "unexpected argument: $1" >& 2
|
|
|
|
show_help >& 2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Using source in: ${SOURCE_DIR}"
|
|
|
|
echo "Using data in: ${DATA_DIR}"
|
|
|
|
|
|
|
|
mkdir -p "${DATA_DIR}"
|
|
|
|
|
2018-12-31 07:45:08 +08:00
|
|
|
# 1080 mailcatcher
|
|
|
|
# 3000 puma... if you must (but unicorn is preferred)
|
|
|
|
# 9292 unicorn
|
|
|
|
# 9405 prometheus exporter
|
|
|
|
|
2019-02-18 10:11:46 +08:00
|
|
|
docker pull discourse/discourse_dev:release
|
2018-12-31 07:45:08 +08:00
|
|
|
docker run -d -p 9405:9405 -p 1080:1080 -p 3000:3000 -p 9292:9292 -v "$DATA_DIR:/shared/postgres_data:delegated" -v "$SOURCE_DIR:/src:delegated" $ENV_ARGS --hostname=discourse --name=discourse_dev --restart=always discourse/discourse_dev:release /sbin/boot
|
2016-09-21 06:35:50 +08:00
|
|
|
|
|
|
|
if [ "${initialize}" = "initialize" ]; then
|
|
|
|
echo "Installing gems..."
|
2017-04-13 00:41:23 +08:00
|
|
|
"${SCRIPTPATH}/bundle" install
|
2016-09-21 06:35:50 +08:00
|
|
|
|
|
|
|
echo "Migrating database..."
|
2017-04-13 00:41:23 +08:00
|
|
|
"${SCRIPTPATH}/rake" db:migrate
|
2017-04-13 01:33:56 +08:00
|
|
|
RAILS_ENV=test "${SCRIPTPATH}/rake" db:migrate
|
2015-11-02 10:33:08 +08:00
|
|
|
|
2016-09-21 06:35:50 +08:00
|
|
|
echo "Creating admin user..."
|
2017-04-13 00:41:23 +08:00
|
|
|
"${SCRIPTPATH}/rake" admin:create
|
2016-09-21 06:35:50 +08:00
|
|
|
fi
|