discourse/bin/docker/boot_dev
Jared Reisinger 4db3f53c87 Improve the "develop inside Docker" experience
This PR is intended to work in concert with the discourse_docker changes
in https://github.com/discourse/discourse_docker/pull/292.  I have used
those changes to build a local "discourse_dev" image, and then
_**these**_ changes to easily spin up and work on Discourse and plugin
functionality.  It's working well for me, but of course YMMV.

Add `--init` and `--patch` options to bin/docker/boot_dev to make it
easier to spin up a container running Discourse out of a development
directory.

Add `bin/docker/README.md` to explain how to go about using the docker
command-line tools.

Tweak the Docker command-line tools to use the `-u` option to specify
user rather than changing to the user "inside" the container via `chpst`
(This way, we don't have to explicitly specify the HOME environment
variable, either.)

Add `bin/docker/shell` command to make it easy to jump inside the
running container.
2016-09-20 15:35:50 -07:00

75 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
SCRIPTPATH=$(cd "$(dirname "$0")"; pwd -P)
SOURCE_DIR=$(cd "$SCRIPTPATH" && cd ../.. && pwd -P)
DATA_DIR=$SOURCE_DIR/tmp/postgres
show_help() {
cat <<EOF
Usage: ${0##*/} [-h] [--init [--patch DIR]]
--init perform first-time initialization
--patch DIR patch ember-data-source with missing dist files from DIR
(for example, "--patch ~/repos/ember-source-data/dist")
requires --init to also be passed
EOF
}
initialize=""
patch_source=""
while [ "${#@}" -ne "0" ]; do
case "$1" in
-h | --help)
show_help
exit 0
;;
-i | --init)
initialize="initialize"
;;
-p | --patch)
patch_source="$2"
shift
;;
*)
echo "unexpected argument: $1" >& 2
show_help >& 2
exit 1
;;
esac
shift
done
if [ -n "${patch_source}" ] && [ "${initialize}" != "initialize" ]; then
echo "error: the --init flag is required when using --patch" >& 2
show_help >& 2
exit 2
fi
echo "Using source in: ${SOURCE_DIR}"
echo "Using data in: ${DATA_DIR}"
mkdir -p "${DATA_DIR}"
docker run -d -p 3000:3000 -v $DATA_DIR:/shared/postgres_data -v $SOURCE_DIR:/src --hostname=discourse --name=discourse_dev --restart=always discourse/discourse_dev:1.3.7 /sbin/boot
if [ "${initialize}" = "initialize" ]; then
echo "Installing gems..."
${SCRIPTPATH}/bundle install
if [ -n "${patch_source}" ]; then
echo "Patching ember-data-source-2.3.0.beta.5 gems..."
docker exec discourse_dev /bin/bash -c "mkdir -p /usr/local/lib/ruby/gems/2.3.0/gems/ember-data-source-2.3.0.beta.5/dist"
for f in "${patch_source}"/globals/*.js; do
docker cp $f discourse_dev:/usr/local/lib/ruby/gems/2.3.0/gems/ember-data-source-2.3.0.beta.5/dist/$(basename $f)
done
fi
echo "Migrating database..."
${SCRIPTPATH}/rake db:migrate
echo "Creating admin user..."
${SCRIPTPATH}/rake admin:create
fi