From 44b6d8a79ae2d8d452f0ea193e3e82bc5d32acfd Mon Sep 17 00:00:00 2001 From: Carlos Munoz Date: Wed, 22 Jun 2016 13:26:20 +1000 Subject: [PATCH] feat: add docker development images (#1211) Add images, Dockerfile, scripts and documentation to be able to quickly run docker containers for Zanata development. --- README.md | 4 + docker/Dockerfile | 22 ++ docker/README.md | 104 +++++ docker/conf/admin-user-setup.sql | 9 + docker/conf/standalone.xml | 636 +++++++++++++++++++++++++++++++ docker/rundb.sh | 23 ++ docker/rundev.sh | 29 ++ 7 files changed, 827 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100644 docker/conf/admin-user-setup.sql create mode 100644 docker/conf/standalone.xml create mode 100755 docker/rundb.sh create mode 100755 docker/rundev.sh diff --git a/README.md b/README.md index 569a713c78..8cc4d1457c 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,7 @@ useful for starting a Zanata instance with the aim of running functional tests from an IDE. The `-h` argument prints the script's help. + +#### Development using docker (experimental) + +For a quick Zanata development environment with Docker, please visit the [docker README](docker/README.md). diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000000..1db9f0c1f0 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,22 @@ +FROM jboss/wildfly:10.0.0.Final + +USER root +RUN yum -y install mysql-connector-java wget && yum clean all + +RUN ln -sf /usr/share/java/mysql-connector-java.jar /opt/jboss/wildfly/standalone/deployments/mysql-connector-java.jar + +# Wildfly modules + +RUN wget --no-verbose https://dl.bintray.com/sflanigan/generic/wildfly-module-hibernate-main-4.2.20.Final.zip \ + && unzip -q wildfly-module-hibernate-main-4.2.20.Final.zip -d /opt/jboss/wildfly + +# ENV ZANATA_VERSION 3.9.0 + +# Zanata war (this is not needed for dev) +# RUN wget --no-verbose -O /opt/jboss/wildfly/standalone/deployments/ROOT.war \ +# https://github.com/zanata/zanata-server/releases/download/server-${ZANATA_VERSION}/zanata-war-${ZANATA_VERSION}.war \ +# && chmod o+rw /opt/jboss/wildfly/standalone/deployments/ROOT.war + +USER jboss + +ADD conf/standalone.xml /opt/jboss/wildfly/standalone/configuration/ diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000000..e845d5f0c0 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,104 @@ +This is a docker image for the Zanata server. This image runs a wildfly server with Zanata running on top of it. It does not run a database server for the Zanata application + +``` +This image has been tested with Docker 1.9 +``` + +## Building + +To build this docker image as "latest", simply type the following command: + +```sh +$ docker build -t zanata/server . +``` + +If you want to build with a different tag, eg 3.8.4, use a command like this: + +```sh +$ docker build -t zanata/server:3.8.4 . +``` + +Be careful about overwriting existing versions. + +The `-t` parameter indicates the name and/or tag for the image. + +## Running a Zanata server with Docker + +### Run a database server container + +Simply run + +```sh +$ ./rundb.sh +``` + +This script will start a docker container with the database. You can inspect the script file to learn the exact docker command it's running. + +The container will map the mysql data directory to `$HOME/docker-volumes/zanata-mariadb`. This can be changed from the script file. + +The database can be accessed via tcp via the `mysql` command or by using any database administration tool. You need to get the actual mapped port on the host by typing `docker ps`. After you have the port, you can connect locally to the database. The following is an example to accomplish this using a locally installed mysql client: + +```sh +mysql --protocol=tcp -h localhost --port= -uzanata -pzanatapw zanata +``` + +Alternatively, a docker container can be used to connect to the database using the mysql client like this: + +```sh +$ docker exec -i zanatadb mysql -uzanata -pzanatapw zanata +``` + +The username and password above are the default given by the `rundb.sh` script. If you wish to change them, edit the script file with your preferred credentials. + +_Note: The server container will be called `zanatadb`. Once stopped, docker will prevent the `rundb.sh` script from running again until the stopped container is removed. To do this, just type:_ + +```sh +$ docker rm zanatadb +``` + +If you don't remove the container, and later want to simply restart this same instance, you can simply run + +```sh +$ docker start zanatadb +``` + +## Run the Zanata development server container + +To start the Zanata server run: + +```sh +$ ./rundev.sh +``` + +This script will start another docker container with the Zanata server, and will log the server output. Unlike the database container, the server container will run in daemon mode. + +The server will connect to the db server which was started in the previous step. It will also take the zanata.war from any war file in the `zanata-war/target` directory. This means a war file must be built beforehand (See `etc/scripts/quickbuild.sh`). You must make sure there is only one `zanata-*.war` file in this directory, otherwise this step will fail. + +This container will have a mapped volume to your `$HOME/zanata` directory to store files, stats, caches, etc. This will allow for backups if you wish to switch between different versions of zanata for instance. + +## Create an admin user + +_This step is only required for empty databases. Since the `rundb.sh` script creates a mapped volume with all the mariadb data, it's not needed for subsequent runs._ + +At this point, you have a running Zanata instance... with no users created (!) + +To create an admin user, you can connect to the database server and run the script at `/conf/admin-user-setup.sql` like this: + +```sh +$ docker exec -i zanatadb mysql -uzanata -pzanatapw zanata < conf/admin-user-setup.sql +``` + +_Note the -u and -p parameters to the mysql command must be followed by the database username and password as indicated in the rundb.sh file. The values above are the default values in the script._ + +This will create a username `admin` with password `admin1234` + +## Access Zanata + +The docker host will forward port 8080 to the container's 8080 port where Wildfly is listening. + +Just open a browser and head to `http://IP_ADDRESS:8080`, where `IP_ADDRESS` is the docker host's address (again, this might localhost or some other IP address if running on OSX for example). + +## DockerHub + +The DockerHub site for Zanata images is here: +https://hub.docker.com/r/zanata/server/ diff --git a/docker/conf/admin-user-setup.sql b/docker/conf/admin-user-setup.sql new file mode 100644 index 0000000000..2a9c4ebc18 --- /dev/null +++ b/docker/conf/admin-user-setup.sql @@ -0,0 +1,9 @@ +-- Username: admin +-- Password: admin1234 +INSERT INTO HAccount (id, creationDate, lastChanged, versionNum, enabled, passwordHash, username) +VALUES (1, now(), now(), 1, 1, 'UZMf4PIqtTBGAo9wWKuTpg==', 'admin'); + +INSERT INTO HPerson (id, creationDate, lastChanged, versionNum, email, `name`, accountId) +VALUES (1, now(), now(), 1, 'admin@noreply.org', 'Administrator', 1); + +INSERT INTO HAccountMembership(accountId, memberOf) VALUES (1, 5); diff --git a/docker/conf/standalone.xml b/docker/conf/standalone.xml new file mode 100644 index 0000000000..bb6d479d34 --- /dev/null +++ b/docker/conf/standalone.xml @@ -0,0 +1,636 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jdbc:mysql://${env.DB_PORT_3306_TCP_ADDR}:3306/${env.DB_ENV_MYSQL_DATABASE}?characterEncoding=UTF-8 + com.mysql.jdbc.Driver + mysql-connector-java.jar + + 0 + 20 + FailingConnectionOnly + + + ${env.DB_ENV_MYSQL_USER} + ${env.DB_ENV_MYSQL_PASSWORD} + + + NOWARN + + + + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + h2 + + sa + sa + + + + + org.h2.jdbcx.JdbcDataSource + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${jboss.bind.address:127.0.0.1} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docker/rundb.sh b/docker/rundb.sh new file mode 100755 index 0000000000..e2246c97f7 --- /dev/null +++ b/docker/rundb.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Change these for different settings +DB_USERNAME=zanata +DB_PASSWORD=zanatapw +DB_SCHEMA=zanata +DB_ROOT_PASSWORD=rootpw + +VOLUME_DIR=$HOME/docker-volumes/zanata-mariadb + +mkdir -p $VOLUME_DIR +chcon -Rt svirt_sandbox_file_t $VOLUME_DIR + +docker run --name zanatadb \ + -e MYSQL_USER=$DB_USERNAME -e MYSQL_PASSWORD=$DB_PASSWORD \ + -e MYSQL_DATABASE=$DB_SCHEMA -e MYSQL_ROOT_PASSWORD=$DB_ROOT_PASSWORD \ + -P \ + -v $VOLUME_DIR:/var/lib/mysql \ + -d mariadb:10.1 \ + --character-set-server=utf8 --collation-server=utf8_general_ci + +echo '' +echo 'Please use the command "docker logs zanatadb" to check that MariaDB starts correctly.' diff --git a/docker/rundev.sh b/docker/rundev.sh new file mode 100755 index 0000000000..757527b6ed --- /dev/null +++ b/docker/rundev.sh @@ -0,0 +1,29 @@ +#!/bin/bash -x + +# 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 )" + +# change to top of the git working directory +cd $DIR/../ +ZANATA_WAR=$(echo $PWD/zanata-war/target/zanata-*.war) +# volume mapping for zanata server files +ZANATA_DIR=$HOME/docker-volumes/zanata +# create the data directory and set permissions (SELinux) +mkdir -p $ZANATA_DIR && chcon -Rt svirt_sandbox_file_t "$ZANATA_DIR" +# make zanata directory and standalone.xml file accessible to docker containers (SELinux) +chcon -Rt svirt_sandbox_file_t "$ZANATA_WAR" + +# build the docker dev image +docker build -t zanata/server-dev docker/ + +# runs zanata/server-dev:latest docker image +docker run --rm --name zanata --link zanatadb:db -p 8080:8080 -it \ + -v $ZANATA_WAR:/opt/jboss/wildfly/standalone/deployments/ROOT.war \ + -v $ZANATA_DIR:/opt/jboss/zanata \ + zanata/server-dev