Skip to content

Commit

Permalink
Merge pull request #5 from KillrVideo/set-flag
Browse files Browse the repository at this point in the history
External Bootstrap Flag
  • Loading branch information
HadesArchitect authored Aug 9, 2019
2 parents 587fe93 + d5fab40 commit 2a8f467
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 111 deletions.
10 changes: 1 addition & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`.
Expand Down
43 changes: 18 additions & 25 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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};"
1 change: 0 additions & 1 deletion build/VERSION

This file was deleted.

16 changes: 0 additions & 16 deletions build/docker-build.ps1

This file was deleted.

13 changes: 0 additions & 13 deletions build/docker-build.sh

This file was deleted.

31 changes: 0 additions & 31 deletions build/docker-publish.sh

This file was deleted.

7 changes: 0 additions & 7 deletions build/git-subtree-pull.ps1

This file was deleted.

5 changes: 0 additions & 5 deletions build/git-subtree-pull.sh

This file was deleted.

0 comments on commit 2a8f467

Please sign in to comment.