Skip to content

Commit

Permalink
Set-Flag Improvement
Browse files Browse the repository at this point in the history
- Switched bootstrap to use external flag instead of the file flag
- Removed curl installation from Dockerfile as curl was needed only for ETCD
  • Loading branch information
HadesArchitect committed Feb 12, 2019
1 parent 57eacad commit d5fab40
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 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};"

0 comments on commit d5fab40

Please sign in to comment.