Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
provide db env from rundev script
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Oct 13, 2016
1 parent 880a0e2 commit e851fd9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM jboss/wildfly:10.1.0.Final

ENV DB_HOSTNAME=zanatadb DB_USERNAME=zanata DB_PASSWORD=zanatapw DB_NAME=zanata
ENV DB_HOSTNAME=zanatadb

# create mysql module
USER root
Expand Down
21 changes: 21 additions & 0 deletions docker/common
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# default settings for the scripts

# default database settings value
DB_USERNAME=zanata
DB_PASSWORD=zanatapw
DB_SCHEMA=zanata
DB_ROOT_PASSWORD=rootpw

# default docker network to join
DOCKER_NETWORK=docker-network

function ensure_docker_network() {
# check if the docker network is already created
if docker network ls | grep -w ${DOCKER_NETWORK}
then
echo "will use docker network $DOCKER_NETWORK"
else
echo "creating docker network $DOCKER_NETWORK"
docker network create ${DOCKER_NETWORK}
fi
}
2 changes: 1 addition & 1 deletion docker/conf/standalone.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<subsystem xmlns="urn:jboss:domain:datasources:4.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/zanataDatasource" pool-name="zanataDatasource" enabled="true" use-ccm="true">
<connection-url>jdbc:mysql://${env.DB_HOSTNAME:zanatadb}:3306/${env.DB_NAME:zanata}?characterEncoding=UTF-8</connection-url>
<connection-url>jdbc:mysql://${env.DB_HOSTNAME:zanatadb}:3306/${env.DB_SCHEMA:zanata}?characterEncoding=UTF-8</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql</driver>
<pool>
Expand Down
34 changes: 14 additions & 20 deletions docker/rundb.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
#!/bin/bash

# Change these for different settings
DB_USERNAME=zanata
DB_PASSWORD=zanatapw
DB_SCHEMA=zanata
DB_ROOT_PASSWORD=rootpw
# default docker network to join
DOCKER_NETWORK=docker-network
# determine directory containing this script
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

source ${DIR}/common

VOLUME_DIR=$HOME/docker-volumes/zanata-mariadb

mkdir -p $VOLUME_DIR
chcon -Rt svirt_sandbox_file_t $VOLUME_DIR

# docker network option

while getopts ":n:H" opt; do
while getopts ":n:h" opt; do
case ${opt} in
n)
echo "===== set docker network to $OPTARG ====="
DOCKER_NETWORK="$OPTARG"
;;
H)
h)
echo "======== HELP ========="
echo "-n <docker network>: will connect container to given docker network (default is $DOCKER_NETWORK)"
echo "-H : display help"
echo "-h : display help"
exit
;;
\?)
Expand All @@ -34,14 +35,7 @@ while getopts ":n:H" opt; do
esac
done

# check if the docker network is already created
if docker network ls | grep -w ${DOCKER_NETWORK}
then
echo "will use docker network $DOCKER_NETWORK"
else
echo "creating docker network $DOCKER_NETWORK"
docker network create ${DOCKER_NETWORK}
fi
ensure_docker_network

docker run --name zanatadb \
-e MYSQL_USER=$DB_USERNAME -e MYSQL_PASSWORD=$DB_PASSWORD \
Expand Down
21 changes: 7 additions & 14 deletions docker/rundev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

source ${DIR}/common

# change to top of the git working directory
cd $DIR/../
ZANATA_WAR=$(echo $PWD/zanata-war/target/zanata-*.war)
Expand All @@ -35,10 +37,7 @@ HTTP_PORT=8080
DEBUG_PORT=8787
MGMT_PORT=9090

# default docker network to join
DOCKER_NETWORK=docker-network

while getopts ":p:n:H" opt; do
while getopts ":p:n:h" opt; do
case ${opt} in
p)
echo "===== set JBoss port offset to $OPTARG ====="
Expand All @@ -59,11 +58,11 @@ while getopts ":p:n:H" opt; do
echo "===== set docker network to $OPTARG ====="
DOCKER_NETWORK=$OPTARG
;;
H)
h)
echo "======== HELP ========="
echo "-p <offset number> : set JBoss port offset"
echo "-n <docker network>: will connect container to given docker network (default is $DOCKER_NETWORK)"
echo "-H : display help"
echo "-h : display help"
exit
;;
\?)
Expand All @@ -73,14 +72,7 @@ while getopts ":p:n:H" opt; do
esac
done

# check if the docker network is already created
if docker network ls | grep -w ${DOCKER_NETWORK}
then
echo "will use docker network $DOCKER_NETWORK"
else
echo "creating docker network $DOCKER_NETWORK"
docker network create ${DOCKER_NETWORK}
fi
ensure_docker_network

# volume mapping for zanata server files
ZANATA_DIR=$HOME/docker-volumes/zanata
Expand All @@ -100,6 +92,7 @@ JBOSS_DEPLOYMENT_VOLUME=/opt/jboss/wildfly/standalone/deployments/
# runs zanata/server-dev:latest docker image
docker run \
-e JAVA_OPTS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/jboss/zanata" \
-e DB_USERNAME=${DB_USERNAME} -e DB_PASSWORD=${DB_PASSWORD} -e DB_SCHEMA=${DB_SCHEMA} -e DB_HOSTNAME=zanatadb\
--rm --name zanata --net=${DOCKER_NETWORK} \
-p ${HTTP_PORT}:8080 -p ${DEBUG_PORT}:8787 -p ${MGMT_PORT}:9990 -it \
-v ${ZANATA_DEPLOYMENTS_DIR}:${JBOSS_DEPLOYMENT_VOLUME} \
Expand Down

0 comments on commit e851fd9

Please sign in to comment.