From 69bad1ddb913e6c05a76f17caf799f8b47a85b4a Mon Sep 17 00:00:00 2001 From: villadalmine Date: Mon, 12 Sep 2016 14:41:54 -0300 Subject: [PATCH] Added test to database before start http --- BINSCRIPTS.md | 4 ++-- bin/build.sh | 6 ++++++ bin/destroy.sh | 10 ++++++++++ bin/install.sh | 13 +++++++++++++ bin/rebuild.sh | 3 +++ bin/rerun.sh | 3 +++ bin/run.sh | 5 +++++ bin/start.sh | 8 ++++++++ bin/stop.sh | 7 +++++++ bin/test.sh | 3 +++ container_files/bin/start.sh | 28 ++++++++++++++++++++++------ 11 files changed, 82 insertions(+), 8 deletions(-) create mode 100755 bin/build.sh create mode 100755 bin/destroy.sh create mode 100755 bin/install.sh create mode 100755 bin/rebuild.sh create mode 100755 bin/rerun.sh create mode 100755 bin/run.sh create mode 100755 bin/start.sh create mode 100755 bin/stop.sh create mode 100755 bin/test.sh diff --git a/BINSCRIPTS.md b/BINSCRIPTS.md index 8569b7d..7818108 100644 --- a/BINSCRIPTS.md +++ b/BINSCRIPTS.md @@ -9,7 +9,7 @@ If you are reading this file in BINSCRIPTS.md, your container project is likely To use these scripts yourself, issue this command: ``` -curl "https://github.internet2.edu/raw/docker/util/master/bin/install.sh?token=AAAAEddkrL9MeeA6VWcNn_PgV30r4lD1ks5XogeiwA%3D%3D" | bash +curl "https://github.internet2.edu/raw/docker/util/master/bin/install.sh?token=AAAAE4VRBLPB8VExPHSR5nCe791IAYqaks5Xzug5wA%3D%3D" | bash ``` ### common.bash @@ -38,4 +38,4 @@ This will also install a Jenkinsfile to your repository, if it doesn't have one. ### Testing -#### test.sh \ No newline at end of file +#### test.sh diff --git a/bin/build.sh b/bin/build.sh new file mode 100755 index 0000000..190c975 --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +source common.bash . + +echo "Building new Docker image($maintainer/$imagename)" +docker build --rm -t $maintainer/$imagename --build-arg maintainer=$maintainer --build-arg imagename=$imagename --build-arg version=$version . \ No newline at end of file diff --git a/bin/destroy.sh b/bin/destroy.sh new file mode 100755 index 0000000..929c13e --- /dev/null +++ b/bin/destroy.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +source common.bash . + +result=$(docker ps -a | grep $maintainer/$imagename) + +if [ ! -z "$result" ]; then + docker rm -f $(docker ps -a | grep $maintainer/$imagename | awk '{print $1}') + docker rmi -f $maintainer/$imagename +fi diff --git a/bin/install.sh b/bin/install.sh new file mode 100755 index 0000000..2db62de --- /dev/null +++ b/bin/install.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +git clone git@github.internet2.edu:docker/util.git +find util/bin -name "*.sh" -exec sh -c 'echo "$1" | sed "s/util\///" >> .gitignore' -- {} \; +mkdir -p bin +mv util/bin/* bin/. +mv util/README.md BINSCRIPTS.md +if [ ! -f common.bash ]; then + mv util/common.bash.sample common.bash +fi +if [ ! -f Jenkinsfile ]; then + mv util/Jenkinsfile.sample Jenkinsfile +fi +rm -rf util \ No newline at end of file diff --git a/bin/rebuild.sh b/bin/rebuild.sh new file mode 100755 index 0000000..3904e58 --- /dev/null +++ b/bin/rebuild.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +source bin/destroy.sh && source bin/build.sh \ No newline at end of file diff --git a/bin/rerun.sh b/bin/rerun.sh new file mode 100755 index 0000000..e279386 --- /dev/null +++ b/bin/rerun.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +source bin/rebuild.sh && source bin/run.sh $1 \ No newline at end of file diff --git a/bin/run.sh b/bin/run.sh new file mode 100755 index 0000000..8af1b06 --- /dev/null +++ b/bin/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +source common.bash . + +docker run -it $maintainer/$imagename $1 \ No newline at end of file diff --git a/bin/start.sh b/bin/start.sh new file mode 100755 index 0000000..9b74d72 --- /dev/null +++ b/bin/start.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +source common.bash . + +echo "Building new Docker image($registry/$maintainer/$imagename)" +docker run --name=$imagename -d $maintainer/$imagename + +exit 0 \ No newline at end of file diff --git a/bin/stop.sh b/bin/stop.sh new file mode 100755 index 0000000..01a2252 --- /dev/null +++ b/bin/stop.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +source common.bash . + +echo "Cleaning up Docker image($maintainer/$imagename)" +docker stop $imagename >> /dev/null +exit 0 diff --git a/bin/test.sh b/bin/test.sh new file mode 100755 index 0000000..6d4b8be --- /dev/null +++ b/bin/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +bats tests \ No newline at end of file diff --git a/container_files/bin/start.sh b/container_files/bin/start.sh index 29c15e6..c778966 100755 --- a/container_files/bin/start.sh +++ b/container_files/bin/start.sh @@ -15,8 +15,8 @@ then else echo "COmanage was configured" >>$log echo "COmanage was configured" - echo "Starting apache" >>$log - echo "Starting apache" + echo "Starting apache and shibd" >>$log + echo "Starting apache shibd" /usr/local/bin/httpd-shib-foreground fi else @@ -24,10 +24,26 @@ else date >> $log echo "Testing connectivity to database before continue with install" >> $log echo "Testing connectivity to database before continue with install" - /opt/wait-for-it/wait-for-it.sh $MYSQL_HOST:3306 -t $WAIT_TIME --strict -- /opt/bin/main.sh - + /opt/wait-for-it/wait-for-it.sh $MYSQL_HOST:3306 -t $WAIT_TIME --strict -- /opt/bin/main.sh >> $log + echo "Mariadb default port is open and test connection ok" + echo "Mariadb default port is open and test connection ok" >> $log + echo "Testing connectivy to database before continue with install" >> $log + echo "Testing connectivy to database before continue with install" + mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -h "$MYSQL_HOST" -e "use $MYSQL_DATABASE; show tables;" + laststatus="$?" + echo "checking connectivity" >> $log + while [ "$laststatus" != "0" ]; do + mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -h "$MYSQL_HOST" -e "use $MYSQL_DATABASE; show tables;" + laststatus="$?" + sleep 5 + date >> $log + echo "Trying to connect to mariadb container with $MYSQL_USER to database $MYSQL_DATABASE" + echo "Trying to connect to mariadb container with $MYSQL_USER to database $MYSQL_DATABASE" >> $log + done + echo "Database Connection with $MYSQL_USER to database $MYSQL_DATABASE was completed without any error" >> $log + echo "Database Connection with $MYSQL_USER to database $MYSQL_DATABASE was completed without any error" date >> $log - echo "Starting apache" >>$log - echo "Starting apache" + echo "Starting apache and shibd" >>$log + echo "Starting apache shibd" /usr/local/bin/httpd-shib-foreground fi