From 9f985077c70906fce034c98260a52a5b7ca8c957 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Tue, 27 Jan 2015 15:00:00 -0800 Subject: [PATCH 1/3] implement rebuild command that reuses git_archive_all --- plugins/git/commands | 8 ++++++-- plugins/ps/commands | 18 ++++++++++++++++++ tests/unit/ps.bats | 11 +++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/plugins/git/commands b/plugins/git/commands index ec5a452be..bfe9fff0c 100755 --- a/plugins/git/commands +++ b/plugins/git/commands @@ -6,14 +6,13 @@ git_archive_all() { TMP_WORK_DIR=$(mktemp -d) chmod 755 $TMP_WORK_DIR unset GIT_DIR GIT_WORK_TREE - git clone -q $DOKKU_ROOT/$APP $TMP_WORK_DIR &> /dev/null pushd $TMP_WORK_DIR > /dev/null + git clone -q $DOKKU_ROOT/$APP $TMP_WORK_DIR &> /dev/null git config advice.detachedHead false git checkout $REV &> /dev/null git submodule update --init --recursive &> /dev/null find -name .git -prune -exec rm -rf {} \; > /dev/null tar c . - popd > /dev/null rm -rf $TMP_WORK_DIR > /dev/null } @@ -41,6 +40,11 @@ case "$1" in pluginhook git-post-pull $APP ;; + git-rebuild) + APP="$2"; REF=$(< "$DOKKU_ROOT/$APP/refs/heads/master") + git_archive_all $APP $REF | dokku receive $APP | sed -u "s/^/"$'\e[1G'"/" + ;; + git-*) APP="$(echo $2 | perl -pe 's/(? List processes running in app container(s) ps:start Start app container(s) ps:stop Stop app container(s) + ps:rebuild Rebuild an app + ps:rebuildall Rebuild all apps ps:restart Restart app container(s) ps:restartall Restart all deployed app containers EOF diff --git a/tests/unit/ps.bats b/tests/unit/ps.bats index 53efb0b35..915563a61 100644 --- a/tests/unit/ps.bats +++ b/tests/unit/ps.bats @@ -57,3 +57,14 @@ teardown() { echo "status: "$status assert_success } + +@test "ps:rebuild" { + run bash -c "dokku ps:rebuild $TEST_APP" + echo "output: "$output + echo "status: "$status + assert_success + run bash -c "docker ps -q --no-trunc | grep -q $(< $DOKKU_ROOT/$TEST_APP/CONTAINER)" + echo "output: "$output + echo "status: "$status + assert_success +} From ef369eb02fa907a63ab073c06d9efab7aabb0961 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Tue, 27 Jan 2015 16:33:36 -0800 Subject: [PATCH 2/3] really make circle fail unit tests before trying deploy tests --- circle.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index affa9b308..90468d67f 100644 --- a/circle.yml +++ b/circle.yml @@ -18,9 +18,8 @@ dependencies: - sudo -E make -e setup-deploy-tests post: - sudo -E make -e lint -test: - pre: - sudo -E make -e unit-tests +test: override: ### deploy tests (against buildstep release) #### - sudo -E make -e deploy-tests: { timeout: 1800 } From c96d139f548ab3970ec5d44095f95b1021eccf6e Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 28 Jan 2015 16:18:57 -0800 Subject: [PATCH 3/3] use flock when (re)building/deploying --- plugins/git/commands | 20 +++++++++++++++++--- plugins/ps/commands | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/git/commands b/plugins/git/commands index bfe9fff0c..621c59202 100755 --- a/plugins/git/commands +++ b/plugins/git/commands @@ -25,7 +25,7 @@ case "$1" in # Only run this script for the master branch. You can remove this # if block if you wish to run it for others as well. if [[ $refname = "refs/heads/master" ]] ; then - git_archive_all $APP $newrev | dokku receive $APP | sed -u "s/^/"$'\e[1G'"/" + dokku git-build $APP $newrev else echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to master." echo $'\e[1G\e[K'"-----> for example, try 'git push ${refname/refs\/heads\/}:master'" @@ -40,8 +40,22 @@ case "$1" in pluginhook git-post-pull $APP ;; - git-rebuild) - APP="$2"; REF=$(< "$DOKKU_ROOT/$APP/refs/heads/master") + git-build) + APP="$2"; APP_BUILD_LOCK="$DOKKU_ROOT/$APP/.build.lock" + APP_BUILD_LOCK_MSG="$APP is currently being deployed or locked. Waiting..." + [[ $(flock -n "$APP_BUILD_LOCK" true &>/dev/null ; echo $?) -ne 0 ]] && echo "$APP_BUILD_LOCK_MSG" + + shift 1 + flock -o "$APP_BUILD_LOCK" dokku git-build-locked "$@" + ;; + + git-build-locked) + APP="$2" + if [[ $# -ge 3 ]];then + REF="$3" + else + REF=$(< "$DOKKU_ROOT/$APP/refs/heads/master") + fi git_archive_all $APP $REF | dokku receive $APP | sed -u "s/^/"$'\e[1G'"/" ;; diff --git a/plugins/ps/commands b/plugins/ps/commands index d57539a43..b1f43478e 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -61,7 +61,7 @@ case "$1" in [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2" - dokku git-rebuild $APP + dokku git-build $APP ;; ps:rebuildall)