diff --git a/docker-compose.yml b/docker-compose.yml index 6930daf368..4f8705f384 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,31 +1,34 @@ -notaryserver: +server: build: . dockerfile: server.Dockerfile links: - - notarymysql - - notarysigner + - mysql + - signer + - signer:notarysigner environment: - - SERVICE_NAME=notaryserver + - SERVICE_NAME=notary_server ports: - "8080" - "4443:4443" entrypoint: /bin/bash command: -c "./migrations/migrate.sh && notary-server -config=fixtures/server-config.json" -notarysigner: +signer: build: . dockerfile: signer.Dockerfile links: - - notarymysql + - mysql environment: - - SERVICE_NAME=notarysigner + - SERVICE_NAME=notary_signer entrypoint: /bin/bash command: -c "./migrations/migrate.sh && notary-signer -config=fixtures/signer-config.json" -notarymysql: +mysql: volumes: - ./notarymysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d - - notarydata:/var/lib/mysql + - notary_data:/var/lib/mysql image: mariadb:10.1.10 ports: - "3306:3306" environment: + - TERM=dumb - MYSQL_ALLOW_EMPTY_PASSWORD="true" + command: mysqld --innodb_file_per_table diff --git a/fixtures/server-config.json b/fixtures/server-config.json index 24c251234a..67fe2d762d 100644 --- a/fixtures/server-config.json +++ b/fixtures/server-config.json @@ -18,6 +18,6 @@ }, "storage": { "backend": "mysql", - "db_url": "server@tcp(notarymysql:3306)/notaryserver?parseTime=True" + "db_url": "server@tcp(mysql:3306)/notaryserver?parseTime=True" } } diff --git a/fixtures/signer-config.json b/fixtures/signer-config.json index b6be189151..2af789a8dc 100644 --- a/fixtures/signer-config.json +++ b/fixtures/signer-config.json @@ -11,6 +11,6 @@ }, "storage": { "backend": "mysql", - "db_url": "signer@tcp(notarymysql:3306)/notarysigner?parseTime=True" + "db_url": "signer@tcp(mysql:3306)/notarysigner?parseTime=True" } } diff --git a/migrations/migrate.sh b/migrations/migrate.sh index 4bd9fbebb5..adb4c3db11 100755 --- a/migrations/migrate.sh +++ b/migrations/migrate.sh @@ -6,30 +6,54 @@ iter=0 case $SERVICE_NAME in - notaryserver) + notary_server) # have to poll for DB to come up - until migrate -path=migrations/server/mysql -url="mysql://server@tcp(notarymysql:3306)/notaryserver" up + until migrate -path=migrations/server/mysql -url="mysql://server@tcp(mysql:3306)/notaryserver" version > /dev/null do ((iter++)) if (( iter > 30 )); then + echo "notaryserver database failed to come up within 30 seconds" exit 1; fi echo "waiting for notarymysql to come up." sleep 1 done - echo "notaryserver database migrated to latest version" + pre=$(migrate -path=migrations/server/mysql -url="mysql://server@tcp(mysql:3306)/notaryserver" version) + if migrate -path=migrations/server/mysql -url="mysql://server@tcp(mysql:3306)/notaryserver" up ; then + post=$(migrate -path=migrations/server/mysql -url="mysql://server@tcp(mysql:3306)/notaryserver" version) + if [ "$pre" != "$post" ]; then + echo "notaryserver database migrated to latest version" + else + echo "notaryserver database already at latest version" + fi + else + echo "notaryserver database migration failed" + exit 1 + fi ;; - notarysigner) + notary_signer) # have to poll for DB to come up - until migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(notarymysql:3306)/notarysigner" up + until migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(mysql:3306)/notarysigner" version > /dev/null do ((iter++)) if (( iter > 30 )); then + echo "notarysigner database failed to come up within 30 seconds" exit 1; fi echo "waiting for notarymysql to come up." sleep 1 done - echo "notarysigner database migrated to latest version" + pre=$(migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(mysql:3306)/notarysigner" version) + if migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(mysql:3306)/notarysigner" up ; then + post=$(migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(mysql:3306)/notarysigner" version) + if [ "$pre" != "$post" ]; then + echo "notarysigner database migrated to latest version" + else + echo "notarysigner database already at latest version" + fi + else + echo "notarysigner database migration failed" + exit 1 + fi ;; esac diff --git a/notarymysql/docker-entrypoint-initdb.d/initial-notaryserver.sql b/notarymysql/docker-entrypoint-initdb.d/initial-notaryserver.sql index 63e5f511ed..0cc1e9b221 100644 --- a/notarymysql/docker-entrypoint-initdb.d/initial-notaryserver.sql +++ b/notarymysql/docker-entrypoint-initdb.d/initial-notaryserver.sql @@ -2,6 +2,6 @@ CREATE DATABASE IF NOT EXISTS `notaryserver`; CREATE USER "server"@"%" IDENTIFIED BY ""; -GRANT +GRANT ALL PRIVILEGES ON `notaryserver`.* TO "server"@"%"; diff --git a/notarymysql/docker-entrypoint-initdb.d/initial-notarysigner.sql b/notarymysql/docker-entrypoint-initdb.d/initial-notarysigner.sql index f2d9a0bd30..1e985d81c7 100644 --- a/notarymysql/docker-entrypoint-initdb.d/initial-notarysigner.sql +++ b/notarymysql/docker-entrypoint-initdb.d/initial-notarysigner.sql @@ -2,6 +2,6 @@ CREATE DATABASE IF NOT EXISTS `notarysigner`; CREATE USER "signer"@"%" IDENTIFIED BY ""; -GRANT +GRANT ALL PRIVILEGES ON `notarysigner`.* TO "signer"@"%";