mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Merge pull request #2587 from dokku/2494-custom-deploy-branch
Allow specifying the deploy branch via DOKKU_DEPLOY_BRANCH
This commit is contained in:
@@ -90,6 +90,18 @@ Dokku supports deploying applications via [Heroku buildpacks](https://devcenter.
|
||||
|
||||
Dokku only supports deploying from its master branch, so if you'd like to deploy a different local branch use: ```git push dokku <local branch>:master```
|
||||
|
||||
An alternative is to use the `DOKKU_DEPLOY_BRANCH` application config value to specify a branch that should be deployed. The implicit default is master, and this can be modified both at the app and global level:
|
||||
|
||||
```shell
|
||||
# on your Dokku host
|
||||
|
||||
# set it globally
|
||||
dokku config:set --global DOKKU_DEPLOY_BRANCH=some-branch
|
||||
|
||||
# override for a specific app
|
||||
dokku config:set ruby-rails-sample DOKKU_DEPLOY_BRANCH=some-branch
|
||||
```
|
||||
|
||||
You can also support pushing multiple branches using the [receive-branch](/dokku/development/plugin-triggers/#receive-branch) plugin trigger in a custom plugin.
|
||||
|
||||
### Skipping deployment
|
||||
|
||||
@@ -55,16 +55,39 @@ suppress_output() {
|
||||
return 0
|
||||
}
|
||||
|
||||
git_deploy_branch() {
|
||||
declare desc="retrieve the deploy branch for a given application"
|
||||
local cmd="git-hook"
|
||||
local APP="$1"
|
||||
|
||||
local DOKKU_DEPLOY_BRANCH="$(config_get "$APP" DOKKU_DEPLOY_BRANCH || true)"
|
||||
local DOKKU_GLOBAL_DEPLOY_BRANCH="$(config_get --global DOKKU_DEPLOY_BRANCH || true)"
|
||||
if [[ -n "$DOKKU_DEPLOY_BRANCH" ]]; then
|
||||
echo "$DOKKU_DEPLOY_BRANCH"
|
||||
elif [[ -n "$DOKKU_GLOBAL_DEPLOY_BRANCH" ]]; then
|
||||
echo "$DOKKU_GLOBAL_DEPLOY_BRANCH"
|
||||
else
|
||||
echo "master"
|
||||
fi
|
||||
}
|
||||
|
||||
git_hook_cmd() {
|
||||
declare desc="kick off receive-app trigger from git prereceive hook"
|
||||
local cmd="git-hook"
|
||||
local APP="$2"
|
||||
local APP="$2"
|
||||
local DOKKU_DEPLOY_BRANCH="$(git_deploy_branch "$APP")"
|
||||
|
||||
if ! git check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" 2> /dev/null; then
|
||||
echo $'\e[1G\e[K'"-----> WARNING: Invalid branch name '$DOKKU_DEPLOY_BRANCH' specified via DOKKU_DEPLOY_BRANCH."
|
||||
echo $'\e[1G\e[K'"-----> For more details, please see the man page for 'git-check-ref-format.'"
|
||||
return
|
||||
fi
|
||||
|
||||
local oldrev newrev refname
|
||||
while read -r oldrev newrev refname; do
|
||||
# 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
|
||||
if [[ $refname = "refs/heads/${DOKKU_DEPLOY_BRANCH}" ]]; then
|
||||
# broken out into plugin so we might support other methods to receive an app
|
||||
# shellcheck disable=SC2086
|
||||
plugn trigger receive-app $APP $newrev
|
||||
|
||||
@@ -145,3 +145,17 @@ teardown() {
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(config) deploy specific DOKKU_DEPLOY_BRANCH" {
|
||||
run ssh dokku@dokku.me config:set --global DOKKU_DEPLOY_BRANCH=global-branch
|
||||
GIT_REMOTE_BRANCH=global-branch deploy_app
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
run ssh dokku@dokku.me config:set $TEST_APP DOKKU_DEPLOY_BRANCH=app-branch
|
||||
GIT_REMOTE_BRANCH=app-branch deploy_app
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
@@ -196,10 +196,11 @@ assert_http_redirect() {
|
||||
}
|
||||
|
||||
deploy_app() {
|
||||
local APP_TYPE="$1"; local APP_TYPE=${APP_TYPE:="nodejs-express"}
|
||||
local GIT_REMOTE="$2"; local GIT_REMOTE=${GIT_REMOTE:="dokku@dokku.me:$TEST_APP"}
|
||||
local CUSTOM_TEMPLATE="$3"; local TMP=$(mktemp -d "/tmp/dokku.me.XXXXX")
|
||||
local CUSTOM_PATH="$4"
|
||||
declare APP_TYPE="$1" GIT_REMOTE="$2" CUSTOM_TEMPLATE="$3" CUSTOM_PATH="$4"
|
||||
local APP_TYPE=${APP_TYPE:="nodejs-express"}
|
||||
local GIT_REMOTE=${GIT_REMOTE:="dokku@dokku.me:$TEST_APP"}
|
||||
local GIT_REMOTE_BRANCH=${GIT_REMOTE_BRANCH:="master"}
|
||||
local TMP=$(mktemp -d "/tmp/dokku.me.XXXXX")
|
||||
|
||||
rmdir "$TMP" && cp -r "./tests/apps/$APP_TYPE" "$TMP"
|
||||
|
||||
@@ -218,7 +219,7 @@ deploy_app() {
|
||||
[[ -f gitignore ]] && mv gitignore .gitignore
|
||||
git add .
|
||||
git commit -m 'initial commit'
|
||||
git push target master || destroy_app $?
|
||||
git push target "master:${GIT_REMOTE_BRANCH}" || destroy_app $?
|
||||
}
|
||||
|
||||
setup_client_repo() {
|
||||
|
||||
Reference in New Issue
Block a user