From d5fab4065640b2c20944b9e822960b52e28ce8f3 Mon Sep 17 00:00:00 2001 From: Aleksandr Volochnev Date: Tue, 12 Feb 2019 21:06:00 +0100 Subject: [PATCH] Set-Flag Improvement - Switched bootstrap to use external flag instead of the file flag - Removed curl installation from Dockerfile as curl was needed only for ETCD --- Dockerfile | 10 +--------- README.md | 6 ++---- bootstrap.sh | 43 ++++++++++++++++++------------------------- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f3eb94..e7453e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,8 @@ FROM datastax/dse-server:6.7.0 -# Copy schema files into /opt/killrvideo-data +# Copy required files COPY [ "lib/killrvideo-data/graph/killrvideo_video_recommendations_schema.groovy", "lib/killrvideo-data/schema.cql", "lib/killrvideo-data/search/*", "keyspace.cql", "/opt/killrvideo-data/" ] - -# Copy bootstrap script(s) and make executable COPY [ "bootstrap.sh", "lib/wait-for-it/wait-for-it.sh", "/" ] -# Make sure curl command is available for registering DSE ports with etcd -USER root -RUN set -x \ - && apt-get update -qq && apt-get install -y curl -# && apt-get install -y sudo - # Set the entrypoint to the bootstrap script ENTRYPOINT [ "/bootstrap.sh" ] diff --git a/README.md b/README.md index 1606a22..74f2b0e 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,7 @@ This container supports several different options for configuration: ### DSE node location By default, this container assumes that DataStax Enterprise is being started in a Docker container -as part of a `docker-compose` configuration. The value of the `KILLRVIDEO_DOCKER_IP` -environment variable is used to register DSE services in `etcd`. +as part of a `docker-compose` configuration. If you instead wish to deploy KillrVideo with an existing external cluster, you can override this behavior by setting the value of the `KILLRVIDEO_DSE_EXTERNAL_IP` environment variable to the location @@ -65,8 +64,7 @@ please see the [KillrVideo Docker documentation page][docker-doc]. ## Builds and Releases -The `./build` folder contains a number of scripts to help with builds and releases. Continuous -integration builds are done by Travis and any commits that are tagged will also automatically +Continuous integration builds are done by Travis and any commits that are tagged will also automatically be released to the [Docker Hub][docker-hub] page. We try to follow semantic versioning, however the version numbering is not related to what version of DSE we're using. For example, version `1.0.0` uses DSE version `5.1.5`. diff --git a/bootstrap.sh b/bootstrap.sh index ed423dd..0231514 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -3,12 +3,6 @@ set -e echo '===> DSE Configuration' -# See if we've already completed bootstrapping -if [ -f killrvideo_bootstrapped ]; then - echo '=> Configuration already completed, exiting' - exit 0 -fi - # Default addresses to use for DSE cluster if starting in Docker dse_ip='dse' dse_external_ip=$KILLRVIDEO_DOCKER_IP @@ -54,7 +48,7 @@ if [ "$KILLRVIDEO_ENABLE_SSL" = 'true' ]; then echo "=> SSL encryption is ENABLED with CERT FILE: $dse_ssl_certfile" fi -# Wait for port 9042 (CQL) to be ready for up to 240 seconds +# Wait for port 9042 (CQL) to be ready for up to 300 seconds echo '=> Waiting for DSE to become available' /wait-for-it.sh -t 300 $dse_ip:9042 echo '=> DSE is available' @@ -68,6 +62,12 @@ dse_password='cassandra' # If requested, create a new superuser to replace the default superuser if [ "$KILLRVIDEO_CREATE_ADMIN_USER" = 'true' ]; then + # Check if initialisation is done already + if [ cqlsh $dse_ip 9042 -u $admin_user -p $admin_password $cql_options -e "DESCRIBE KEYSPACE kv_init_done;" 2>&1 | grep -q 'CREATE KEYSPACE kv_init_done' ]; then + echo "The database is already initialised, exiting..." + exit 0 + fi + echo "=> Creating new superuser $KILLRVIDEO_ADMIN_USERNAME" cqlsh $dse_ip 9042 -u $admin_user -p $admin_password $cql_options -e "CREATE ROLE $KILLRVIDEO_ADMIN_USERNAME with SUPERUSER = true and LOGIN = true and PASSWORD = '$KILLRVIDEO_ADMIN_PASSWORD'" # Login as new superuser to delete default superuser (cassandra) @@ -80,6 +80,15 @@ if [ ! -z "$KILLRVIDEO_ADMIN_USERNAME" ]; then admin_password=$KILLRVIDEO_ADMIN_PASSWORD fi +if cqlsh $dse_ip 9042 -u $admin_user -p $admin_password $cql_options -e "DESCRIBE KEYSPACE kv_init_done;" 2>&1 | grep -q 'CREATE KEYSPACE kv_init_done'; then + if [ ! -z "$KILLRVIDEO_FORCE_BOOTSTRAP" ]; then + echo '=> Forced bootstrap!' + else + echo "The database is already initialised, exiting..." + exit 0 + fi +fi + # If requested, create a new standard user if [ "$KILLRVIDEO_CREATE_DSE_USER" = 'true' ]; then # Create user and grant permission to create keyspaces (generator and web will need) @@ -142,23 +151,7 @@ if [ ! -z "$KILLRVIDEO_GRAPH_REPLICATION" ]; then fi dse gremlin-console -e $graph_file -# Register services in ETCD once all the schema are configured, using an IP that will be accessible -# internally and externally to the Docker environment -hostname="$(hostname)" - -if [ ! -z "$KILLRVIDEO_SERVICE_DISCOVERY_DISABLED" ]; then - echo '=> Skipping registration in ETCD as service discovery is disabled' -else - echo '=> Registering DSE DB (Cassandra) cluster in ETCD' - curl "http://etcd:2379/v2/keys/killrvideo/services/cassandra/$hostname" -XPUT -d value="$dse_external_ip:9042" - - echo '=> Registering DSE Search in ETCD' - curl "http://etcd:2379/v2/keys/killrvideo/services/dse-search/$hostname" -XPUT -d value="$dse_external_ip:8983" - - echo '=> Registering DSE Graph in ETCD' - curl "http://etcd:2379/v2/keys/killrvideo/services/gremlin/$hostname" -XPUT -d value="$dse_external_ip:8182" -fi +echo '=> Configuration of DSE users and schema complete' # Don't bootstrap next time we start -echo '=> Configuration of DSE users and schema complete' -touch killrvideo_bootstrapped +cqlsh $dse_ip 9042 -u $dse_user -p $dse_password $cql_options -e "CREATE KEYSPACE IF NOT EXISTS kv_init_done WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};"