forked from toolshed/abra
Compare commits
5 Commits
filter-by-
...
plusone_ni
Author | SHA1 | Date | |
---|---|---|---|
06d480ce91 | |||
f96bf9a8ac
|
|||
dcecf32999
|
|||
bc88dac150
|
|||
704c0e9c74
|
61
cli/recipe/diff.go
Normal file
61
cli/recipe/diff.go
Normal file
@ -0,0 +1,61 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// getGitDiffArgs builds the `git diff` invocation args
|
||||
func getGitDiffArgs(repoPath string) []string {
|
||||
return []string{
|
||||
"-C",
|
||||
repoPath,
|
||||
"--no-pager",
|
||||
"-c",
|
||||
"color.diff=always",
|
||||
"diff",
|
||||
}
|
||||
}
|
||||
|
||||
var recipeDiffCommand = cli.Command{
|
||||
Name: "diff",
|
||||
Usage: "Show unstaged changes in recipe config",
|
||||
Description: "Due to limitations in our underlying Git dependency, this command requires /usr/bin/git.",
|
||||
Aliases: []string{"d"},
|
||||
ArgsUsage: "<recipe>",
|
||||
Flags: []cli.Flag{
|
||||
internal.DebugFlag,
|
||||
internal.NoInputFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
BashComplete: autocomplete.RecipeNameComplete,
|
||||
Action: func(c *cli.Context) error {
|
||||
recipeName := c.Args().First()
|
||||
|
||||
if recipeName != "" {
|
||||
internal.ValidateRecipe(c)
|
||||
}
|
||||
|
||||
_, err := exec.LookPath("git")
|
||||
if err != nil {
|
||||
logrus.Fatal("unable to locate 'git' command?")
|
||||
}
|
||||
|
||||
gitDiffArgs := getGitDiffArgs(path.Join(config.RECIPES_DIR, recipeName))
|
||||
diff, err := exec.Command("git", gitDiffArgs...).Output()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Print(string(diff))
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
@ -30,5 +30,7 @@ manner. Abra supports convenient automation for recipe maintainenace, see the
|
||||
recipeSyncCommand,
|
||||
recipeUpgradeCommand,
|
||||
recipeVersionCommand,
|
||||
recipeResetCommand,
|
||||
recipeDiffCommand,
|
||||
},
|
||||
}
|
||||
|
56
cli/recipe/reset.go
Normal file
56
cli/recipe/reset.go
Normal file
@ -0,0 +1,56 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var recipeResetCommand = cli.Command{
|
||||
Name: "reset",
|
||||
Usage: "Remove all unstaged changes from recipe config",
|
||||
Description: "WARNING, this will delete your changes. Be Careful.",
|
||||
Aliases: []string{"rs"},
|
||||
ArgsUsage: "<recipe>",
|
||||
Flags: []cli.Flag{
|
||||
internal.DebugFlag,
|
||||
internal.NoInputFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
BashComplete: autocomplete.RecipeNameComplete,
|
||||
Action: func(c *cli.Context) error {
|
||||
recipeName := c.Args().First()
|
||||
|
||||
if recipeName != "" {
|
||||
internal.ValidateRecipe(c)
|
||||
}
|
||||
|
||||
repoPath := path.Join(config.RECIPES_DIR, recipeName)
|
||||
repo, err := git.PlainOpen(repoPath)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
ref, err := repo.Head()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
worktree, err := repo.Worktree()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
opts := &git.ResetOptions{Commit: ref.Hash(), Mode: git.HardReset}
|
||||
if err := worktree.Reset(opts); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ABRA_VERSION="0.8.0-beta"
|
||||
ABRA_VERSION="0.8.1-beta"
|
||||
ABRA_RELEASE_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$ABRA_VERSION"
|
||||
RC_VERSION="0.8.0-beta"
|
||||
RC_VERSION="0.8.1-beta"
|
||||
RC_VERSION_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$RC_VERSION"
|
||||
|
||||
for arg in "$@"; do
|
||||
@ -82,7 +82,7 @@ function install_abra_release {
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$(tput setaf 3)WARNING: $HOME/.local/bin/ is not in \$PATH! If you want to run abra by just typing "abra" you should add it to your \$PATH! To do that run:$(tput sgr0)"
|
||||
p=$HOME/.local/bin
|
||||
com="echo PATH=\$PATH:$p"
|
||||
com="export PATH=\$PATH:$p"
|
||||
if [[ $SHELL =~ "bash" ]]; then
|
||||
echo "$com >> $HOME/.bashrc"
|
||||
elif [[ $SHELL =~ "fizsh" ]]; then
|
||||
|
@ -35,7 +35,7 @@ setup(){
|
||||
|
||||
run $ABRA app check "$TEST_APP_DOMAIN"
|
||||
assert_success
|
||||
assert_output --partial 'all necessary environment variables defined'
|
||||
refute_output --partial '❌'
|
||||
|
||||
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
|
||||
}
|
||||
@ -111,12 +111,16 @@ setup(){
|
||||
}
|
||||
|
||||
@test "error if missing env var" {
|
||||
run $ABRA app check "$TEST_APP_DOMAIN"
|
||||
assert_success
|
||||
refute_output --partial '❌'
|
||||
|
||||
run bash -c 'echo "NEW_VAR=foo" >> "$ABRA_DIR/recipes/$TEST_RECIPE/.env.sample"'
|
||||
assert_success
|
||||
|
||||
run $ABRA app check "$TEST_APP_DOMAIN" --chaos
|
||||
assert_failure
|
||||
assert_output --partial "NEW_VAR"
|
||||
assert_success
|
||||
assert_output --partial '❌'
|
||||
|
||||
_checkout_recipe
|
||||
}
|
||||
|
@ -321,6 +321,8 @@ teardown(){
|
||||
|
||||
# bats test_tags=slow
|
||||
@test "COMPOSE_FILE with \$COMPOSE_FILE override works" {
|
||||
_reset_recipe
|
||||
|
||||
run sed -i 's/#COMPOSE_FILE="$COMPOSE_FILE:compose.extra_env.yml"/COMPOSE_FILE="$COMPOSE_FILE:compose.extra_env.yml"/g' \
|
||||
"$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
assert_success
|
||||
|
@ -110,10 +110,11 @@ setup(){
|
||||
assert_success
|
||||
assert_output --partial 'test_pass_one'
|
||||
|
||||
run docker -c "$TEST_SERVER" secret ls
|
||||
run bash -c '$ABRA app secret ls $TEST_APP_DOMAIN --machine | \
|
||||
jq -r ".[] | select(.name==\"test_pass_one\") | .version"'
|
||||
assert_success
|
||||
assert_output --regexp ".*_test_pass_one_v2"
|
||||
refute_output --regexp ".*_test_pass_one_v1"
|
||||
assert_output --partial 'v2'
|
||||
refute_output --partial 'v1'
|
||||
|
||||
run $ABRA app secret rm "$TEST_APP_DOMAIN" --all
|
||||
assert_success
|
||||
|
21
tests/integration/recipe_diff.bats
Normal file
21
tests/integration/recipe_diff.bats
Normal file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
setup() {
|
||||
load "$PWD/tests/integration/helpers/common"
|
||||
_common_setup
|
||||
}
|
||||
|
||||
@test "show unstaged changes" {
|
||||
run $ABRA recipe diff "$TEST_RECIPE"
|
||||
assert_success
|
||||
refute_output --partial 'traefik.enable'
|
||||
|
||||
run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml"
|
||||
assert_success
|
||||
|
||||
run $ABRA recipe diff "$TEST_RECIPE"
|
||||
assert_success
|
||||
assert_output --partial 'traefik.enable'
|
||||
|
||||
_reset_recipe
|
||||
}
|
25
tests/integration/recipe_reset.bats
Normal file
25
tests/integration/recipe_reset.bats
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
setup() {
|
||||
load "$PWD/tests/integration/helpers/common"
|
||||
_common_setup
|
||||
}
|
||||
|
||||
@test "reset unstaged changes" {
|
||||
run $ABRA recipe fetch "$TEST_RECIPE"
|
||||
assert_success
|
||||
|
||||
run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml"
|
||||
assert_success
|
||||
|
||||
run $ABRA recipe diff "$TEST_RECIPE"
|
||||
assert_success
|
||||
assert_output --partial 'traefik.enable'
|
||||
|
||||
run $ABRA recipe reset "$TEST_RECIPE"
|
||||
assert_success
|
||||
|
||||
run $ABRA recipe diff "$TEST_RECIPE"
|
||||
assert_success
|
||||
refute_output --partial 'traefik.enable'
|
||||
}
|
Reference in New Issue
Block a user