From cd59237d3c49d57a69cd014a099220da40cbea62 Mon Sep 17 00:00:00 2001 From: Rob Witoff Date: Sun, 21 May 2017 19:33:11 -0700 Subject: [PATCH 1/4] Should have a dockerized DB Client with sourcecode and mysql DB ops --- server/trillian_db_client/Dockerfile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 server/trillian_db_client/Dockerfile diff --git a/server/trillian_db_client/Dockerfile b/server/trillian_db_client/Dockerfile new file mode 100644 index 0000000000..c202509ad1 --- /dev/null +++ b/server/trillian_db_client/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.8 + +RUN apt-get update +RUN apt-get install -y mysql-client + +ADD . /go/src/github.com/google/trillian +WORKDIR /go/src/github.com/google/trillian + +RUN go get -v ./server/trillian_log_server + +ENV DB_USER=test \ + DB_PASSWORD=zaphod \ + DB_DATABASE=test + +CMD [ 'mysql' ] From 47d3b81858efd9c7b1c998a82d535248ee7932eb Mon Sep 17 00:00:00 2001 From: Rob Witoff Date: Sun, 21 May 2017 19:33:54 -0700 Subject: [PATCH 2/4] DB operations should be flexibile to run against many environments --- scripts/resetdb.sh | 68 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/scripts/resetdb.sh b/scripts/resetdb.sh index 939bf0a959..8882a25f9b 100755 --- a/scripts/resetdb.sh +++ b/scripts/resetdb.sh @@ -1,12 +1,58 @@ #!/bin/bash -echo "Completely wipe and reset database 'test'." -read -p "Are you sure? " -n 1 -r -if [[ $REPLY =~ ^[Yy]$ ]] -then - # A command line supplied -u will override the first argument. - mysql -u root "$@" -e 'DROP DATABASE IF EXISTS test;' - mysql -u root "$@" -e 'CREATE DATABASE test;' - mysql -u root "$@" -e "GRANT ALL ON test.* TO 'test'@'localhost' IDENTIFIED BY 'zaphod';" - mysql -u root "$@" -D test < ${GOPATH}/src/github.com/google/trillian/storage/mysql/storage.sql -fi -echo + +set -e + +usage() { + echo "$0 [--force] [--verbose] ..." + echo "accepts envars:" + echo " - DB_NAME" + echo " - DB_USER" + echo " - DB_PASSWORD" +} + +collect_vars() { + # set unset envars to defaults + [ -z ${DB_USER+x} ] && DB_USER="root" + [ -z ${DB_NAME+x} ] && DB_NAME="test" + # format reused supplied envas + FLAGS="" + [ -z ${DB_PASSWORD+x} ] || FLAGS="${FLAGS} -p$DB_PASSWORD" + + # handle flags + FORCE=false + VERBOSE=false + while [[ $# -gt 0 ]]; do + case "$1" in + --force) FORCE=true ;; + --verbose) VERBOSE=true ;; + *) FLAGS="${FLAGS} $1" + esac + shift 1 + done +} + +main() { + collect_vars "$@" + + # what we're about to do + if [[ ${VERBOSE} = 'true' ]] + then + echo "-- using DB_USER: ${DB_USER}" + echo "-- Warning: about to destroy and reset database '${DB_NAME}'." + fi + + [[ ${FORCE} = true ]] || read -p "Are you sure? " -n 1 -r + + if [ -z ${REPLY+x} ] || [[ $REPLY =~ ^[Yy]$ ]] + then + # A command line supplied -u will override the first argument. + echo "Resetting DB..." + mysql -u $DB_USER $FLAGS -e "DROP DATABASE IF EXISTS ${DB_NAME};" + mysql -u $DB_USER $FLAGS -e "CREATE DATABASE ${DB_NAME};" + mysql -u $DB_USER $FLAGS -e "GRANT ALL ON ${DB_NAME}.* TO '${DB_NAME}'@'localhost' IDENTIFIED BY 'zaphod';" + mysql -u $DB_USER $FLAGS -D ${DB_NAME} < ${GOPATH}/src/github.com/google/trillian/storage/mysql/storage.sql + echo "Reset Complete" + fi +} + +main "$@" From ac453917c99449b8a7ca7fe114acc614ce845aa5 Mon Sep 17 00:00:00 2001 From: Rob Witoff Date: Sun, 21 May 2017 19:35:38 -0700 Subject: [PATCH 3/4] Dockerize core components --- README.md | 4 +++- scripts/resetdb.sh | 16 +++++++------- server/trillian_db_client/Dockerfile | 4 ++-- server/trillian_log_server/Dockerfile | 31 +++++++++++++++++++++++++++ server/trillian_log_signer/Dockerfile | 31 +++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 server/trillian_log_server/Dockerfile create mode 100644 server/trillian_log_signer/Dockerfile diff --git a/README.md b/README.md index c6f1786980..8a6974b6d7 100644 --- a/README.md +++ b/README.md @@ -95,8 +95,10 @@ You can then set up the [expected tables](storage/mysql/storage.sql) in a ```bash ./scripts/resetdb.sh -Completely wipe and reset database 'test'. +Warning: about to destroy and reset database 'test' Are you sure? y +> Resetting DB... +> Reset Complete ``` ### Integration Tests diff --git a/scripts/resetdb.sh b/scripts/resetdb.sh index 8882a25f9b..062d2caf78 100755 --- a/scripts/resetdb.sh +++ b/scripts/resetdb.sh @@ -4,17 +4,17 @@ set -e usage() { echo "$0 [--force] [--verbose] ..." - echo "accepts envars:" + echo "accepts environment variables:" echo " - DB_NAME" echo " - DB_USER" echo " - DB_PASSWORD" } collect_vars() { - # set unset envars to defaults + # set unset environment variables to defaults [ -z ${DB_USER+x} ] && DB_USER="root" [ -z ${DB_NAME+x} ] && DB_NAME="test" - # format reused supplied envas + # format reused supplied environment variables FLAGS="" [ -z ${DB_PASSWORD+x} ] || FLAGS="${FLAGS} -p$DB_PASSWORD" @@ -38,8 +38,8 @@ main() { if [[ ${VERBOSE} = 'true' ]] then echo "-- using DB_USER: ${DB_USER}" - echo "-- Warning: about to destroy and reset database '${DB_NAME}'." fi + echo "Warning: about to destroy and reset database '${DB_NAME}'" [[ ${FORCE} = true ]] || read -p "Are you sure? " -n 1 -r @@ -47,10 +47,10 @@ main() { then # A command line supplied -u will override the first argument. echo "Resetting DB..." - mysql -u $DB_USER $FLAGS -e "DROP DATABASE IF EXISTS ${DB_NAME};" - mysql -u $DB_USER $FLAGS -e "CREATE DATABASE ${DB_NAME};" - mysql -u $DB_USER $FLAGS -e "GRANT ALL ON ${DB_NAME}.* TO '${DB_NAME}'@'localhost' IDENTIFIED BY 'zaphod';" - mysql -u $DB_USER $FLAGS -D ${DB_NAME} < ${GOPATH}/src/github.com/google/trillian/storage/mysql/storage.sql + mysql $FLAGS -u $DB_USER -e "DROP DATABASE IF EXISTS ${DB_NAME};" + mysql $FLAGS -u $DB_USER -e "CREATE DATABASE ${DB_NAME};" + mysql $FLAGS -u $DB_USER -e "GRANT ALL ON ${DB_NAME}.* TO '${DB_NAME}'@'localhost' IDENTIFIED BY 'zaphod';" + mysql $FLAGS -u $DB_USER -D ${DB_NAME} < ${GOPATH}/src/github.com/google/trillian/storage/mysql/storage.sql echo "Reset Complete" fi } diff --git a/server/trillian_db_client/Dockerfile b/server/trillian_db_client/Dockerfile index c202509ad1..b88b36a0f5 100644 --- a/server/trillian_db_client/Dockerfile +++ b/server/trillian_db_client/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.8 -RUN apt-get update -RUN apt-get install -y mysql-client +RUN apt-get update && \ + apt-get install -y mysql-client ADD . /go/src/github.com/google/trillian WORKDIR /go/src/github.com/google/trillian diff --git a/server/trillian_log_server/Dockerfile b/server/trillian_log_server/Dockerfile new file mode 100644 index 0000000000..981d9d94b3 --- /dev/null +++ b/server/trillian_log_server/Dockerfile @@ -0,0 +1,31 @@ +FROM golang:1.8 + +ADD . /go/src/github.com/google/trillian +WORKDIR /go/src/github.com/google/trillian + +RUN go get -v ./server/trillian_log_server + +ENV DB_USER=test \ + DB_PASSWORD=zaphod \ + DB_DATABASE=test \ + DB_HOST=127.0.0.0:3306 + +ENV RPC_HOST=localhost \ + RPC_PORT=8090 \ + HOST=0.0.0.0 \ + HTTP_PORT=8091 + +ENV DUMP_METRICS 0s + +ENTRYPOINT /go/bin/trillian_log_server \ + --mysql_uri="${DB_USER}:${DB_PASSWORD}@tcp(${DB_HOST})/${DB_DATABASE}" \ + --rpc_endpoint="$RPC_HOST:$RPC_PORT" \ + --http_endpoint="$HTTP_HOST:$HTTP_PORT" \ + --dump_metrics_interval="$DUMP_METRICS" \ + --logtostderr + +EXPOSE $RPC_PORT +EXPOSE $HTTP_PORT + +HEALTHCHECK --interval=5m --timeout=3s \ + CMD curl -f http://localhost:$HTTP_PORT/debug/vars || exit 1 diff --git a/server/trillian_log_signer/Dockerfile b/server/trillian_log_signer/Dockerfile new file mode 100644 index 0000000000..58414d29ec --- /dev/null +++ b/server/trillian_log_signer/Dockerfile @@ -0,0 +1,31 @@ +FROM golang:1.8 + +ENV DB_USER=test \ + DB_PASSWORD=zaphod \ + DB_DATABASE=test \ + DB_HOST=127.0.0.0:3306 + +ENV HOST=0.0.0.0 \ + HTTP_PORT=8091 + +ENV SEQUENCER_GUARD_WINDOW=0s \ + DUMP_METRICS=0s \ + FORCE_MASTER=true + +ADD . /go/src/github.com/google/trillian +WORKDIR /go/src/github.com/google/trillian + +RUN go get -v ./server/trillian_log_signer + +# Run the outyet command by default when the container starts. +ENTRYPOINT /go/bin/trillian_log_signer \ + --mysql_uri="${DB_USER}:${DB_PASSWORD}@tcp(${DB_HOST})/${DB_DATABASE}" \ + --http_endpoint="$HOST:$HTTP_PORT" \ + --dump_metrics_interval="$DUMP_METRICS" \ + --sequencer_guard_window="$SEQUENCER_GUARD_WINDOW" \ + --force_master="$FORCE_MASTER" + +EXPOSE $HTTP_PORT + +HEALTHCHECK --interval=5m --timeout=3s \ + CMD curl -f http://localhost:$HTTP_PORT/debug/vars || exit 1 From 893a1a73a100a2b90e2ab4e1ba1482eb4ec861f7 Mon Sep 17 00:00:00 2001 From: Rob Witoff Date: Wed, 7 Jun 2017 21:50:11 -0700 Subject: [PATCH 4/4] remove deprecated comment --- scripts/resetdb.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/resetdb.sh b/scripts/resetdb.sh index 062d2caf78..35c9d5cb0a 100755 --- a/scripts/resetdb.sh +++ b/scripts/resetdb.sh @@ -45,7 +45,6 @@ main() { if [ -z ${REPLY+x} ] || [[ $REPLY =~ ^[Yy]$ ]] then - # A command line supplied -u will override the first argument. echo "Resetting DB..." mysql $FLAGS -u $DB_USER -e "DROP DATABASE IF EXISTS ${DB_NAME};" mysql $FLAGS -u $DB_USER -e "CREATE DATABASE ${DB_NAME};"