Skip to content

Commit

Permalink
Merge branch 'feature/vagrant'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderdean committed Jan 7, 2015
2 parents 88a112a + 1634faf commit 1ae223f
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Only project- and language-specific ignores in here. Use global .gitignore for editors etc

# Vagrant
.vagrant/
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: java

jdk:
- oraclejdk7

script:
./ci/lint.bash
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Release 22 (2015-01-07)
-----------------------
Added Release button to README (#104)
Added dedicated Vagrant setup (#100)
Added Travis support to project (#99)
Implemented vagrant push scripting for deployment (#101)

Release 21 (2015-01-05)
-----------------------
Added: com.snowplowanalytics.snowplow/elasticsearch_enriched_event/jsonschema/1-0-0
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Iglu Central

[ ![Build Status] [travis-image] ] [travis] [ ![Release] [release-image] ] [releases]

Iglu Central (**[webite] [iglucentral-website]**) is a central repository for storing JSON Schemas, maintained and hosted by the team at **[Snowplow Analytics] [snowplow-website]**. Think of it like RubyGems.org or Maven Central but for storing data schemas instead of code.

All of the schemas for **[Snowplow] [snowplow-repo]** (amongst other systems) are stored in Iglu Central.
Expand All @@ -25,6 +27,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

[travis]: https://travis-ci.org/snowplow/iglu-central
[travis-image]: https://travis-ci.org/snowplow/iglu-central.png?branch=master

[release-image]: http://img.shields.io/badge/release-22-ff69b4.svg?style=flat
[releases]: https://github.com/snowplow/iglu-central/releases

[iglucentral-website]: http://iglucentral.com
[snowplow-repo]: https://github.com/snowplow/snowplow
[snowplow-wiki]: https://github.com/snowplow/snowplow/wiki
Expand Down
23 changes: 23 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Vagrant.configure("2") do |config|

config.vm.box = "ubuntu/trusty64"
config.ssh.forward_agent = true

config.vm.provider :virtualbox do |vb|
vb.name = Dir.pwd().split("/")[-1] + "-" + Time.now.to_f.to_i.to_s
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize [ "guestproperty", "set", :id, "--timesync-threshold", 10000 ]
# We don't need much memory for working with schemas
vb.memory = 512
end

# Requires Vagrant 1.7.0+
config.push.define "binary", strategy: "local-exec" do |push|
push.script = "vagrant/push.bash"
end

config.vm.provision :shell do |sh|
sh.path = "vagrant/up.bash"
end

end
101 changes: 101 additions & 0 deletions ci/lint.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash
set -e

# Constants
install_dir="/tmp"
validator_v="2.2.6"
validator_uri="https://bintray.com/artifact/download/fge/maven/com/github/fge/json-schema-validator/${validator_v}"
validator_jar="json-schema-validator-${validator_v}-lib.jar"
jsonschema_glob="schemas/*/*/jsonschema"

# Similar to Perl die
function die() {
echo "$@" 1>&2 ; exit 1;
}

# Go to parent dir of this script
function cd_script_parent() {
source="${BASH_SOURCE[0]}"
while [ -h "${source}" ] ; do source="$(readlink "${source}")"; done
dir="$( cd -P "$( dirname "${source}" )/.." && pwd )"
cd ${dir}
}

# Downloads and installs the full-fat XXX jarfile
function install_validator() {
if [ ! -f ${install_dir}/${validator_jar} ] ; then
wget ${validator_uri}/${validator_jar} -P ${install_dir}
fi
echo "... done"
}

# Checks a single JSON Schema's syntax.
#
# Arguments:
# 1. schema_path
# 2. sucesses
# 3. failures
# 4. out_successes (out parameter)
# 5. out_failures (out parameter)
function check_syntax() {
[ "$#" -eq 5 ] || die "5 arguments required, $# provided"
local __schema_path=$1
local __successes=$2
local __failures=$3
local __out_successes=$4
local __out_failures=$5

set +e
lint_out=`java -jar ${install_dir}/${validator_jar} --syntax ${1}`
local lint_ok=${?}
set -e
if [ ${lint_ok} == "0" ] ; then
echo "[ $(tput setaf 2)+$(tput sgr0) ] ${1}"
eval $__out_successes="$((__successes+1))"
else
echo "[ $(tput setaf 1)x$(tput sgr0) ] ${1}"
echo ""
echo ${lint_out}
echo ""
eval ${__out_failures}="$((__failures+1))"
fi
}

# Checks all schemas
#
# Arguments:
# 1. out_status (out parameter)
function check_schemas() {
[ "$#" -eq 1 ] || die "1 argument required, $# provided"
local __out_status=$1

successes=0
failures=0
schemas=`find ${jsonschema_glob} -type f`
while read schema; do
check_syntax ${schema} ${successes} ${failures} "successes" "failures"
done <<< "${schemas}"
echo ""
echo "... JSON Schema syntax tests: $(tput setaf 2)${successes}$(tput sgr0) passed; $(tput setaf 1)${failures}$(tput sgr0) failed"
if (( ${failures} > 0 )); then
eval ${__out_status}="'1'"
else
eval ${__out_status}="'0'"
fi
}


cd_script_parent

echo "================================"
echo "INSTALLING JSON SCHEMA VALIDATOR"
echo "--------------------------------"

install_validator

echo "==================================="
echo "CHECKING SYNTAX OF ALL JSON SCHEMAS"
echo "-----------------------------------"

check_schemas "check_status"
exit ${check_status}
3 changes: 3 additions & 0 deletions vagrant/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.peru
oss-playbooks
ansible
2 changes: 2 additions & 0 deletions vagrant/ansible.hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[vagrant]
127.0.0.1:2222
14 changes: 14 additions & 0 deletions vagrant/peru.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
imports:
ansible: ansible
ansible_playbooks: oss-playbooks

curl module ansible:
# Equivalent of git cloning tags/v1.6.6 but much, much faster
url: https://codeload.github.com/ansible/ansible/zip/69d85c22c7475ccf8169b6ec9dee3ee28c92a314
build: unzip ansible-69d85c22c7475ccf8169b6ec9dee3ee28c92a314.zip
export: ansible-69d85c22c7475ccf8169b6ec9dee3ee28c92a314

git module ansible_playbooks:
url: https://github.com/snowplow/ansible-playbooks.git
# Comment out to fetch a specific rev instead of master:
# rev: xxx
13 changes: 13 additions & 0 deletions vagrant/push.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -e

s3_bucket=iglucentral.com

# Get the parent directory of where this script is.
source="${BASH_SOURCE[0]}"
while [ -h "${source}" ] ; do source="$(readlink "${source}")"; done
dir="$( cd -P "$( dirname "${source}" )/.." && pwd )"
cd ${dir}

# Note - this runs on HOST: https://groups.google.com/forum/#!topic/vagrant-up/LgqE-JFAqZc
aws s3 cp schemas/ s3://${s3_bucket}/schemas/ --include "*.*" --recursive
50 changes: 50 additions & 0 deletions vagrant/up.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -e

vagrant_dir=/vagrant/vagrant
bashrc=/home/vagrant/.bashrc

echo "========================================"
echo "INSTALLING PERU AND ANSIBLE DEPENDENCIES"
echo "----------------------------------------"
apt-get update
apt-get install -y language-pack-en git unzip libyaml-dev python3-pip python-yaml python-paramiko python-jinja2

echo "==============="
echo "INSTALLING PERU"
echo "---------------"
sudo pip3 install peru

echo "======================================="
echo "CLONING ANSIBLE AND PLAYBOOKS WITH PERU"
echo "---------------------------------------"
cd ${vagrant_dir} && peru sync -v
echo "... done"

env_setup=${vagrant_dir}/ansible/hacking/env-setup
hosts=${vagrant_dir}/ansible.hosts

echo "==================="
echo "CONFIGURING ANSIBLE"
echo "-------------------"
touch ${bashrc}
echo "source ${env_setup}" >> ${bashrc}
echo "export ANSIBLE_HOSTS=${hosts}" >> ${bashrc}
echo "... done"

echo "=========================================="
echo "RUNNING PLAYBOOKS WITH ANSIBLE*"
echo "* no output while each playbook is running"
echo "------------------------------------------"
while read pb; do
su - -c "source ${env_setup} && ${vagrant_dir}/ansible/bin/ansible-playbook ${vagrant_dir}/${pb} --connection=local --inventory-file=${hosts}" vagrant
done <${vagrant_dir}/up.playbooks

guidance=${vagrant_dir}/up.guidance

if [ -f ${guidance} ]; then
echo "==========="
echo "PLEASE READ"
echo "-----------"
cat $guidance
fi
4 changes: 4 additions & 0 deletions vagrant/up.guidance
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To get started:
vagrant ssh
cd /vagrant
xxx
1 change: 1 addition & 0 deletions vagrant/up.playbooks
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oss-playbooks/java7.yml

0 comments on commit 1ae223f

Please sign in to comment.