Permalink
Browse files

Add MySQL as the default option

Handle configuring/starting/seeding mysql as the default option. In
this pass, we are handling Links, Runtime Variables and with in the
container. A future iteration will include service discovery.
  • Loading branch information...
1 parent 020f0de commit 3f6bbac056ed6f403bbb4b59593a619a11b3d256 @cloudnautique cloudnautique committed Feb 3, 2015
View
@@ -1,3 +1,8 @@
dist
.vagrant
.idea
+*.py[c-o]
+__pycache__
+.tox
+server/target
+MANIFEST
View
@@ -0,0 +1 @@
+--privileged
View
@@ -0,0 +1,4 @@
+FROM rancher/dind:v0.1.0
+COPY ./scripts/bootstrap /scripts/bootstrap
+RUN /scripts/bootstrap
+WORKDIR /source
View
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+apt-get update -q
+apt-get install -y python-dev python-pip python-tox libyaml-dev
+
+pip install -U pip tox virtualenv
+/usr/local/bin/pip install docker-compose==1.1.0
View
@@ -0,0 +1,111 @@
+#!/bin/bash
+
+teardown()
+{
+ rm -rf .tox
+ docker-compose -f fig-test-env.yml stop
+}
+
+wait_for_env()
+{
+ local url=$1
+ echo "Checking for $url availability"
+ for ((i=0;i<180;i++))
+ do
+ if [[ "$(curl -s ${url}/ping)" = "pong" ]]; then
+ if [[ "$i" = "1" ]]; then
+ echo "Environment at ${url} did not come up"
+ fi
+ break
+ else
+ sleep 1
+ fi
+ done
+}
+
+get_port()
+{
+ local id=$1
+ echo $(docker inspect -f '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' \
+ $id)
+}
+
+get_url()
+{
+ local port=$1
+ echo "http://${DOCKER_IP}:${port}"
+}
+
+setup()
+{
+ local server=$1
+ local url=$2
+ ID=$(fig_get_id $server)
+ PORT=$(get_port $ID)
+ export $url=$(get_url $PORT)
+ eval url=\$$url
+ wait_for_env $url
+}
+
+if [ -x /usr/local/bin/wrapdocker ]; then
+ wrapdocker > /tmp/docker.log 2>&1
+ WRAPPED="true"
+fi
+
+if [ "$(uname -s)" == "Linux" ]; then
+ export DOCKER_IP=$(ip addr show eth0 |grep inet|grep -v inet6|cut -d' ' -f6|cut -d'/' -f1)
+fi
+
+if [ $(command -v boot2docker) ]; then
+ export DOCKER_IP=$(boot2docker ip)
+fi
+
+cd $(dirname $0)/..
+pushd ./server > /dev/null
+./build-image.sh
+popd > /dev/null
+
+# Just doing server for now.
+pushd ./tests/server > /dev/null
+
+export CATTLE_DB_CATTLE_MYSQL_HOST=$DOCKER_IP
+docker-compose -f fig-test-env.yml build
+docker-compose -f fig-test-env.yml up -d
+
+fig_get_id()
+{
+ echo $(docker-compose -f fig-test-env.yml ps -q $1)
+}
+
+trap teardown EXIT
+
+for db_case in "h2dbcattle" "mysqllinkscattle" "mysqlmanualcattle" "localmysqlcattle"; do
+ echo $db_case
+
+ case $db_case in
+ h2dbcattle)
+ setup $db_case "CATTLE_H2DB_TEST_URL"
+ ;;
+ mysqllinkscattle)
+ setup $db_case "CATTLE_MYSQL_LINK_TEST_URL"
+ ;;
+ localmysqlcattle)
+ setup $db_case "CATTLE_MYSQL_LOCAL_TEST_URL"
+ ;;
+ mysqlmanualcattle)
+ setup $db_case "CATTLE_MYSQL_MANUAL_TEST_URL"
+ ;;
+ *)
+ echo "No tests setup for $db_case"
+ ;;
+ esac
+done
+
+popd > /dev/null
+if [[ "$WRAPPED" == "true" ]]; then
+ cp -r ./tests /scratch
+ pushd /scratch > /dev/null
+fi
+pushd tests/server >/dev/null
+rm -rf .tox
+tox
View
@@ -1,11 +1,27 @@
FROM ubuntu:14.04.1
-RUN apt-get update && apt-get install -y --no-install-recommends openjdk-7-jre-headless
-RUN apt-get update && apt-get install -y curl
+
+ENV DEBIAN_FRONTEND noninteractive
+RUN apt-get update && apt-get install -y --no-install-recommends openjdk-7-jre-headless \
+ curl \
+ mysql-server
+
ENV CATTLE_HOME /var/lib/cattle
ENV CATTLE_API_UI_INDEX http://cdn.rancher.io/ui/0.8.19/static/index.html
+ENV CATTLE_DB_CATTLE_DATABASE mysql
ADD artifacts /usr/share/cattle
+
+ADD service /service
+ENV S6_SERVICE_DIR /service
+
+COPY target/*static.tar.gz /s6-statics/
+RUN cd / && for i in $(ls /s6-statics/*static.tar.gz);do tar -zxvf $i;done
+
VOLUME ["/var/lib/cattle"]
+VOLUME ["/var/lib/mysql"]
+
EXPOSE 8080
-ENV RANCHER_SERVER_IMAGE v0.9.1
-CMD ["/usr/share/cattle/cattle.sh"]
+ENV RANCHER_SERVER_IMAGE v0.10.0-rc1
+
+EXPOSE 3306
ADD https://github.com/rancherio/cattle/releases/download/v0.16.0/cattle.jar /usr/share/cattle/
+CMD ["/usr/bin/s6-svscan", "/service"]
@@ -5,6 +5,7 @@ cd /var/lib/cattle
JAR=/usr/share/cattle/cattle.jar
DEBUG_JAR=/var/lib/cattle/lib/cattle-debug.jar
+export S6_SERVICE_DIR=${S6_SERVICE_DIR:-$S6_SERVICE_DIR}
if [ "$URL" != "" ]
then
@@ -34,12 +35,59 @@ setup_gelf()
fi
}
+start_local_mysql()
+{
+ s6-svc -u ${S6_SERVICE_DIR}/mysql
+
+ set +e
+ for ((i=0;i<60;i++))
+ do
+ if mysqladmin status 2> /dev/null; then
+ break
+ else
+ if [ "$i" -eq "59" ]; then
+ echo "Could not start MySQL..." 1>&2
+ exit 1
+ fi
+ sleep 1
+ fi
+ done
+ set -e
+}
+
+setup_local_db()
+{
+ local db_user=$CATTLE_DB_CATTLE_USERNAME
+ local db_pass=$CATTLE_DB_CATTLE_PASSWORD
+ local db_name=$CATTLE_DB_CATTLE_MYSQL_NAME
+
+ echo "Setting up database"
+ mysql -uroot<< EOF
+CREATE DATABASE IF NOT EXISTS ${db_name} COLLATE = 'utf8_general_ci' CHARACTER SET = 'utf8';
+GRANT ALL ON ${db_name}.* TO "${db_user}"@'%' IDENTIFIED BY "${db_pass}";
+GRANT ALL ON ${db_name}.* TO "${db_user}"@'localhost' IDENTIFIED BY "${db_pass}";
+EOF
+}
+
setup_mysql()
{
- export CATTLE_DB_CATTLE_MYSQL_HOST=${CATTLE_DB_CATTLE_MYSQL_HOST:-$MYSQL_PORT_3306_TCP_ADDR}
- export CATTLE_DB_CATTLE_MYSQL_PORT=${CATTLE_DB_CATTLE_MYSQL_PORT:-$MYSQL_PORT_3306_TCP_PORT}
- if [ -n "$CATTLE_DB_CATTLE_MYSQL_HOST" ]; then
- export CATTLE_DB_CATTLE_DATABASE=${CATTLE_DB_CATTLE_DATABASE:-mysql}
+ # Set in the Dockerfile by default... overriden by runtime.
+ if [ ${CATTLE_DB_CATTLE_DATABASE} == "mysql" ]; then
+ export CATTLE_DB_CATTLE_MYSQL_HOST=${CATTLE_DB_CATTLE_MYSQL_HOST:-$MYSQL_PORT_3306_TCP_ADDR}
+ export CATTLE_DB_CATTLE_MYSQL_PORT=${CATTLE_DB_CATTLE_MYSQL_PORT:-$MYSQL_PORT_3306_TCP_PORT}
+ export CATTLE_DB_CATTLE_USERNAME=${CATTLE_DB_CATTLE_USERNAME:-cattle}
+ export CATTLE_DB_CATTLE_PASSWORD=${CATTLE_DB_CATTLE_PASSWORD:-cattle}
+ export CATTLE_DB_CATTLE_MYSQL_NAME=${CATTLE_DB_CATTLE_MYSQL_NAME:-cattle}
+
+ if [ -z "$CATTLE_DB_CATTLE_MYSQL_HOST" ]; then
+ export CATTLE_DB_CATTLE_MYSQL_HOST="localhost"
+ start_local_mysql
+ setup_local_db
+ fi
+
+ if [ -z "$CATTLE_DB_CATTLE_MYSQL_PORT" ]; then
+ CATTLE_DB_CATTLE_MYSQL_PORT=3306
+ fi
fi
}
@@ -1,7 +1,12 @@
#!/bin/bash
+
+cd $(dirname $0)
+
+mkdir target
+docker run -it -v $(pwd)/target:/output rancher/s6-builder:v0.1.0 /opt/build.sh
+
TAG=${TAG:-dev}
IMAGE=rancher/server:${TAG}
-cd $(dirname $0)
docker build -t ${IMAGE} .
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+s6-svcscanctl -t /service
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+exec /usr/share/cattle/cattle.sh
No changes.
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+s6-svcscanctl -t /service
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+exec 2>&1
+exec /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
@@ -0,0 +1 @@
+Rancher tests
@@ -0,0 +1,42 @@
+h2dbcattle:
+ image: rancher/server:dev
+ ports:
+ - "8080:8080"
+ environment:
+ CATTLE_DB_CATTLE_DATABASE: h2
+mysqllink:
+ image: mysql:latest
+ environment:
+ MYSQL_ROOT_PASSWORD: password
+ MYSQL_USER: cattle
+ MYSQL_PASSWORD: cattle
+ MYSQL_DATABASE: cattle
+mysqllinkscattle:
+ image: rancher/server:dev
+ ports:
+ - "8081:8080"
+ links:
+ - mysqllink:mysql
+localmysqlcattle:
+ image: rancher/server:dev
+ ports:
+ - "8082:8080"
+mysqlmanual:
+ image: mysql:latest
+ ports:
+ - "13306:3306"
+ environment:
+ MYSQL_ROOT_PASSWORD: 'password'
+ MYSQL_USER: 'cattle1'
+ MYSQL_PASSWORD: 'cattle1'
+ MYSQL_DATABASE: 'cattle1'
+mysqlmanualcattle:
+ image: rancher/server:dev
+ environment:
+ CATTLE_DB_CATTLE_MYSQL_HOST:
+ CATTLE_DB_CATTLE_MYSQL_PORT: '13306'
+ CATTLE_DB_CATTLE_USERNAME: 'cattle1'
+ CATTLE_DB_CATTLE_PASSWORD: 'cattle1'
+ CATTLE_DB_CATTLE_MYSQL_NAME: 'cattle1'
+ ports:
+ - "8083:8080"
@@ -0,0 +1,2 @@
+[pytest]
+norecursedirs = .git .tox server agent docs server
No changes.
Oops, something went wrong.

0 comments on commit 3f6bbac

Please sign in to comment.