From 3e2989d954ce33822f8234462d12d4b12b1a2fe8 Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Mon, 10 Jun 2013 21:26:31 -0700 Subject: [PATCH] committing my progress, but no working tests yet. stuck on bug where I can't curl the URL I get from the deploy transcript --- tests/nodejs/express/Procfile | 1 + tests/nodejs/express/package.json | 11 +++++++++++ tests/nodejs/express/web.js | 12 ++++++++++++ tests/{run.sh => run_ec2} | 15 ++++++++++----- tests/run_vagrant | 14 ++++++++++++++ tests/test_deploy | 21 +++++++++++++++++++++ 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 tests/nodejs/express/Procfile create mode 100644 tests/nodejs/express/package.json create mode 100644 tests/nodejs/express/web.js rename tests/{run.sh => run_ec2} (72%) create mode 100755 tests/run_vagrant create mode 100755 tests/test_deploy diff --git a/tests/nodejs/express/Procfile b/tests/nodejs/express/Procfile new file mode 100644 index 000000000..ed458e829 --- /dev/null +++ b/tests/nodejs/express/Procfile @@ -0,0 +1 @@ +web: bin/node web.js diff --git a/tests/nodejs/express/package.json b/tests/nodejs/express/package.json new file mode 100644 index 000000000..7bdf8db0c --- /dev/null +++ b/tests/nodejs/express/package.json @@ -0,0 +1,11 @@ +{ + "name": "node-example", + "version": "0.0.1", + "dependencies": { + "express": "2.5.x" + }, + "engines": { + "node": "0.8.x", + "npm": "1.1.x" + } +} \ No newline at end of file diff --git a/tests/nodejs/express/web.js b/tests/nodejs/express/web.js new file mode 100644 index 000000000..66aa53614 --- /dev/null +++ b/tests/nodejs/express/web.js @@ -0,0 +1,12 @@ +var express = require('express'); + +var app = express.createServer(express.logger()); + +app.get('/', function(request, response) { + response.send('nodejs/express'); +}); + +var port = process.env.PORT || 5000; +app.listen(port, function() { + console.log("Listening on " + port); +}); \ No newline at end of file diff --git a/tests/run.sh b/tests/run_ec2 similarity index 72% rename from tests/run.sh rename to tests/run_ec2 index 9248ebac2..7848edf27 100755 --- a/tests/run.sh +++ b/tests/run_ec2 @@ -1,12 +1,18 @@ #!/bin/bash KEYNAME="$1" +indent() { sed "s/^/ /"; } echo "-----> Booting EC2 instance..." -INSTANCE=$(ec2-run-instances -k $1 ami-c90277a0 2>/dev/null | awk '/^INSTANCE/ {print $2}') +start=$(ec2-run-instances -k $1 ami-f3d1bb9a 2>/dev/null) +if [[ $? > 0 ]]; then + echo "$start" + exit +fi +INSTANCE=$(echo "$start" | awk '/^INSTANCE/ {print $2}') terminate() { echo "-----> Terminating $INSTANCE..." ec2-terminate-instances $INSTANCE &>/dev/null && echo " Shutting down" } -#trap "terminate" EXIT +trap "terminate" EXIT sleep 30 status="" while [[ "$status" != "running" ]]; do @@ -20,8 +26,7 @@ while [[ "$status" != "running" ]]; do fi done PUBLIC_IP=$(echo "$info" | awk '{print $14}') -echo "-----> Waiting for SSH on instance..." +echo "-----> Waiting for SSH at $PUBLIC_IP..." sleep 10 echo "-----> Connecting and running boostrap script..." -indent() { sed "s/^/ /"; } -cat ../bootstrap.sh | ssh -o "StrictHostKeyChecking=no" ubuntu@$PUBLIC_IP "HOSTNAME=$PUBLIC_IP sudo bash" 2>/dev/null | indent \ No newline at end of file +cat ../bootstrap.sh | ssh -o "StrictHostKeyChecking=no" ubuntu@$PUBLIC_IP "HOSTNAME=$PUBLIC_IP sudo bash" 2>&1 | indent \ No newline at end of file diff --git a/tests/run_vagrant b/tests/run_vagrant new file mode 100755 index 000000000..eadf3cb4f --- /dev/null +++ b/tests/run_vagrant @@ -0,0 +1,14 @@ +#!/bin/bash +SELF=`which $0` +VAGRANT_SSH_PORT=${$VAGRANT_SSH_PORT:-"2222"} +PUBLIC_KEY=${PUBLIC_KEY:-"~/.ssh/id_rsa.pub"} +indent() { sed "s/^/ /"; } +if [[ ! $(cat ~/.ssh/config 2>/dev/null | grep dokku.me) ]]; then + echo "-----> Configuring SSH to use $VAGRANT_SSH_PORT for dokku.me..." + touch ~/.ssh/config + echo "Host dokku.me" >> ~/.ssh/config + echo " Port $VAGRANT_SSH_PORT" >> ~/.ssh/config +fi +echo "-----> Ensuring Vagrant is running..." +cd "$(dirname $SELF)/.." && vagrant up | indent +cat $PUBLIC_KEY | ssh -o "StrictHostKeyChecking=no" -i ~/.vagrant.d/insecure_private_key vagrant@dokku.me "sudo gitreceive upload-key test" diff --git a/tests/test_deploy b/tests/test_deploy new file mode 100755 index 000000000..4be9b8f09 --- /dev/null +++ b/tests/test_deploy @@ -0,0 +1,21 @@ +#!/bin/bash +# set -e +SELF=`which $0`; APP="$1"; TARGET="$2" +TMP=$(mktemp -d -t $TARGET) +trap "rm -rf $TMP" EXIT +cp -r $(dirname $SELF)/$APP/* $TMP +cd $TMP +git init +git add . +git commit -m 'initial commit' +REPO="test-$RANDOM" +git remote add target git@$TARGET:$REPO +URL_FILE=$(mktemp -t url) +git push target master 2>&1 | while read line; do + echo "$line" + [[ $(echo "$line" | grep $TARGET | grep remote) ]] && echo "$line" | awk '{print $2}' > $URL_FILE +done +set -x +URL=$(<$URL_FILE) +curl -v "$URL:8080" # GAHAHHHHH WHY DOESNT THIS WORK +rm $URL_FILE \ No newline at end of file