Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix revert behavior, add ability to run local tests before a deploy #20

Open
wants to merge 9 commits into from

2 participants

@necaris

Remove trailing newline in the ref fetched from from nth_deploy_commit(), which blocks git reset working properly.

Also, add the ability to run tests locally on the developer's machine before a deploy.

necaris and others added some commits
@necaris necaris Trim trailing newline from `nth_deploy_commit` ref
Reverting deploys would fail at the `git reset` step because the
ref fetched from `nth_deploy_commit` had a trailing newline.
e190c91
@necaris necaris Add ability to run tests locally before deploying
Add a `local_hook()` function to run a local hook command, and a
`local-test` config key to take advantage of this ability.

This is useful in situations where server-side testing infrastructure
is not set up or is not desirable, and local testing before code is
deployed becomes even more critical.
443032d
@necaris necaris Don't run local tests if `--no-tests` is passed d975b0c
@necaris necaris Add a `local-pre-deploy` hook for any local tasks
e.g. bumping a version number in a manifest file
27be40e
@necaris necaris Enable script to update from my fork c6e51d1
@danmactough danmactough Add option to skip strict host key checking.
Useful when the instance backing an Elastic IP has changed.
6d48a4b
@necaris necaris Merge pull request #1 from danmactough/feature/option-strict-host-key…
…-checking

Add option to skip strict host key checking.
5470bcd
@danmactough danmactough Add pre-setup and post-setup hooks 4085c5c
@necaris necaris Merge pull request #2 from danmactough/setup-hooks
Add pre-setup and post-setup hooks
431e6f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 22, 2014
  1. @necaris

    Trim trailing newline from `nth_deploy_commit` ref

    necaris authored
    Reverting deploys would fail at the `git reset` step because the
    ref fetched from `nth_deploy_commit` had a trailing newline.
Commits on Feb 25, 2014
  1. @necaris

    Add ability to run tests locally before deploying

    necaris authored
    Add a `local_hook()` function to run a local hook command, and a
    `local-test` config key to take advantage of this ability.
    
    This is useful in situations where server-side testing infrastructure
    is not set up or is not desirable, and local testing before code is
    deployed becomes even more critical.
Commits on Feb 28, 2014
  1. @necaris
  2. @necaris

    Add a `local-pre-deploy` hook for any local tasks

    necaris authored
    e.g. bumping a version number in a manifest file
Commits on Mar 17, 2014
  1. @necaris
Commits on Sep 30, 2014
  1. @danmactough

    Add option to skip strict host key checking.

    danmactough authored
    Useful when the instance backing an Elastic IP has changed.
  2. @necaris

    Merge pull request #1 from danmactough/feature/option-strict-host-key…

    necaris authored
    …-checking
    
    Add option to skip strict host key checking.
Commits on Mar 19, 2015
  1. @danmactough
Commits on Mar 23, 2015
  1. @necaris

    Merge pull request #2 from danmactough/setup-hooks

    necaris authored
    Add pre-setup and post-setup hooks
This page is out of date. Refresh to see the latest.
Showing with 42 additions and 4 deletions.
  1. +42 −4 bin/deploy
View
46 bin/deploy
@@ -7,10 +7,11 @@
# https://github.com/visionmedia/deploy
#
-VERSION="0.6.0"
+VERSION="0.6.1-necaris"
CONFIG=./deploy.conf
LOG=/tmp/deploy.log
TEST=1
+STRICT_KEYS=1
REF=
ENV=
@@ -28,6 +29,7 @@ usage() {
-C, --chdir <path> change the working directory to <path>
-c, --config <path> set config path. defaults to ./deploy.conf
-T, --no-tests ignore test hook
+ -K, --no-strict-keys skip strict host key checking
-V, --version output program version
-h, --help output help information
@@ -119,7 +121,8 @@ ssh_command() {
test -n "$key" && local identity="-i $key"
test -n "$port" && local port="-p $port"
test -n "$needs_tty" && local tty="-t"
- echo "ssh $tty $agent $port $identity $url"
+ test $STRICT_KEYS -eq 0 && local strict_keys="-o StrictHostKeyChecking=no"
+ echo "ssh $strict_keys $tty $agent $port $identity $url"
}
#
@@ -156,6 +159,26 @@ config() {
}
#
+# Execute hook <name> in the developer's repository, before
+# deploying code to the server
+#
+
+local_hook() {
+ test -n "$1" || abort hook name required
+ local hook=$1
+ local path=`config_get path`
+ local cmd=`config_get $hook`
+ if test -n "$cmd"; then
+ log "executing $hook \`$cmd\` in local repository"
+ ($cmd 2>&1 | tee -a $LOG && exit ${PIPESTATUS})
+ test $? -eq 0
+ else
+ log local_hook $hook
+ fi
+}
+
+
+#
# Execute hook <name> relative to the path configured.
#
@@ -183,6 +206,9 @@ hook() {
setup() {
local path=`config_get path`
local repo=`config_get repo`
+
+ hook pre-setup || abort pre-setup hook failed
+
run "mkdir -p $path/{shared/{logs,pids},source}"
test $? -eq 0 || abort setup paths failed
log running setup
@@ -191,6 +217,9 @@ setup() {
test $? -eq 0 || abort failed to clone
run "ln -sfn $path/source $path/current"
test $? -eq 0 || abort symlink failed
+
+ hook post-setup || abort post-setup hook failed
+
log setup complete
}
@@ -203,6 +232,14 @@ deploy() {
local path=`config_get path`
log deploying
+ if test $TEST -eq 1; then
+ local_hook local-test || abort local tests failed!
+ else
+ log ignoring local tests
+ fi
+
+ # run any local tasks e.g. cache-busting
+ local_hook local-pre-deploy || abort local-pre-deploy failed
hook pre-deploy || abort pre-deploy hook failed
# fetch source
@@ -268,7 +305,7 @@ current_commit() {
nth_deploy_commit() {
local n=$1
local path=`config_get path`
- run "cat $path/.deploys | tail -n $n | head -n 1 | cut -d ' ' -f 1"
+ run "cat $path/.deploys | tail -n $n | head -n 1 | cut -d ' ' -f 1 | tr -d '\n'"
}
#
@@ -328,7 +365,7 @@ check_for_local_changes() {
update() {
log "updating deploy(1)"
rm -fr /tmp/deploy
- git clone git://github.com/visionmedia/deploy.git \
+ git clone git://github.com/necaris/deploy.git \
--depth 0 \
/tmp/deploy \
&> /tmp/deploy.log \
@@ -347,6 +384,7 @@ while test $# -ne 0; do
-c|--config) set_config_path $1; shift ;;
-C|--chdir) log cd $1; cd $1; shift ;;
-T|--no-tests) TEST=0 ;;
+ -K|--no-strict-keys) STRICT_KEYS=0 ;;
run|exec) require_env; run "cd `config_get path`/current && $@"; exit ;;
console) require_env; console; exit ;;
curr|current) require_env; current_commit; exit ;;
Something went wrong with that request. Please try again.