-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding docker compose and instructions to run via docker
- Loading branch information
1 parent
95f1698
commit d70feb9
Showing
24 changed files
with
547 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ node_modules | |
target | ||
*.log | ||
bcp-build.json | ||
docker/*/*.jar | ||
docker/*/Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +0,0 @@ | ||
subprojects { | ||
configurations.all { | ||
// check for updates every build | ||
resolutionStrategy.cacheChangingModulesFor 0, 'seconds' | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bash | ||
|
||
RELEASE_VERSION=${1-snapshot} | ||
IP=${2-} | ||
# Add a colon if IP is set, we want <host_ip>:<host_port:<container_port> or <host_port:<container_port> | ||
if [ -n "$IP" ] | ||
then | ||
IP=${IP}: | ||
fi | ||
|
||
echo "================== Config =======================" | ||
echo " RELEASE_VERSION: $RELEASE_VERSION" | ||
echo " IP: $IP" | ||
echo "=================================================" | ||
|
||
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
|
||
# Create Dockerfile for consumer and producer | ||
sed "s|{RELEASE_VERSION}|$RELEASE_VERSION|g;" $SCRIPT_DIR/consumer/Dockerfile.template > $SCRIPT_DIR/consumer/Dockerfile | ||
sed "s|{RELEASE_VERSION}|$RELEASE_VERSION|g;" $SCRIPT_DIR/producer/Dockerfile.template > $SCRIPT_DIR/producer/Dockerfile | ||
|
||
cd .. | ||
|
||
./gradlew :gr8-rest-producer:clean :gr8-rest-producer:assemble | ||
cp -rf gr8-rest-producer/build/libs/gr8-rest-producer-0.1.jar docker/producer | ||
./gradlew :gr8-rest-consumer:clean :gr8-rest-consumer:assemble | ||
cp -rf gr8-rest-consumer/build/libs/gr8-rest-consumer-0.1.jar docker/consumer | ||
|
||
cd docker | ||
|
||
#Optional if already running | ||
docker-machine start | ||
|
||
eval `docker-machine env default` | ||
|
||
# Cleanup any existing containers and delete their volumes. | ||
docker-compose -f $SCRIPT_DIR/docker-compose.yml kill | ||
docker-compose -f $SCRIPT_DIR/docker-compose.yml rm --force # Not using -v flag to preserve volumes between deploys | ||
|
||
# create and run all containers | ||
docker-compose -f $SCRIPT_DIR/docker-compose.yml build | ||
docker-compose -f $SCRIPT_DIR/docker-compose.yml up -d | ||
|
||
# Scale kafka to 3 | ||
docker-compose -f $SCRIPT_DIR/docker-compose.yml scale kafka=3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM java:openjdk-8u91-jdk | ||
|
||
EXPOSE 8282 | ||
|
||
ADD bin/wait-for-it.sh /wait-for-it.sh | ||
|
||
# FIXME: fix /app volume issue with jdk base image. | ||
RUN mkdir -p /consumer && mkdir -p /producer | ||
|
||
ADD gr8-rest-consumer-0.1.jar /consumer/consumer.jar | ||
|
||
CMD /bin/sh -c "/wait-for-it.sh redis:6379 --strict && /wait-for-it.sh kafka:9092 --strict && java -jar /consumer/consumer.jar --spring.profiles.active=docker" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#!/usr/bin/env bash | ||
# Use this script to test if a given TCP host/port are available | ||
# Note: From https://github.com/vishnubob/wait-for-it/blob/20c60949dedb74a34b06cb954ddd0d71a3c1c769/wait-for-it.sh | ||
|
||
cmdname=$(basename $0) | ||
|
||
echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } | ||
|
||
usage() | ||
{ | ||
cat << USAGE >&2 | ||
Usage: | ||
$cmdname host:port [-s] [-t timeout] [-- command args] | ||
-h HOST | --host=HOST Host or IP under test | ||
-p PORT | --port=PORT TCP port under test | ||
Alternatively, you specify the host and port as host:port | ||
-s | --strict Only execute subcommand if the test succeeds | ||
-q | --quiet Don't output any status messages | ||
-t TIMEOUT | --timeout=TIMEOUT | ||
Timeout in seconds, zero for no timeout | ||
-- COMMAND ARGS Execute command with args after the test finishes | ||
USAGE | ||
exit 1 | ||
} | ||
|
||
wait_for() | ||
{ | ||
if [[ $TIMEOUT -gt 0 ]]; then | ||
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT" | ||
else | ||
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout" | ||
fi | ||
start_ts=$(date +%s) | ||
while : | ||
do | ||
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1 | ||
result=$? | ||
if [[ $result -eq 0 ]]; then | ||
end_ts=$(date +%s) | ||
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds" | ||
break | ||
fi | ||
sleep 1 | ||
done | ||
return $result | ||
} | ||
|
||
wait_for_wrapper() | ||
{ | ||
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 | ||
if [[ $QUIET -eq 1 ]]; then | ||
timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & | ||
else | ||
timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & | ||
fi | ||
PID=$! | ||
trap "kill -INT -$PID" INT | ||
wait $PID | ||
RESULT=$? | ||
if [[ $RESULT -ne 0 ]]; then | ||
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT" | ||
fi | ||
return $RESULT | ||
} | ||
|
||
# process arguments | ||
while [[ $# -gt 0 ]] | ||
do | ||
case "$1" in | ||
*:* ) | ||
hostport=(${1//:/ }) | ||
HOST=${hostport[0]} | ||
PORT=${hostport[1]} | ||
shift 1 | ||
;; | ||
--child) | ||
CHILD=1 | ||
shift 1 | ||
;; | ||
-q | --quiet) | ||
QUIET=1 | ||
shift 1 | ||
;; | ||
-s | --strict) | ||
STRICT=1 | ||
shift 1 | ||
;; | ||
-h) | ||
HOST="$2" | ||
if [[ $HOST == "" ]]; then break; fi | ||
shift 2 | ||
;; | ||
--host=*) | ||
HOST="${1#*=}" | ||
shift 1 | ||
;; | ||
-p) | ||
PORT="$2" | ||
if [[ $PORT == "" ]]; then break; fi | ||
shift 2 | ||
;; | ||
--port=*) | ||
PORT="${1#*=}" | ||
shift 1 | ||
;; | ||
-t) | ||
TIMEOUT="$2" | ||
if [[ $TIMEOUT == "" ]]; then break; fi | ||
shift 2 | ||
;; | ||
--timeout=*) | ||
TIMEOUT="${1#*=}" | ||
shift 1 | ||
;; | ||
--) | ||
shift | ||
CLI="$@" | ||
break | ||
;; | ||
--help) | ||
usage | ||
;; | ||
*) | ||
echoerr "Unknown argument: $1" | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
if [[ "$HOST" == "" || "$PORT" == "" ]]; then | ||
echoerr "Error: you need to provide a host and port to test." | ||
usage | ||
fi | ||
|
||
TIMEOUT=${TIMEOUT:-15} | ||
STRICT=${STRICT:-0} | ||
CHILD=${CHILD:-0} | ||
QUIET=${QUIET:-0} | ||
|
||
if [[ $CHILD -gt 0 ]]; then | ||
RESULT=$(wait_for) | ||
exit $RESULT | ||
else | ||
if [[ $TIMEOUT -gt 0 ]]; then | ||
wait_for_wrapper | ||
RESULT=$? | ||
else | ||
RESULT=$(wait_for) | ||
fi | ||
fi | ||
|
||
if [[ $CLI != "" ]]; then | ||
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then | ||
echoerr "$cmdname: strict mode, refusing to execute subprocess" | ||
exit $RESULT | ||
fi | ||
exec $CLI | ||
else | ||
exit $RESULT | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
consumer: | ||
build: consumer | ||
ports: | ||
- "${IP}8282:8282" | ||
links: | ||
- redis:redis | ||
- kafka:kafka | ||
- zookeeper:zk | ||
- rabbitmq:rabbit | ||
|
||
producer: | ||
build: producer | ||
ports: | ||
- "${IP}8080:8080" | ||
links: | ||
- redis:redis | ||
- kafka:kafka | ||
- zookeeper:zk | ||
- rabbitmq:rabbit | ||
|
||
redis: | ||
image: redis:3.0.7-alpine | ||
|
||
zookeeper: | ||
image: wurstmeister/zookeeper:3.4.6 | ||
ports: | ||
- "2181" | ||
kafka: | ||
image: wurstmeister/kafka:0.9.0.0-1 | ||
ports: | ||
- "9092" | ||
links: | ||
- zookeeper:zk | ||
environment: | ||
HOSTNAME_COMMAND: "route -n | awk '/UG[ \t]/{print $$2}'" | ||
privileged: true # Needed for SELinux | ||
volumes: | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
rabbitmq: | ||
image: bijukunjummen/rabbitmq-server | ||
ports: | ||
- "5672:5672" | ||
- "15672:15672" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM java:openjdk-8u91-jdk | ||
|
||
EXPOSE 8080 | ||
|
||
ADD bin/wait-for-it.sh /wait-for-it.sh | ||
|
||
# FIXME: fix /app volume issue with jdk base image. | ||
RUN mkdir -p /consumer && mkdir -p /producer | ||
|
||
ADD gr8-rest-producer-0.1.jar /producer/producer.jar | ||
|
||
CMD /bin/sh -c "/wait-for-it.sh redis:6379 --strict && /wait-for-it.sh kafka:9092 --strict && java -jar /producer/producer.jar --spring.profiles.active=docker" |
Oops, something went wrong.