Skip to content

Commit

Permalink
Squashed 'lib/killrvideo-docker-common/' changes from 0c67c94..be86c0f
Browse files Browse the repository at this point in the history
be86c0f Merge pull request #3 from KillrVideo/dse-5.1.0-update
bf4126c Update to new Docker image for DSE 5.1.0
19e1fac Switch to killrvideo-dse image
a102c4b Create lo0 alias and use when doing Docker for Mac setup
aa4f607 Don't need to specify IP to bind
c60aebe Hardcode IPs on Docker for Mac
4c5d1d6 Specify IP when publishing ports
ffcd0ee Make get environment script executable
bc68e1e Make create environment script executable
d887201 Add create environment shell script
58411ae Add a little documentation to shell script
0500cf9 Update shell script for docker toolbox setups
f16318a Add COMPOSE_FILE to output

git-subtree-dir: lib/killrvideo-docker-common
git-subtree-split: be86c0f837500393e1e7f6c223f0d285ec6e71ba
  • Loading branch information
Jeffrey Carpenter authored and Jeffrey Carpenter committed Apr 20, 2017
1 parent 9ee998a commit e60a06e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 15 deletions.
22 changes: 15 additions & 7 deletions create-environment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,27 @@ if ((Test-Path $envFilePath) -and ($Force -eq $false)) {
Exit
}

# Make sure the path exists for the .env we're generating
if ((Test-Path $Path) -eq $false) {
New-Item -Path $Path -Type Directory | Out-Null
}

$scriptPath = Split-Path -parent $PSCommandPath

# Use the base compose file from this project, plus one that should be in the same location
# as the .env file we're generating
Push-Location $Path
$composeFile = Resolve-Path -Relative "$scriptPath\docker-compose.yaml"
Pop-Location
$composeFile += ";.\docker-compose.yaml"

# Base environment variables
$dockerEnv = @("COMPOSE_PROJECT_NAME=$ProjectName")
$dockerEnv = @("COMPOSE_PROJECT_NAME=$ProjectName", "COMPOSE_FILE=$composeFile")

# Get path to the get-environment script and run it, adding each value to the env array
$scriptPath = Split-Path -parent $PSCommandPath
$getEnvCommand = Resolve-Path "$scriptPath\get-environment.ps1"
& "$getEnvCommand" |% { $dockerEnv += $_ }

# Make sure the path exists for the file
if ((Test-Path $Path) -eq $false) {
New-Item -Path $Path -Type Directory | Out-Null
}

# Write the file (have to use the .NET API here because we need UTF-8 WITHOUT the BOM)
$Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllLines($envFilePath, $dockerEnv, $Utf8NoBom)
Expand Down
34 changes: 34 additions & 0 deletions create-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

set -e # Bail if something fails

# This script tries to create a .env file in the current working directory for
# use with docker-compose. The file contains variables that include info on the
# user's docker setup like the IP address of the Host and VM.

ENV_FILE_PATH="$PWD/.env"

# TODO: Don't overwrite file if it already exists?

# Relative path that contains this script
SCRIPT_PATH=${BASH_SOURCE%/*}

# Create an alias for the loopback adapter so that the Mac and Docker VM can communicate using that IP
export LOOPBACK_IP='10.0.75.1'
echo 'We need to create an alias for the loopback adapter (lo0) using sudo'
echo 'so your Mac and the Docker VM can communicate. It will be created using'
echo "IP $LOOPBACK_IP. You will be prompted for your password."
sudo ifconfig lo0 alias $LOOPBACK_IP

# Should use compose file relative to this script, followed by a compose file relative to the
# working directory (i.e. where the .env file is going to be created)
COMPOSE_FILE="$SCRIPT_PATH/docker-compose.yaml:./docker-compose.yaml"
COMPOSE_PROJECT_NAME='killrvideo'

# Get other variables from the get-environment.sh script
GET_ENV_OUTPUT=$(exec $SCRIPT_PATH/get-environment.sh)

# Write to .env file in current working directory
echo "COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME
COMPOSE_FILE=$COMPOSE_FILE
$GET_ENV_OUTPUT" > $ENV_FILE_PATH
8 changes: 5 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ services:
depends_on:
- etcd

# DataStax Enterprise
# DataStax Enterprise with KillrVideo schema and search config
dse:
image: luketillman/datastax-enterprise:4.8.7
image: killrvideo/killrvideo-dse:2.0.0
ports:
- "9042:9042"
- "8983:8983"
cap_add:
- IPC_LOCK
ulimits:
memlock: -1
environment:
SERVICE_9042_NAME: cassandra
SERVICE_9042_NAME: cassandra
SERVICE_8983_NAME: dse-search
33 changes: 28 additions & 5 deletions get-environment.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,43 @@

set -e # Bail if something fails

# This script will try and detect a user's docker setup and write some environment
# variable pairs to stdout. The stdout output from this script can then be used to,
# for example, create a .env file for use with docker-compose

# TODO: Determine if a Docker Toolbox setup
IS_TOOLBOX=false

if [ "$IS_TOOLBOX" = true ]; then
echo "TODO: Docker machine environment setup"
# Make sure default docker machine is started
STATUS=$(docker-machine status default)
if [ "$STATUS" != "Running" ]; then
docker-machine start default > /dev/null
fi

# Load docker machine env into this shell
eval $(docker-machine env default)
fi

# Get the docker VM's IP address
DOCKER_IP_CMD="ip -4 addr show scope global dev eth0 | grep inet | awk '{print \$2}' | cut -d / -f 1"
DOCKER_IP=$(docker run --rm --net=host busybox bin/sh -c "$DOCKER_IP_CMD")
if [ "$IS_TOOLBOX" = true ]; then
# Just use the command that comes with docker-machine
DOCKER_IP=$(docker-machine ip)
else
# The create-environment.sh script should have setup a loopback alias, so use that IP
DOCKER_IP=$LOOPBACK_IP
fi

# Get the docker VM Host's IP address
HOST_IP_CMD="ip -4 route list dev eth0 0/0 | cut -d ' ' -f 3"
HOST_IP=$(docker run --rm --net=host busybox bin/sh -c "$HOST_IP_CMD")
if [ "$IS_TOOLBOX" = true ]; then
# The host only CIDR address will contain the host's IP (along with a suffix like /24)
HOST_IP=$(docker-machine inspect --format '{{ .Driver.HostOnlyCIDR }}' default)
# Remove suffix
HOST_IP=${HOST_IP//\/[[:digit:]][[:digit:]]/}
else
# The create-environment.sh script should have setup a loopback alias, so use that IP
HOST_IP=$LOOPBACK_IP
fi

# Write values to stdout
echo "KILLRVIDEO_DOCKER_TOOLBOX=$IS_TOOLBOX"
Expand Down

0 comments on commit e60a06e

Please sign in to comment.