Skip to content

Commit

Permalink
start refactoring the shell commands, automatically push the new version
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Dec 7, 2015
1 parent 9313d3f commit 320bb81
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 18 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ after_script:

# deployment
before_deploy: "./war.sh"
after_deploy: "./catalogue docker notify"
deploy:
provider: releases
api_key:
Expand Down
24 changes: 24 additions & 0 deletions bin/docker/notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

echo "Travis reported branch $TRAVIS_BRANCH"

#go to home and setup git
cd $HOME
git config --global user.email "[email protected]"
git config --global user.name "Travis"

git clone --quiet --branch=2.x https://${GH_TOKEN}@github.com/MetadataRegistry/registry.git registry > /dev/null

cd registry

sed "s/ENV MC_VERSION.*/ENV MC_VERSION $TRAVIS_TAG/" Dockerfile > TemporaryDockerfile
rm Dockerfile
mv TemporaryDockerfile Dockerfile

git add -A .
git commit -m "Travis MetadataRegistry/ModelCataloguePlugin build $TRAVIS_BUILD_NUMBER pushed MetadataRegistry/registry"
git tag "$TRAVIS_TAG"
git push -fq origin 2.x > /dev/null
git push -fq origin "$TRAVIS_TAG" > /dev/null

echo "Metadata Registry notified of successful build"
68 changes: 68 additions & 0 deletions bin/lib/delegate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

###
# prints single command with it's description using the first line of the text file named same as the command
# but having .txt extension.
###
function print_command() {
local PADDING=' '
local FOLDER=$1
local COMMAND=$2
local DESC="(no description provided)"

if [ -f "$FOLDER/$COMMAND.txt" ] ; then
DESC=$(head -n 1 "$FOLDER/$COMMAND.txt")
fi

printf "%s %s %s\n" "$COMMAND" "${PADDING:${#COMMAND}}" "$DESC"
}

###
# prints usage for folder listing all *.sh files and directories (except lib directory)
# @param FOLDER folder to be listed
###
function print_usage_for_folder(){
local ORIGINAL_DIRECTORY=$(pwd)
cd "$1"
echo "Usage:"
for f in * ; do
if [ "$f" == "lib" ] ; then
continue
elif [ -d "$f" ]; then
print_command $(pwd) "$f"
elif [ "$f" == *.sh ]; then
local COMMAND_NAME="${f/.sh/}"
print_command $(pwd) "$COMMAND_NAME"
fi
done
cd "$ORIGINAL_DIRECTORY"
}

###
# delegates to scripts inside folder
# @param FOLDER folder to be delegated to
# @param COMMAND name of the script to be delegated to
###
function delegate_to_folder() {
local FOLDER="$1"
local SCRIPT="$2"
local COMMAND="$FOLDER""/""$SCRIPT"

shift 2


if [ -d "$COMMAND" ]; then
delegate_to_folder "$COMMAND" "$@"
elif [ -f "$COMMAND.sh" ]; then
"$COMMAND.sh" "$@"
else
COMMAND=${COMMAND//bin\///}
COMMAND=${COMMAND//\// }
echo
echo "Unknown command:$COMMAND"
echo
print_usage_for_folder "$FOLDER"
echo
exit 2
fi
}
1 change: 1 addition & 0 deletions bin/nested.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests the command
3 changes: 3 additions & 0 deletions bin/nested/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo "nested"
3 changes: 3 additions & 0 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo "test"
1 change: 1 addition & 0 deletions bin/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests the command
5 changes: 5 additions & 0 deletions catalogue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

source bin/lib/delegate.sh

delegate_to_folder "bin" "$@"
73 changes: 55 additions & 18 deletions conf/docker/mc-config.groovy
Original file line number Diff line number Diff line change
@@ -1,29 +1,66 @@
// config
grails.logging.jul.usebridge = false
grails.serverURL = "http://${System.getenv('VIRTUAL_HOST')}"
grails.serverURL = "http://${System.getenv('VIRTUAL_HOST') ?: System.getenv('METADATA_URL')}"

// datasource
dataSource {
driverClassName = "com.mysql.jdbc.Driver"
dialect='org.hibernate.dialect.MySQL5InnoDBDialect'
url = "jdbc:mysql://mc-mysql:3306/metadata?autoReconnect=true&useUnicode=yes"
username = "metadata"
password = "metadata"
dbCreate = "update"
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=false
validationQuery="SELECT 1"
jdbcInterceptors="ConnectionState"

def metadataDbPassword = System.getenv('METADATA_PASSWORD')
def metadataDbUsername = System.getenv('METADATA_USERNAME')
def metadataJdbcString = System.getenv('METADATA_JDBC_URL')

if (!metadataJdbcString && System.getenv("MC_MYSQL_NAME")) {
metadataJdbcString = "jdbc:mysql://mc-mysql:3306/metadata?autoReconnect=true&useUnicode=yes"
}

if (metadataJdbcString) {
driverClassName = "com.mysql.jdbc.Driver"
dialect='org.hibernate.dialect.MySQL5InnoDBDialect'
url = metadataJdbcString
username = metadataDbUsername
password = metadataDbPassword
dbCreate = "update"
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=false
validationQuery="SELECT 1"
jdbcInterceptors="ConnectionState"
}
} else {
def dbdir = "${System.properties['catalina.base']}/db"

dbCreate = "update"
url = "jdbc:h2:file:${dbdir};MVCC=TRUE;LOCK_TIMEOUT=10000"
pooled = true
username = "sa"
password = "db!admin"

properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}


}

mc.search.elasticsearch.host='mc-es'
if (System.getenv("MC_ES_NAME")) {
// mc-es is bound
mc.search.elasticsearch.host='mc-es'
} else {
mc.search.elasticsearch.local="${System.properties['catalina.base']}/es"
}

grails.plugin.console.enabled=true

Expand Down

0 comments on commit 320bb81

Please sign in to comment.