refactor: combine both clone and sync commands

Using a single command will allow users to not have to worry about the workflow they use to setup or update a given app.
This commit is contained in:
Jose Diaz-Gonzalez committed 2021-01-17 17:00:33 -05:00
1 parent e3d0f693a7
commit 3f25514e1a
6 files changed
+82 -171

No files matched your search

+9 -39
View File
@@ -4,8 +4,7 @@
``` ```
git:allow-host <host> # Adds a host to known_hosts git:allow-host <host> # Adds a host to known_hosts
git:clone [--build] <app> <repository> [<git-ref>] # Creates an app from remote git repo git:sync [--build] <app> <repository> [<git-ref>] # Clone or fetch an app from remote git repo
git:fetch [--build] <app> <repository> [<git-ref>] # Fetch the app at an optional repo object and build the codebase
git:initialize <app> # Initialize a git repository for an app git:initialize <app> # Initialize a git repository for an app
git:public-key # Outputs the dokku public deploy key git:public-key # Outputs the dokku public deploy key
git:report [<app>] [<flag>] # Displays a git report for one or more apps git:report [<app>] [<flag>] # Displays a git report for one or more apps
@@ -114,58 +113,29 @@ dokku git:set node-js-app keep-git-dir ""
> The application must exist before the repository can be initialized > The application must exist before the repository can be initialized
A Dokku app repository can be initialized from a remote git repository via the `git:clone` command. This command should only be used for an initial sync to a remote repository as it may wipe out any local Dokku history that isn't in sync with the remote. Any repository that can be cloned by the `dokku` user can be specified. A Dokku app repository can be initialized or updated from a remote git repository via the `git:sync` command. This command will either clone or fetch updates from a remote repository and has undefined behavior if the history cannot be fast-fowarded to the referenced repository reference. Any repository that can be cloned by the `dokku` user can be specified.
```shell ```shell
dokku git:clone node-js-app https://github.com/heroku/node-js-getting-started.git dokku git:sync node-js-app https://github.com/heroku/node-js-getting-started.git
``` ```
The `git:clone` command optionally takes an optional third parameter containing a git reference, which may be a branch, tag, or specific commit. The `git:sync` command optionally takes an optional third parameter containing a git reference, which may be a branch, tag, or specific commit.
```shell ```shell
# specify a branch # specify a branch
dokku git:clone node-js-app https://github.com/heroku/node-js-getting-started.git main dokku git:sync node-js-app https://github.com/heroku/node-js-getting-started.git main
# specify a tag # specify a tag
dokku git:clone node-js-app https://github.com/heroku/node-js-getting-started.git 1 dokku git:sync node-js-app https://github.com/heroku/node-js-getting-started.git 1
# specify a commit # specify a commit
dokku git:clone node-js-app https://github.com/heroku/node-js-getting-started.git 97e6c72491c7531507bfc5413903e0e00e31e1b0 dokku git:sync node-js-app https://github.com/heroku/node-js-getting-started.git 97e6c72491c7531507bfc5413903e0e00e31e1b0
``` ```
By default, this command does not trigger an application build. To do so during a `git:clone`, specify the `--build` flag. By default, this command does not trigger an application build. To do so during a `git:sync`, specify the `--build` flag.
```shell ```shell
dokku git:clone --build node-js-app https://github.com/heroku/node-js-getting-started.git dokku git:sync --build node-js-app https://github.com/heroku/node-js-getting-started.git
```
### Fetching repository updates from a remote repository
> The application must exist before the repository can be initialized
A Dokku app repository can be updated from a remote git repository via the `git:fetch` command. This command may fail if the specified remote repository cannot be synced from the current Dokku repository state. Any repository that can be cloned by the `dokku` user can be specified.
```shell
dokku git:fetch node-js-app https://github.com/heroku/node-js-getting-started.git
```
The `git:fetch` command optionally takes an optional third parameter containing a git reference, which may be a branch, tag, or specific commit.
```shell
# specify a branch
dokku git:fetch node-js-app https://github.com/heroku/node-js-getting-started.git main
# specify a tag
dokku git:fetch node-js-app https://github.com/heroku/node-js-getting-started.git 1
# specify a commit
dokku git:fetch node-js-app https://github.com/heroku/node-js-getting-started.git 97e6c72491c7531507bfc5413903e0e00e31e1b0
```
By default, this command does not trigger an application build. To do so during a `git:fetch`, specify the `--build` flag.
```shell
dokku git:fetch --build node-js-app https://github.com/heroku/node-js-getting-started.git
``` ```
### Allowing remote repository hosts ### Allowing remote repository hosts
+1 -2
View File
@@ -28,8 +28,7 @@ fn-help-content() {
declare desc="return help content" declare desc="return help content"
cat <<help_content cat <<help_content
git:allow-host <host>, Adds a host to known_hosts git:allow-host <host>, Adds a host to known_hosts
git:clone [--build] <app> <repository> [<git-ref>], Creates an app from remote git repo git:sync [--build] <app> <repository> [<git-ref>], Clone or fetch an app from remote git repo
git:fetch [--build] <app> <repository> [<git-ref>], Fetch the app at an optional repo object and build the codebase
git:initialize <app>, Initialize a git repository for an app git:initialize <app>, Initialize a git repository for an app
git:public-key, Outputs the dokku public deploy key git:public-key, Outputs the dokku public deploy key
git:report [<app>] [<flag>], Displays a git report for one or more apps git:report [<app>] [<flag>], Displays a git report for one or more apps
+8 -39
View File
@@ -15,9 +15,9 @@ cmd-git-allow-host() {
dokku_log_info1 "$HOST added to known hosts" dokku_log_info1 "$HOST added to known hosts"
} }
cmd-git-clone() { cmd-git-sync() {
declare desc="creates an app from remote git repo" declare desc="clone or fetch an app from remote git repo"
local cmd="git:clone" local cmd="git:sync"
[[ "$1" == "$cmd" ]] && shift 1 [[ "$1" == "$cmd" ]] && shift 1
declare APP GIT_REMOTE GIT_REF FLAG declare APP GIT_REMOTE GIT_REF FLAG
@@ -42,44 +42,13 @@ cmd-git-clone() {
return return
fi fi
fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF" local APP_ROOT="$DOKKU_ROOT/$APP"
if [[ "$FLAG" == "--build" ]]; then if [[ "$(git -C "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then
if [[ -n "$GIT_REF" ]]; then fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF"
plugn trigger receive-app "$APP" "$GIT_REF" else
else fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF"
plugn trigger receive-app "$APP"
fi
fi
}
cmd-git-fetch() {
declare desc="fetch the app at an optional repo object and build the codebase"
local cmd="git:fetch"
[[ "$1" == "$cmd" ]] && shift 1
declare APP GIT_REMOTE GIT_REF FLAG
ARGS=()
for arg in "$@"; do
if [[ "$arg" == "--build" ]]; then
FLAG="--build"
continue
fi
ARGS+=("$arg")
done
APP="${ARGS[0]}"
GIT_REMOTE="${ARGS[1]}"
GIT_REF="${ARGS[2]}"
verify_app_name "$APP"
if [[ -z "$GIT_REMOTE" ]]; then
dokku_log_fail "Missing GIT_REMOTE parameter"
return
fi fi
fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF"
if [[ "$FLAG" == "--build" ]]; then if [[ "$FLAG" == "--build" ]]; then
if [[ -n "$GIT_REF" ]]; then if [[ -n "$GIT_REF" ]]; then
plugn trigger receive-app "$APP" "$GIT_REF" plugn trigger receive-app "$APP" "$GIT_REF"
-6
View File
@@ -1,6 +0,0 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/git/internal-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-git-fetch "$@"
@@ -3,4 +3,4 @@ source "$PLUGIN_AVAILABLE_PATH/git/internal-functions"
set -eo pipefail set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x [[ $DOKKU_TRACE ]] && set -x
cmd-git-clone "$@" cmd-git-sync "$@"
+63 -84
View File
@@ -60,13 +60,13 @@ teardown() {
assert_equal "$output" "$((start_lines + 2))" assert_equal "$output" "$((start_lines + 2))"
} }
@test "(git) git:clone [errors]" { @test "(git) git:sync new [errors]" {
run /bin/bash -c "dokku git:clone" run /bin/bash -c "dokku git:sync"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
run /bin/bash -c "dokku git:clone $TEST_APP-non-existent" run /bin/bash -c "dokku git:sync $TEST_APP-non-existent"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
@@ -76,7 +76,7 @@ teardown() {
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:clone $TEST_APP-non-existent" run /bin/bash -c "dokku git:sync $TEST_APP-non-existent"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
@@ -87,94 +87,73 @@ teardown() {
assert_success assert_success
} }
@test "(git) git:clone [--no-build noarg]" { @test "(git) git:sync new [--no-build noarg]" {
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git"
echo "output: $output"
echo "status: $status"
assert_success
run destroy_app
echo "output: $output"
echo "status: $status"
assert_success
run create_app
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch"
echo "output: $output"
echo "status: $status"
assert_success
run destroy_app
echo "output: $output"
echo "status: $status"
assert_success
run create_app
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output"
echo "status: $status"
assert_success
run destroy_app
echo "output: $output"
echo "status: $status"
assert_success
run create_app
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
} }
@test "(git) git:clone [--build noarg]" { @test "(git) git:sync new [--no-build branch]" {
run /bin/bash -c "dokku git:clone --build $TEST_APP https://github.com/dokku/smoke-test-app.git" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(git) git:sync new [--no-build tag]" {
run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(git) git:sync new [--no-build commit]" {
run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(git) git:sync new [--build noarg]" {
run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
assert_output_contains "Application deployed" assert_output_contains "Application deployed"
} }
@test "(git) git:clone [--build branch]" { @test "(git) git:sync new [--build branch]" {
run /bin/bash -c "dokku git:clone --build $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch" run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
assert_output_contains "Application deployed" assert_output_contains "Application deployed"
} }
@test "(git) git:clone [--build tag]" { @test "(git) git:sync new [--build tag]" {
run /bin/bash -c "dokku git:clone --build $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
assert_output_contains "Application deployed" assert_output_contains "Application deployed"
} }
@test "(git) git:clone [--build commit]" { @test "(git) git:sync new [--build commit]" {
run /bin/bash -c "dokku git:clone --build $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9" run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
assert_output_contains "Application deployed" assert_output_contains "Application deployed"
} }
@test "(git) git:fetch [errors]" { @test "(git) git:sync existing [errors]" {
run /bin/bash -c "dokku git:fetch" run /bin/bash -c "dokku git:sync"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
run /bin/bash -c "dokku git:fetch $TEST_APP-non-existent" run /bin/bash -c "dokku git:sync $TEST_APP-non-existent"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
@@ -184,7 +163,7 @@ teardown() {
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:fetch $TEST_APP-non-existent" run /bin/bash -c "dokku git:sync $TEST_APP-non-existent"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
@@ -195,100 +174,100 @@ teardown() {
assert_success assert_success
} }
@test "(git) git:fetch [--no-build noarg]" { @test "(git) git:sync existing [--no-build noarg]" {
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:fetch $TEST_APP https://github.com/dokku/smoke-test-app.git" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
} }
@test "(git) git:fetch [--no-build branch]" { @test "(git) git:sync existing [--no-build branch]" {
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:fetch $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
} }
@test "(git) git:fetch [--no-build tag]" { @test "(git) git:sync existing [--no-build tag]" {
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:fetch $TEST_APP https://github.com/dokku/smoke-test-app.git 2.0.0" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 2.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
} }
@test "(git) git:fetch [--no-build commit]" { @test "(git) git:sync existing [--no-build commit]" {
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:fetch $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
} }
@test "(git) git:fetch [--build noarg]" { @test "(git) git:sync existing [--build noarg]" {
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:fetch --build $TEST_APP https://github.com/dokku/smoke-test-app.git" run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
assert_output_contains "Application deployed" assert_output_contains "Application deployed"
} }
@test "(git) git:fetch [--build branch]" { @test "(git) git:sync existing [--build branch]" {
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 2.0.0" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 2.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:fetch --build $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch" run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git another-branch"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
assert_output_contains "Application deployed" assert_output_contains "Application deployed"
} }
@test "(git) git:fetch [--build tag]" { @test "(git) git:sync existing [--build tag]" {
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:fetch --build $TEST_APP https://github.com/dokku/smoke-test-app.git 2.0.0" run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git 2.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
assert_output_contains "Application deployed" assert_output_contains "Application deployed"
} }
@test "(git) git:fetch [--build commit]" { @test "(git) git:sync existing [--build commit]" {
run /bin/bash -c "dokku git:clone $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0" run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app.git 1.0.0"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:fetch --build $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9" run /bin/bash -c "dokku git:sync --build $TEST_APP https://github.com/dokku/smoke-test-app.git 5c8a5e42bbd7fae98bd657fb17f41c6019b303f9"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success