Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit 0340de2

Browse files
committed
Added Vagrant push tracker to build and deploy new JavaScript Tracker (closes snowplow#313)
1 parent fa819c0 commit 0340de2

3 files changed

Lines changed: 102 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ aws.json
2828

2929
# Vagrant
3030
.vagrant
31+
VERSION

Vagrantfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ Vagrant.configure("2") do |config|
1616
sh.path = "vagrant/up.bash"
1717
end
1818

19+
# Requires Vagrant 1.7.0+
20+
config.push.define "push-tracker", strategy: "local-exec" do |push|
21+
push.script = "vagrant/push/publish-tracker.bash"
22+
end
23+
1924
end

vagrant/push/publish-tracker.bash

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Similar to Perl die
5+
function die() {
6+
echo "$@" 1>&2 ; exit 1;
7+
}
8+
9+
# Check if our Vagrant box is running. Expects `vagrant status` to look like:
10+
#
11+
# > Current machine states:
12+
# >
13+
# > default poweroff (virtualbox)
14+
# >
15+
# > The VM is powered off. To restart the VM, simply run `vagrant up`
16+
#
17+
# Parameters:
18+
# 1. out_running (out parameter)
19+
function is_running {
20+
[ "$#" -eq 1 ] || die "1 argument required, $# provided"
21+
local __out_running=$1
22+
23+
set +e
24+
vagrant status | sed -n 3p | grep -q "^default\s*running (virtualbox)$"
25+
local retval=${?}
26+
set -e
27+
if [ ${retval} -eq "0" ] ; then
28+
eval ${__out_running}=1
29+
else
30+
eval ${__out_running}=0
31+
fi
32+
}
33+
34+
# Get version, checking we are on the latest
35+
#
36+
# Parameters:
37+
# 1. out_version (out parameter)
38+
# 2. out_error (out parameter)
39+
function get_version {
40+
[ "$#" -eq 2 ] || die "2 arguments required, $# provided"
41+
local __out_version=$1
42+
local __out_error=$2
43+
44+
# Extract the version from package.json using Node and save it in a file named "VERSION"
45+
vagrant ssh -c "cd /vagrant && node -e \"var fs=require('fs');fs.readFile('./package.json', 'utf8', function(e,d){console.log(JSON.parse(d)['version'])});\" > VERSION" \
46+
|| die "Failed to get extract version information from package.json"
47+
file_version=`cat VERSION`
48+
tag_version=`git describe --abbrev=0 --tags`
49+
if [ ${file_version} != ${tag_version} ] ; then
50+
eval ${__out_error}="'File version ${file_version} != tag version ${tag_version}'"
51+
else
52+
eval ${__out_version}=${file_version}
53+
fi
54+
}
55+
56+
# Go to parent-parent dir of this script
57+
function cd_root() {
58+
source="${BASH_SOURCE[0]}"
59+
while [ -h "${source}" ] ; do source="$(readlink "${source}")"; done
60+
dir="$( cd -P "$( dirname "${source}" )/../.." && pwd )"
61+
cd ${dir}
62+
}
63+
64+
echo "Your AWS information will be saved in a temporary aws.json file, overwriting any existing aws.json file."
65+
read -p "Do you want to publish the Snowplow JavaScript Tracker? [Y/N]" -n 1 -r
66+
echo
67+
if [[ $REPLY =~ ^[Yy]$ ]]
68+
then
69+
cd_root
70+
71+
# Precondition for running
72+
running=0 && is_running "running"
73+
[ ${running} -eq 1 ] || die "Vagrant guest must be running to push"
74+
75+
# Git tag must match version in package.json
76+
version="" && error="" && get_version "version" "error"
77+
[ "${error}" ] && die "Versions don't match: ${error}. Are you trying to publish an old version, or maybe on the wrong branch?"
78+
79+
touch aws.json
80+
81+
echo "Please enter your AWS access key"
82+
read -e -s key
83+
echo "Please enter your AWS secret key"
84+
read -e -s secret
85+
echo "Please enter your AWS bucket"
86+
read -e -s bucket
87+
echo "Please enter your AWS distribution"
88+
read -e -s distribution
89+
90+
echo "{\"key\":\"$key\",\"secret\":\"$secret\",\"bucket\":\"$bucket\",\"distribution\":\"$distribution\"}" > aws.json
91+
92+
vagrant ssh -c "cd /vagrant && sudo npm install && grunt publish"
93+
94+
rm aws.json
95+
fi
96+
exit 0

0 commit comments

Comments
 (0)