Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added test to database before start http
villadalmine committed Sep 12, 2016
1 parent 2f71915 commit 69bad1d
Showing 11 changed files with 82 additions and 8 deletions.
4 changes: 2 additions & 2 deletions 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
#### test.sh
6 changes: 6 additions & 0 deletions 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 .
10 changes: 10 additions & 0 deletions 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
13 changes: 13 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions bin/rebuild.sh
@@ -0,0 +1,3 @@
#!/bin/bash

source bin/destroy.sh && source bin/build.sh
3 changes: 3 additions & 0 deletions bin/rerun.sh
@@ -0,0 +1,3 @@
#!/bin/bash

source bin/rebuild.sh && source bin/run.sh $1
5 changes: 5 additions & 0 deletions bin/run.sh
@@ -0,0 +1,5 @@
#!/bin/bash

source common.bash .

docker run -it $maintainer/$imagename $1
8 changes: 8 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions bin/test.sh
@@ -0,0 +1,3 @@
#!/bin/bash

bats tests
28 changes: 22 additions & 6 deletions container_files/bin/start.sh
@@ -15,19 +15,35 @@ 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
echo "Composed so waiting for MariaDB: " > $log
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

0 comments on commit 69bad1d

Please sign in to comment.