From 43d8862f8fa3ef25c108c60d70aded0f2e6f0794 Mon Sep 17 00:00:00 2001 From: Rachel Sanders Date: Thu, 17 Sep 2015 12:09:02 -0700 Subject: [PATCH 1/7] Fixed mysql contrib script so it's scriptable --- contrib/scripts/setup-mysql-db.sh | 55 ++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/contrib/scripts/setup-mysql-db.sh b/contrib/scripts/setup-mysql-db.sh index fa3b3e7..19b716f 100755 --- a/contrib/scripts/setup-mysql-db.sh +++ b/contrib/scripts/setup-mysql-db.sh @@ -14,12 +14,57 @@ # See the License for the specific language governing permissions and # limitations under the License. -db="hackpad" -mysql="mysql" -echo "Creating database ${db}..." -echo "create database ${db};" | ${mysql} -u root -p +MYSQL="mysql" +DATABASE="hackpad" +DB_USERNAME=root +DB_PASSWORD= + +PROMPT=true + +while [[ $# > 0 ]] +do +key="$1" + +case $key in + + -d|--database) + DATABASE="$2" + shift # past argument=value + ;; + -u|--username) + DB_USERNAME="$2" + shift # past argument=value + ;; + -p|--password) + DB_PASSWORD="$2" + PROMPT=false + shift # past argument=value + ;; + *) + # unknown option + ;; +esac +shift +done + + +if [ "$PROMPT" == true ]; then + MYSQL_CMD="${MYSQL} -u ${DB_USERNAME} -p" +else + if [ -z "$DB_PASSWORD" ]; then + + MYSQL_CMD="${MYSQL} -u ${DB_USERNAME}" + else + MYSQL_CMD="${MYSQL} -u ${DB_USERNAME} -p ${DB_PASSWORD}" + fi +fi + + +echo "Creating database ${DATABASE}..." +echo "create database ${DATABASE};" | echo ${MYSQL_CMD} + echo "Granting priviliges..." -echo "grant all privileges on ${db}.* to 'hackpad'@'localhost' identified by 'password';" | ${mysql} -u root -p +echo "grant all privileges on ${DATABASE}.* to 'hackpad'@'localhost' identified by 'password';" | echo ${MYSQL_CMD} echo "Success" From feaa7a26d5d69547346a13bf951a94a2b7338cc1 Mon Sep 17 00:00:00 2001 From: Rachel Sanders Date: Fri, 18 Sep 2015 11:34:33 -0700 Subject: [PATCH 2/7] It would help to actually run the commands --- contrib/scripts/setup-mysql-db.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/scripts/setup-mysql-db.sh b/contrib/scripts/setup-mysql-db.sh index 19b716f..134d38d 100755 --- a/contrib/scripts/setup-mysql-db.sh +++ b/contrib/scripts/setup-mysql-db.sh @@ -61,10 +61,10 @@ fi echo "Creating database ${DATABASE}..." -echo "create database ${DATABASE};" | echo ${MYSQL_CMD} +echo "create database ${DATABASE};" | ${MYSQL_CMD} echo "Granting priviliges..." -echo "grant all privileges on ${DATABASE}.* to 'hackpad'@'localhost' identified by 'password';" | echo ${MYSQL_CMD} +echo "grant all privileges on ${DATABASE}.* to 'hackpad'@'localhost' identified by 'password';" | ${MYSQL_CMD} echo "Success" From 3d6dd2c1ad267e98a3591c6f0c8a737681d9bbd1 Mon Sep 17 00:00:00 2001 From: Rachel Sanders Date: Fri, 18 Sep 2015 14:22:17 -0700 Subject: [PATCH 3/7] Added dockerfile and entrypoint --- Dockerfile | 20 ++++++++++++++ bin/docker-entrypoint.sh | 57 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Dockerfile create mode 100755 bin/docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..69b0e41 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +from ubuntu:14.04 + +RUN apt-get -y update + +RUN apt-get install -yf \ + openjdk-7-jdk \ + mysql-server \ + scala + +RUN mkdir /etc/hackpad + +VOLUME /etc/hackpad/src + +COPY bin/docker-entrypoint.sh /etc/hackpad/ + +ENTRYPOINT ["/etc/hackpad/docker-entrypoint.sh"] + +EXPOSE 9000 + +CMD ["hackpad"] \ No newline at end of file diff --git a/bin/docker-entrypoint.sh b/bin/docker-entrypoint.sh new file mode 100755 index 0000000..a4b2290 --- /dev/null +++ b/bin/docker-entrypoint.sh @@ -0,0 +1,57 @@ +#!/bin/bash +set -e + +HACKPAD_SRC="/etc/hackpad/src" + +if [ "$1" = 'hackpad' ]; then + + if [ ! -d "$HACKPAD_SRC" ]; then + echo "The directory $HACKPAD_SRC doesn't exist." + echo "Either your docker image is broken (rebuild from scratch if so) or you're running this script on the host machine and should stop it." + exit 1 + fi + + cd "$HACKPAD_SRC" + + if [ ! -f "$HACKPAD_SRC/README.md" ]; then + echo "I can't find any hackpad source files. Did you forget to mount the volume?" + echo "[insert instructions here]" + exit 1 + fi + + echo "-->Editing configuration files" + + sed 's:^export SCALA_HOME=".*$:export SCALA_HOME="/usr/share/java":' -i '' bin/exports.sh + sed 's:^export SCALA_LIBRARY_JAR=".*$:export SCALA_LIBRARY_JAR="$SCALA_HOME/scala-library.jar":' -i '' bin/exports.sh + sed 's:^export JAVA_HOME=".*$:export JAVA_HOME="/usr/share/java":' -i '' bin/exports.sh + + cp etherpad/etc/etherpad.localdev-default.properties etherpad/etc/etherpad.local.properties + sed 's:__email_addresses_with_admin_access__:admin@localhost.info:' -i '' etherpad/etc/etherpad.local.properties + + echo "-->Running build" + + ./bin/build.sh + + echo "-->Starting mysql" + service mysql restart + + echo "-->Creating database" + ./contrib/scripts/setup-mysql-db.sh -p "" + + + echo + echo "Starting server. A fake admin account has been created, use admin@localhost.info" + echo + + ./bin/run.sh + +elif [[ "$1" = 'server' ]]; then + echo + echo "Starting server." + echo + + ./bin/run.sh + +fi + +exec "$@" \ No newline at end of file From cfc8bd89b550f3509a97f0bf7ab95ed1849568df Mon Sep 17 00:00:00 2001 From: Rachel Sanders Date: Fri, 18 Sep 2015 14:51:01 -0700 Subject: [PATCH 4/7] Added Docker instructions --- DOCKER.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 DOCKER.md diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..e5c942f --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,64 @@ +How to develop Hackpad under Docker +=================================== + +If you'd like to develop Hackpad on Docker, these instructions are for you. + +This will let you edit this repository and see your changes reflected in the docker image. + +Getting it running +------------------- + +1. Obviously, if you haven't already, you'll need to install [Docker](https://docs.docker.com/installation/). + +2. Build the image. From the root of this repo, run: + + docker build -t hackpad . + +3. Run the container. Docker doesn't let you automatically mount a directory on your host machine in the container, so you'll need to specify by hand. + + Replace /path/to/this/repo below with the path to the current repository. Leave the other path alone. + + docker run -d -p 9000:9000 -v /path/to/this/repo:/etc/hackpad/src hackpad + +4. Fix networking (one time only). If you're on OS X or Windows, you'll need to set up some port forwarding to have Hackpad work properly. Linux folk can skip this. + + 1. Open VirtualBox + + 2. Select the default image and click Settings + + 3. Go to Network -> Adapter 1 -> Port forwarding + + 4. Create a custom rule like so: + + * Host IP: 127.0.0.1 + * Host Port: 9000 + * Guest IP: blank + * Guest Port: 9000 + + You should only have to do this once. + + At this point you should be able to open http://localhost:9000 in a browser and see the Hackpad page. + +5. Create a password for the admin account. + + As part of the Docker setup, Hackpad is configured with 'admin@localhost.info' as a admin account, but you'll need to create a password to log in. + + To do that: + + 1. Open http://localhost:9000 and click Log In + + 2. Create an account with 'admin@localhost.info' and any password you like. + + 3. From the command line, run: + + 1. Find the name of your running container by running `docker ps`. Note the name. + + 2. Run this query and find the token: + + docker exec -it [container name] mysql -D hackpad -e 'select * from email_signup;' + + 3. Load this in a browser: http://localhost:9000/ep/account/validate-email?email=admin%40localhost.info&token=TOKEN + + +You're all set! You should be able to edit the Hackpad source code and the docker container will track those changes. + From 1a59f89e1ad6736934ba2f03dca034cea8f7db7a Mon Sep 17 00:00:00 2001 From: Rachel Sanders Date: Fri, 18 Sep 2015 14:57:33 -0700 Subject: [PATCH 5/7] Made instructions a bit clearer --- bin/docker-entrypoint.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/docker-entrypoint.sh b/bin/docker-entrypoint.sh index a4b2290..26c563e 100755 --- a/bin/docker-entrypoint.sh +++ b/bin/docker-entrypoint.sh @@ -7,15 +7,17 @@ if [ "$1" = 'hackpad' ]; then if [ ! -d "$HACKPAD_SRC" ]; then echo "The directory $HACKPAD_SRC doesn't exist." - echo "Either your docker image is broken (rebuild from scratch if so) or you're running this script on the host machine and should stop it." + echo "You're probably running this on the host machine and not in the Docker container. Don't do that." + echo "If this is happening on the Docker container, try building a new image from scratch." exit 1 fi cd "$HACKPAD_SRC" + # sanity check that we see any files at all. if [ ! -f "$HACKPAD_SRC/README.md" ]; then - echo "I can't find any hackpad source files. Did you forget to mount the volume?" - echo "[insert instructions here]" + echo "I can't find any Hackpad source files. Did you forget to mount the volume?" + echo "e.g., docker run -d -p 9000:9000 -v /path/to/this/repo:/etc/hackpad/src hackpad" exit 1 fi @@ -40,7 +42,7 @@ if [ "$1" = 'hackpad' ]; then echo - echo "Starting server. A fake admin account has been created, use admin@localhost.info" + echo "Starting server. The admin account is 'admin@localhost.info'." echo ./bin/run.sh From c5a7f69fa47315f307c9c7d2509c6d404333a1be Mon Sep 17 00:00:00 2001 From: Rachel Sanders Date: Fri, 18 Sep 2015 15:29:36 -0700 Subject: [PATCH 6/7] Fixing sed syntax problem --- DOCKER.md | 4 ++++ bin/docker-entrypoint.sh | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index e5c942f..34cde16 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -20,6 +20,10 @@ Getting it running docker run -d -p 9000:9000 -v /path/to/this/repo:/etc/hackpad/src hackpad + It'll build hackpad and run schema migrations and such. If you want to see what's going on, do: + + docker logs -f [container name] + 4. Fix networking (one time only). If you're on OS X or Windows, you'll need to set up some port forwarding to have Hackpad work properly. Linux folk can skip this. 1. Open VirtualBox diff --git a/bin/docker-entrypoint.sh b/bin/docker-entrypoint.sh index 26c563e..6d0ece6 100755 --- a/bin/docker-entrypoint.sh +++ b/bin/docker-entrypoint.sh @@ -23,12 +23,12 @@ if [ "$1" = 'hackpad' ]; then echo "-->Editing configuration files" - sed 's:^export SCALA_HOME=".*$:export SCALA_HOME="/usr/share/java":' -i '' bin/exports.sh - sed 's:^export SCALA_LIBRARY_JAR=".*$:export SCALA_LIBRARY_JAR="$SCALA_HOME/scala-library.jar":' -i '' bin/exports.sh - sed 's:^export JAVA_HOME=".*$:export JAVA_HOME="/usr/share/java":' -i '' bin/exports.sh + sed 's:^export SCALA_HOME=".*$:export SCALA_HOME="/usr/share/java":' -i'' bin/exports.sh + sed 's:^export SCALA_LIBRARY_JAR=".*$:export SCALA_LIBRARY_JAR="$SCALA_HOME/scala-library.jar":' -i'' bin/exports.sh + sed 's:^export JAVA_HOME=".*$:export JAVA_HOME="/usr/share/java":' -i'' bin/exports.sh cp etherpad/etc/etherpad.localdev-default.properties etherpad/etc/etherpad.local.properties - sed 's:__email_addresses_with_admin_access__:admin@localhost.info:' -i '' etherpad/etc/etherpad.local.properties + sed 's:__email_addresses_with_admin_access__:admin@localhost.info:' -i'' etherpad/etc/etherpad.local.properties echo "-->Running build" From b06c62ce2ba41979b55a8588acc1c556e3237dd9 Mon Sep 17 00:00:00 2001 From: Rachel Sanders Date: Fri, 18 Sep 2015 15:36:31 -0700 Subject: [PATCH 7/7] Copyediting DOCKER.md --- DOCKER.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index 34cde16..5b3f190 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -12,7 +12,7 @@ Getting it running 2. Build the image. From the root of this repo, run: - docker build -t hackpad . + docker build -t hackpad . 3. Run the container. Docker doesn't let you automatically mount a directory on your host machine in the container, so you'll need to specify by hand. @@ -20,15 +20,15 @@ Getting it running docker run -d -p 9000:9000 -v /path/to/this/repo:/etc/hackpad/src hackpad - It'll build hackpad and run schema migrations and such. If you want to see what's going on, do: + This will build hackpad, run schema migrations, and then start the server. It may take a few minutes. If you want to see what's going on, do: docker logs -f [container name] -4. Fix networking (one time only). If you're on OS X or Windows, you'll need to set up some port forwarding to have Hackpad work properly. Linux folk can skip this. +4. Fix networking (one time only). If you're on OS X or Windows, you'll need to set up port forwarding to have Hackpad work properly. Linux folk can skip this. 1. Open VirtualBox - 2. Select the default image and click Settings + 2. Select the `default` image and click Settings 3. Go to Network -> Adapter 1 -> Port forwarding @@ -59,7 +59,7 @@ Getting it running 2. Run this query and find the token: - docker exec -it [container name] mysql -D hackpad -e 'select * from email_signup;' + docker exec -it [container name] mysql -D hackpad -e 'select * from email_signup;' 3. Load this in a browser: http://localhost:9000/ep/account/validate-email?email=admin%40localhost.info&token=TOKEN