diff --git a/.gitignore b/.gitignore index 9dfa377bcf8..896584c6da0 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ public/plugins/* public/tombstone/* # Ignore bundler config -/bin /.bundle /.vagrant /.vagrantfile diff --git a/bin/docker/README.md b/bin/docker/README.md new file mode 100644 index 00000000000..f9119edba19 --- /dev/null +++ b/bin/docker/README.md @@ -0,0 +1,39 @@ +# Developing using Docker + +Since Discourse runs in Docker, why not develop there? If you have Docker installed, you should be able to run Discourse directly from your source directory using a Discourse development container. + +## Step-by-step + +It should be as easy as (from your source root): + +```sh +./bin/docker/boot_dev --init + # wait while: + # - dependencies are installed, + # - the database is migrated, and + # - an admin user is created (you'll need to interact with this) +./bin/docker/rails s +``` + +... then open a browser on http://localhost:3000 and _voila!_, you should see Discourse. + +When you're done, you can kill the Docker container with: + +```sh +./bin/docker/shutdown_dev +``` + +Note that data is persisted between invocations of the container in your source root `tmp/postgres` directory. + +## Caveats + +There seems to be an issue with the ember-data-source gem installed by default (2.3.0.beta.5). It's missing its `dist` directory. I've worked around this by acquiring that commit, building the distribution locally, and patching it into `/usr/local/lib/ruby/gems/2.3.0/gems/ember-data-source-2.3.0.beta.5` by hand. I _believe_ later versions of the gem fix this, but the very next version (2.3.0 proper) bumps the ember-source dependency up to 2.0, which Discourse isn't using yet. + +You can get `boot_dev` to patch for you by passing `--patch local/path/to/ember-data-source/dist` on the command-line. You should only have to do this once (like `--init`). + + +## Other Notes + +##### Where is the container image/Dockerfile defined? + +The Dockerfile comes from [discourse/discourse_docker on GitHub](https://github.com/discourse/discourse_docker), in particular [image/discourse_dev](https://github.com/discourse/discourse_docker/tree/master/image/discourse_dev). diff --git a/bin/docker/boot_dev b/bin/docker/boot_dev index 0b3ed1eca23..336c01879ce 100755 --- a/bin/docker/boot_dev +++ b/bin/docker/boot_dev @@ -1,14 +1,74 @@ #!/bin/bash - -pushd `dirname $0` > /dev/null -SCRIPTPATH=`pwd -P` -popd > /dev/null - - -SOURCE_DIR=`(cd $SCRIPTPATH && cd ../../ && pwd)` +SCRIPTPATH=$(cd "$(dirname "$0")"; pwd -P) +SOURCE_DIR=$(cd "$SCRIPTPATH" && cd ../.. && pwd -P) DATA_DIR=$SOURCE_DIR/tmp/postgres -echo $SOURCE_DIR -echo $DATA_DIR +show_help() { +cat <& 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 diff --git a/bin/docker/bundle b/bin/docker/bundle index d304ab47123..1d1005c5a08 100755 --- a/bin/docker/bundle +++ b/bin/docker/bundle @@ -1,5 +1,5 @@ #!/bin/bash PARAMS="$@" -CMD="cd /src && HOME=/home/discourse chpst -u discourse:discourse bundle $PARAMS" -docker exec -it discourse_dev /bin/bash -c "$CMD" +CMD="cd /src && RAILS_ENV=${RAILS_ENV:=development} bundle $PARAMS" +docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/psql b/bin/docker/psql index 6336af07b1b..c9542d02dea 100755 --- a/bin/docker/psql +++ b/bin/docker/psql @@ -1,5 +1,5 @@ #!/bin/bash PARAMS="$@" -CMD="chpst -u postgres psql $PARAMS" -docker exec -it discourse_dev /bin/bash -c "$CMD" +CMD="psql $PARAMS" +docker exec -it -u postgres discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/rails b/bin/docker/rails index afbda658024..a9b4d4189c2 100755 --- a/bin/docker/rails +++ b/bin/docker/rails @@ -5,5 +5,5 @@ if [[ $# = 1 ]] && [[ "$1" =~ "s" ]]; then PARAMS="$PARAMS -b 0.0.0.0" fi -CMD="cd /src && HOME=/home/discourse RAILS_ENV=${RAILS_ENV:=development} chpst -u discourse:discourse rails $PARAMS" -docker exec -it discourse_dev /bin/bash -c "$CMD" +CMD="cd /src && RAILS_ENV=${RAILS_ENV:=development} rails $PARAMS" +docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/rake b/bin/docker/rake index 2ecac1b25e4..92abb3546b5 100755 --- a/bin/docker/rake +++ b/bin/docker/rake @@ -1,5 +1,5 @@ #!/bin/bash PARAMS="$@" -CMD="cd /src && HOME=/home/discourse RAILS_ENV=${RAILS_ENV:=development} chpst -u discourse:discourse rake $PARAMS" -docker exec -it discourse_dev /bin/bash -c "$CMD" +CMD="cd /src && RAILS_ENV=${RAILS_ENV:=development} rake $PARAMS" +docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/reset_db b/bin/docker/reset_db index 2d1ae28c06a..99bfaff0c69 100755 --- a/bin/docker/reset_db +++ b/bin/docker/reset_db @@ -1,12 +1,8 @@ #!/bin/bash - -pushd `dirname $0` > /dev/null -SCRIPTPATH=`pwd -P` -popd > /dev/null - - -SOURCE_DIR=`(cd $SCRIPTPATH && cd ../../ && pwd)` +SCRIPTPATH=$(cd "$(dirname "$0")"; pwd -P) +SOURCE_DIR=$(cd "$SCRIPTPATH" && cd ../.. && pwd -P) DATA_DIR=$SOURCE_DIR/tmp/postgres - -docker run -it -v $DATA_DIR:/shared/postgres_data samsaffron/discourse_dev:1.0.13 /bin/bash -c "rm -fr /shared/postgres_data/*" +# Should this also run /etc/runit/1.d/ensure_database, or will that +# happen automatically? +docker run -it -v $DATA_DIR:/shared/postgres_data discourse/dev /bin/bash -c "rm -fr /shared/postgres_data/*" diff --git a/bin/docker/shell b/bin/docker/shell new file mode 100755 index 00000000000..5f3d78cff2a --- /dev/null +++ b/bin/docker/shell @@ -0,0 +1,2 @@ +#!/bin/bash +docker exec -it -u discourse:discourse discourse_dev /bin/bash