From 83f320ac8e701f0d6aa8734a159f5ee1653ecb2a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 1 Apr 2018 23:13:11 -0400 Subject: [PATCH] feat: add ability to initialize a git repository out of band This is useful in contexts where the repository directory may be created and interacted with via git-http-backend or other methods of updating a repository. --- docs/deployment/methods/git.md | 18 ++++++++++++++++- docs/template.html | 1 + plugins/git/commands | 3 ++- plugins/git/functions | 29 +++++++++++++++++++--------- plugins/git/internal-functions | 27 ++++++++++++++++++++++++++ plugins/git/subcommands/default | 5 +++++ plugins/git/subcommands/initialize | 16 +++++++++++++++ plugins/git/subcommands/set | 2 +- tests/unit/10_git.bats | 31 ++++++++++++++++++++++++++++++ 9 files changed, 120 insertions(+), 12 deletions(-) create mode 100755 plugins/git/subcommands/default create mode 100755 plugins/git/subcommands/initialize diff --git a/docs/deployment/methods/git.md b/docs/deployment/methods/git.md index 001140135..7e9d10721 100644 --- a/docs/deployment/methods/git.md +++ b/docs/deployment/methods/git.md @@ -3,14 +3,30 @@ > Subcommands new as of 0.12.0 ``` +git:initialize # Initialize a git repository for an app git:report [] [] # Displays a git report for one or more apps git:set () # Set or clear a git property for an app ``` -GIT-based deployment has been the traditional method of deploying applications in Dokku. As of v0.12.0, Dokku introduces a few ways to customize the experience of deploying via `git push`. +GIT-based deployment has been the traditional method of deploying applications in Dokku. As of v0.12.0, Dokku introduces a few ways to customize the experience of deploying via `git push`. A GIT-based deployment currently supports building applications via both [Buildpack](/docs/deployment/methods/buildpacks.md) and [Dockerfile](/docs/deployment/methods/dockerfiles.md). ## Usage +### Initializing an Application + +When an application is created via `git push`, Dokku will create the proper `pre-receive` hook in order to execute the build pipeline. In certain cases - such as when fronting deploys with the [`git-http-backend`](https://git-scm.com/docs/git-http-backend) - this may not be correctly created. As an alternative, the `git:initialize` subcommand can be used to trigger this creation: + +```shell +# on the Dokku host + +# overrides any existing pre-receive hook +dokku git:initialize node-js-app +``` + +In order for the above command to succeed, the application _must_ already exist. + +> Warning: If the pre-receive hook was customized in any way, this will overwrite that hook with the current defaults for Dokku. + ### Changing the Deploy Branch By default, Dokku will deploy code pushed to the `master` branch. In order to quickly deploy a different local branch, the following GIT command can be used: diff --git a/docs/template.html b/docs/template.html index 3fe95ec5c..6127425c7 100644 --- a/docs/template.html +++ b/docs/template.html @@ -131,6 +131,7 @@ Buildpack Deployment Dockerfile Deployment Docker Image Deployment + Git Deployment Tarfile Deployment Configuration diff --git a/plugins/git/commands b/plugins/git/commands index 7df19a867..bb9160cc6 100755 --- a/plugins/git/commands +++ b/plugins/git/commands @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/git/functions" +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" case "$1" in git-hook) @@ -16,7 +17,7 @@ case "$1" in ;; help | git:help) - echo -n "" + cmd-git-help "$@" ;; *) diff --git a/plugins/git/functions b/plugins/git/functions index 03545f311..7fef5d1f7 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -211,15 +211,7 @@ git_glob_cmd() { if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then [[ ! -d "$DOKKU_ROOT/$APP" ]] && apps_maybe_create "$APP" - git init --bare "$APP_PATH" > /dev/null - local PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" - cat > "$PRERECEIVE_HOOK" < /dev/null + fi + + cat > "$PRERECEIVE_HOOK" <, Initialize a git repository for an app + git:report [] [], Displays a git report for one or more apps + git:set (), Set or clear a git property for an app +help_content +} + +cmd-git-help() { + if [[ $1 = "git:help" ]] ; then + echo -e 'Usage: dokku git[:COMMAND]' + echo '' + echo 'Manages the git integration for an app.' + echo '' + echo 'Additional commands:' + git_help_content_func | sort | column -c2 -t -s, + echo '' + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + git_help_content_func + else + cat<