Permalink
Browse files

Deploy Works

Foreman Works
Names are a bit more sane
  • Loading branch information...
1 parent 7357a4e commit ec40557f26008a1dc97d3c1863aa072731666378 Eric Fode committed Dec 11, 2012
Showing with 72 additions and 40 deletions.
  1. +1 −1 .profile
  2. +0 −1 .slugignore
  3. +37 −0 deploy.sh
  4. +2 −11 env.sample
  5. +23 −23 lib/ferret.rb
  6. +5 −0 setup_client.sh
  7. +4 −4 tests/http_recurl
View
@@ -1,5 +1,4 @@
#!/bin/bash
-export APP=$APP_PREFIX
[ -n "$APP" ] || { echo "error: APP required"; exit 1; }
[ -n "$HEROKU_API_KEY" ] || { echo "error: HEROKU_API_KEY required"; exit 1; }
@@ -18,3 +17,4 @@ if [ ! -f $HOME/.ssh/id_rsa ]; then
heroku keys:add --app $APP
heroku config:set --app $APP SSH_PRIVATE_KEY="$(< $HOME/.ssh/id_rsa)" SSH_PUBLIC_KEY="$(< $HOME/.ssh/id_rsa.pub)"
fi
+
View
@@ -1,2 +1 @@
-app/
tmp/
View
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+L2MET_URL=https://drain.l2met.net/consumers/6f65d7cc-5443-4a99-9545-8bec7a301941/logs
+TARGET_APP_PATH=$1
+APP=$(whoami)
+ORG=ferret-dev
+UNPRIVILEGED_USER=heroku.ferret.dev@gmail.com
+TARGET_APP_NAME=$(echo $TARGET_APP_PATH | sed 's:[/._]:-:g')
+APP=$APP-$TARGET_APP_NAME
+echo "Setting up ${TARGET_APP_NAME} from path ${TARGET_APP_PATH}"
+echo "Cleaning Procfile"
+#cleanup procfile so that we can make the target app the tester proc
+rm Procfile
+touch Procfile
+echo "tester: ${TARGET_APP_PATH}" >> Procfile
+
+echo "Getting unprivileged api key from ${UNPRIVILEGED_USER}"
+#someday we get to use oauth tokens instead of this hack
+UNPRIVILEGED_HEROKU_API_KEY=$(heroku sudo user:info -x \
+ --user ${UNPRIVILEGED_USER} \
+ | awk '/Api Key:/ {print $3;}' \
+ | head -1)
+echo "Cleaning up old deploy of $APP"
+
+heroku sudo --user ${UNPRIVILEGED_USER} apps:delete $APP --confirm $APP
+
+
+heroku apps:create $APP
+heroku manager:transfer --to $ORG --app ${APP}
+heroku config:set --app ${APP} \
+ APP=$APP \
+ HEROKU_API_KEY=$UNPRIVILEGED_HEROKU_API_KEY \
+ APP_PREFIX=ferret-$(whoami) \
+ ORG=$ORG
+heroku build -b https://github.com/nzoschke/buildpack-ferret.git -r $APP
+heroku scale tester=1 --app ${APP}
+heroku drains:add --app ${APP} ${L2MET_URL}
View
@@ -1,11 +1,2 @@
-APP_PREFIX=ferret-dev
-GMAIL_USER=heroku.ferret.dev@gmail.com
-ORG=ferret-dev
-L2MET_URL=https://drain.l2met.net/consumers/<uuid>/logs
-
-
-ORG=ferret-dev
-FERRET_USER=fode
-FERRET_ACCOUNT
-APP=ferret-dev-fode
-L2MET_URL=https://drain.l2met.net/consumers/6f65d7cc-5443-4a99-9545-8bec7a301941/logs
+APP_PREFIX=ferret-fode
+ORG=ferret-dev
View
@@ -4,17 +4,18 @@
require "tmpdir"
ENV["FERRET_DIR"] ||= File.expand_path(File.join(__FILE__, "..", ".."))
-ENV["ORG"] ||= "ferret"
+ENV["ORG"] ||= "ferret-dev"
ENV["NAME"] ||= File.basename($0, File.extname($0)) # e.g. git_push
-ENV["TARGET"] ||= "#{ENV["APP"]}.#{ENV["NAME"]}" # e.g. ferret-noah.git-push
-ENV["TARGET_APP"] ||= ENV["TARGET"].gsub(/[\._]/, '-') # e.g. ferret-noah-git-push
+ENV["SERVICE_LOG_NAME"] ||= "#{ENV["APP_PREFIX"]}.#{ENV["NAME"]}" # e.g. ferret-noah.git-push #slave app name
+ENV["SERVICE_APP_NAME"] ||= ENV["SERVICE_LOG_NAME"].gsub(/[\._]/, '-') # e.g. ferret-noah-git-push #used for deploying slave app
ENV["TEMP_DIR"] ||= Dir.mktmpdir
ENV["XID"] ||= SecureRandom.hex(4)
ENV["FREQ"] ||= "10"
-$log_prefix ||= { app: ENV["TARGET"], xid: ENV["XID"] }
+$log_prefix ||= { app: ENV["SERVICE_LOG_NAME"], xid: ENV["XID"] }
$logdevs ||= [$stdout, IO.popen("logger", "w")]
$threads = []
$lock = Mutex.new
+
trap("EXIT") do
log fn: :exit
pids = $logdevs.map { |logdev| logdev.pid }.compact
@@ -28,30 +29,31 @@ def rmerge!(h)
end
end
-def run(time)
- if time == :forever
+def run(opts={})
+ puts opts.inspect
+ if opts[:forever]
$threads.each(&:join)
else
#should be
#sleep time
#but for some reason this code path is being hit even when forever is passed
- $threads.each(&:join)
+ sleep opts[:time]
end
end
def uses_app(path)
ENV["APP_DIR"] = path
bash(retry: 2, name: :setup, stdin: <<-'EOSTDIN')
- heroku info --app $TARGET_APP || {
- heroku create $TARGET_APP \
- && heroku plugins:install https://github.com/heroku/manager-cli.git \
- && heroku manager:transfer --app $TARGET_APP --to $ORG \
- && cd $APP_DIR \
- && bundle install \
- && heroku build -r $TARGET_APP $APP_DIR \
- && heroku scale web=1 --app $TARGET_APP \
- && cd $FERRET_DIR
- }
+ heroku apps:delete $SERVICE_APP_NAME --confirm $SERVICE_APP_NAME
+ heroku apps:create $SERVICE_APP_NAME \
+ && heroku plugins:install https://github.com/heroku/manager-cli.git \
+ && heroku manager:transfer --app $SERVICE_APP_NAME --to $ORG \
+ && cd $APP_DIR \
+ && bundle install \
+ && heroku build -r $SERVICE_APP_NAME \
+ && heroku scale web=1 --app $SERVICE_APP_NAME \
+ && cd $FERRET_DIR
+
EOSTDIN
#if setup has been defined use that
#otherwise run basic deploy
@@ -63,7 +65,7 @@ def run_interval(interval, &block)
$lock.synchronize {
block.call
}
- sleep interval * Integer(ENV["FREQ"])
+ sleep interval * 10
}
end
end
@@ -74,7 +76,7 @@ def run_every_time(&block)
$lock.synchronize {
block.call
}
- sleep Integer(ENV["FREQ"])
+ sleep 10
}
end
end
@@ -102,7 +104,7 @@ def bash(opts={})
status = $?.exitstatus
out = r1.read
-
+ puts out
success = true
success &&= status == opts[:status] if opts[:status]
success &&= !!(out =~ opts[:pattern]) if opts[:pattern]
@@ -113,7 +115,7 @@ def bash(opts={})
log source: "#{ENV["NAME"]}.#{opts[:name]}", app: ENV["APP"], i: i, at: :return, val: Time.now - start, measure: "time"
return success # break out of retry loop
else
- out.each_line { |l| log source: "#{ENV["NAME"]}.#{opts[:name]}", i: i, at: :failure, out: "'#{l.strip}'" }
+ out.each_line { |l| log source: "#{ENV["NAME"]}.#{opts[:name]}",app: ENV["APP"], i: i, at: :failure, out: "'#{l.strip}'" }
# only measure last failure
if i == opts[:retry] - 1
log source: "#{ENV["NAME"]}.#{opts[:name]}", app: ENV["APP"], i: i, status: status, measure: "failure"
@@ -124,8 +126,6 @@ def bash(opts={})
log source: "#{ENV["NAME"]}.#{opts[:name]}", app: ENV["APP"], i: i, at: :return, val: Time.now - start
end
end
-
- exit(1)
end
rescue Timeout::Error
log source: "#{ENV["NAME"]}.#{opts[:name]}", app: ENV["APP"],at: :timeout, val: opts[:timeout]
View
@@ -0,0 +1,5 @@
+# client and account pre-reqs
+cp env.sample .env
+heroku plugins:install https://github.com/heroku/manager-cli.git
+heroku plugins:install https://github.com/ddollar/heroku-anvil.git
+heroku sudo passes:add logplex-beta-program
View
@@ -1,12 +1,12 @@
#!/usr/bin/env ruby
require_relative "../lib/ferret"
-uses_app "../app/basic_http"
+uses_app ENV["FERRET_DIR"] + "/app/basic_http"
run_interval 10 do
bash(name: :consider_restart, timeout:50,stdin: <<-'EESTD')
- heroku restart --app $TARGET_APP
+ heroku restart --app $SERVICE_APP_NAME
EESTD
end
@@ -15,10 +15,10 @@ end
run_every_time do
bash(name: :poll, timeout: 3900, stdin: <<-'EOSH')
set -x
- res=$( curl -w %{http_code} -s --output /dev/null http://${TARGET_APP}.herokuapp.com)
+ res=$( curl -w %{http_code} -s --output /dev/null http://${SERVICE_APP_NAME}.herokuapp.com)
[ $res == "200" ]
EOSH
end
-run time: :forever
+run forever: true

0 comments on commit ec40557

Please sign in to comment.