2015-11-01 21:33:08 -05:00
|
|
|
#!/bin/bash
|
2017-12-14 02:02:42 -05:00
|
|
|
set -e
|
|
|
|
|
2017-12-14 18:11:00 -05:00
|
|
|
SCRIPTPATH=$(cd "$(dirname "$0")" > /dev/null; pwd -P)
|
|
|
|
SOURCE_DIR=$(cd "$SCRIPTPATH" > /dev/null; cd ../.. > /dev/null; pwd -P)
|
2017-05-18 11:36:12 -04:00
|
|
|
DATA_DIR="$SOURCE_DIR/data/postgres"
|
2019-08-14 04:13:01 -04:00
|
|
|
PLUGINS_DIR="$SOURCE_DIR/plugins"
|
2015-11-01 21:33:08 -05:00
|
|
|
|
2016-09-20 18:35:50 -04:00
|
|
|
show_help() {
|
|
|
|
cat <<EOF
|
2018-08-01 02:44:27 -04:00
|
|
|
Usage: ${0##*/} [-e VAR=VAL] [--env VAR=VAL] [--env-file filename] [-h] [--init]
|
2015-11-01 21:33:08 -05:00
|
|
|
|
2018-08-01 02:44:27 -04:00
|
|
|
-e, --env set environment variables
|
|
|
|
--env-file pass in a file containing a list of environment variable assignments
|
|
|
|
--init perform first-time initialization
|
2019-11-03 20:51:35 -05:00
|
|
|
-p --net-public publish ports on container on 0.0.0.0 (less secure as users on LAN may see dev env)
|
2016-09-20 18:35:50 -04:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize=""
|
2018-08-01 02:44:27 -04:00
|
|
|
ENV_ARGS=""
|
2019-11-03 20:51:35 -05:00
|
|
|
local_publish="127.0.0.1"
|
2016-09-20 18:35:50 -04:00
|
|
|
|
|
|
|
while [ "${#@}" -ne "0" ]; do
|
|
|
|
case "$1" in
|
|
|
|
-h | --help)
|
|
|
|
show_help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-i | --init)
|
|
|
|
initialize="initialize"
|
|
|
|
;;
|
2019-11-03 20:51:35 -05:00
|
|
|
-p | --net-public)
|
|
|
|
local_publish="0.0.0.0"
|
|
|
|
;;
|
2018-08-01 02:44:27 -04: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
|
2019-08-14 04:13:01 -04:00
|
|
|
else
|
2018-08-01 02:44:27 -04:00
|
|
|
ENV_ARGS="--env-file=$2"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
;;
|
2016-09-20 18:35:50 -04:00
|
|
|
*)
|
|
|
|
echo "unexpected argument: $1" >& 2
|
|
|
|
show_help >& 2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2021-05-21 11:01:59 -04:00
|
|
|
if [[ $(docker info -f "{{.Architecture}}") != *x86_64* ]]; then
|
|
|
|
echo "WARNING: Docker architecture is not x86_64."
|
|
|
|
echo "Discourse development is unlikely to work using Docker's architecture emulation."
|
|
|
|
echo "Please try a native development installation."
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
2016-09-20 18:35:50 -04:00
|
|
|
echo "Using source in: ${SOURCE_DIR}"
|
|
|
|
echo "Using data in: ${DATA_DIR}"
|
|
|
|
|
|
|
|
mkdir -p "${DATA_DIR}"
|
|
|
|
|
2019-08-14 04:13:01 -04:00
|
|
|
mount_plugin_symlinks=""
|
2021-08-16 01:28:54 -04:00
|
|
|
for symlink in $(find $PLUGINS_DIR -maxdepth 1 -type l); do
|
2020-10-20 18:39:53 -04:00
|
|
|
# `readlink -f` doesn't work on macOS, to fix it you need to override the `readlink` with `greadlink`
|
|
|
|
# > brew install coreutils
|
|
|
|
# > ln -s "$(which greadlink)" "$(dirname "$(which greadlink)")/readlink"
|
|
|
|
# reference: https://meta.discourse.org/t/beginners-guide-to-install-discourse-for-development-using-docker/102009/124?u=aleber
|
2020-01-12 18:33:34 -05:00
|
|
|
symlink_value=$(readlink -f $symlink)
|
2020-10-20 18:39:53 -04:00
|
|
|
plugin_name=$(basename $symlink)
|
|
|
|
mount_plugin_symlinks+=" -v ${symlink_value}:/src/plugins/${plugin_name}:delegated"
|
2019-08-14 04:13:01 -04:00
|
|
|
done
|
2020-10-20 18:39:53 -04:00
|
|
|
[[ ! -z "$mount_plugin_symlinks" ]] && echo "Mounting symlinks for plugins: ${mount_plugin_symlinks}"
|
2019-08-14 04:13:01 -04:00
|
|
|
|
2021-10-08 01:40:46 -04:00
|
|
|
# 8025 mailhog
|
2018-12-30 18:45:08 -05:00
|
|
|
# 3000 puma... if you must (but unicorn is preferred)
|
|
|
|
# 9292 unicorn
|
|
|
|
# 9405 prometheus exporter
|
|
|
|
|
2019-02-17 21:11:46 -05:00
|
|
|
docker pull discourse/discourse_dev:release
|
2019-08-14 04:13:01 -04:00
|
|
|
docker run -d \
|
2021-10-08 01:40:46 -04:00
|
|
|
-p $local_publish:8025:8025 \
|
2019-11-03 20:51:35 -05:00
|
|
|
-p $local_publish:3000:3000 \
|
2021-05-21 11:24:09 -04:00
|
|
|
-p $local_publish:4200:4200 \
|
2019-11-03 20:51:35 -05:00
|
|
|
-p $local_publish:9292:9292 \
|
|
|
|
-p $local_publish:9405:9405 \
|
2019-08-14 04:13:01 -04:00
|
|
|
-v "$DATA_DIR:/shared/postgres_data:delegated" \
|
|
|
|
-v "$SOURCE_DIR:/src:delegated" \
|
2019-11-03 20:51:35 -05:00
|
|
|
-e UNICORN_BIND_ALL=true \
|
2019-08-14 04:13:01 -04:00
|
|
|
$mount_plugin_symlinks \
|
|
|
|
$ENV_ARGS \
|
|
|
|
--hostname=discourse \
|
|
|
|
--name=discourse_dev \
|
|
|
|
--restart=always \
|
|
|
|
discourse/discourse_dev:release /sbin/boot
|
2016-09-20 18:35:50 -04:00
|
|
|
|
|
|
|
if [ "${initialize}" = "initialize" ]; then
|
|
|
|
echo "Installing gems..."
|
2017-04-12 12:41:23 -04:00
|
|
|
"${SCRIPTPATH}/bundle" install
|
2016-09-20 18:35:50 -04:00
|
|
|
|
|
|
|
echo "Migrating database..."
|
2017-04-12 12:41:23 -04:00
|
|
|
"${SCRIPTPATH}/rake" db:migrate
|
2017-04-12 13:33:56 -04:00
|
|
|
RAILS_ENV=test "${SCRIPTPATH}/rake" db:migrate
|
2015-11-01 21:33:08 -05:00
|
|
|
|
2016-09-20 18:35:50 -04:00
|
|
|
echo "Creating admin user..."
|
2017-04-12 12:41:23 -04:00
|
|
|
"${SCRIPTPATH}/rake" admin:create
|
2016-09-20 18:35:50 -04:00
|
|
|
fi
|