forked from coop-cloud/abra
Compare commits
8 Commits
7c1a97be72
...
29fa607190
Author | SHA1 | Date |
---|---|---|
decentral1se | 29fa607190 | |
decentral1se | 7c541ffdfa | |
decentral1se | 7ccc4b4c08 | |
decentral1se | ef4df35995 | |
decentral1se | 71a9155042 | |
decentral1se | 2a88491d7c | |
decentral1se | bf79552204 | |
decentral1se | 0a7fa54759 |
|
@ -8,6 +8,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/pkg/client"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/config"
|
||||||
"coopcloud.tech/abra/pkg/dns"
|
"coopcloud.tech/abra/pkg/dns"
|
||||||
"coopcloud.tech/abra/pkg/formatter"
|
"coopcloud.tech/abra/pkg/formatter"
|
||||||
|
@ -16,15 +17,19 @@ import (
|
||||||
"coopcloud.tech/abra/pkg/recipe"
|
"coopcloud.tech/abra/pkg/recipe"
|
||||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
dockerClient "github.com/docker/docker/client"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DeployAction is the main command-line action for this package
|
// DeployAction is the main command-line action for this package
|
||||||
func DeployAction(c *cli.Context, cl *dockerClient.Client) error {
|
func DeployAction(c *cli.Context) error {
|
||||||
app := ValidateApp(c)
|
app := ValidateApp(c)
|
||||||
|
|
||||||
|
cl, err := client.New(app.Server)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if !Chaos {
|
if !Chaos {
|
||||||
if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
|
if err := recipe.EnsureUpToDate(app.Recipe); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
composetypes "github.com/docker/cli/cli/compose/types"
|
composetypes "github.com/docker/cli/cli/compose/types"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
|
gitConfig "github.com/go-git/go-git/v5/config"
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
@ -583,7 +584,7 @@ func EnsureUpToDate(recipeName string) error {
|
||||||
|
|
||||||
isClean, err := gitPkg.IsClean(recipeDir)
|
isClean, err := gitPkg.IsClean(recipeDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to check git clean status in %s: %s", recipeDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isClean {
|
if !isClean {
|
||||||
|
@ -593,12 +594,12 @@ func EnsureUpToDate(recipeName string) error {
|
||||||
|
|
||||||
repo, err := git.PlainOpen(recipeDir)
|
repo, err := git.PlainOpen(recipeDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to open %s: %s", recipeDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
remotes, err := repo.Remotes()
|
remotes, err := repo.Remotes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to read remotes in %s: %s", recipeDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(remotes) == 0 {
|
if len(remotes) == 0 {
|
||||||
|
@ -608,27 +609,35 @@ func EnsureUpToDate(recipeName string) error {
|
||||||
|
|
||||||
worktree, err := repo.Worktree()
|
worktree, err := repo.Worktree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to open git work tree in %s: %s", recipeDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
branch, err := gitPkg.CheckoutDefaultBranch(repo, recipeDir)
|
branch, err := gitPkg.CheckoutDefaultBranch(repo, recipeDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to check out default branch in %s: %s", recipeDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchOpts := &git.FetchOptions{
|
fetchOpts := &git.FetchOptions{
|
||||||
Tags: git.AllTags,
|
Tags: git.AllTags,
|
||||||
|
RefSpecs: []gitConfig.RefSpec{
|
||||||
|
gitConfig.RefSpec(fmt.Sprintf("%s:%s", branch, branch)),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := repo.Fetch(fetchOpts); err != nil {
|
||||||
|
if !strings.Contains(err.Error(), "already up-to-date") {
|
||||||
|
return fmt.Errorf("unable to fetch tags in %s: %s", recipeDir, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
repo.Fetch(fetchOpts)
|
|
||||||
|
|
||||||
opts := &git.PullOptions{
|
opts := &git.PullOptions{
|
||||||
Force: true,
|
Force: true,
|
||||||
ReferenceName: branch,
|
ReferenceName: branch,
|
||||||
|
SingleBranch: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := worktree.Pull(opts); err != nil {
|
if err := worktree.Pull(opts); err != nil {
|
||||||
if !strings.Contains(err.Error(), "already up-to-date") {
|
if !strings.Contains(err.Error(), "already up-to-date") {
|
||||||
return err
|
return fmt.Errorf("unable to git pull in %s: %s", recipeDir, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1053,15 +1062,6 @@ func UpdateRepositories(repos RepoCatalogue, recipeName string) error {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
isClean, err := gitPkg.IsClean(recipeDir)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isClean {
|
|
||||||
logrus.Fatalf("%s has locally unstaged changes", rm.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := EnsureUpToDate(rm.Name); err != nil {
|
if err := EnsureUpToDate(rm.Name); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,8 @@ func Fatal(hostname string, err error) error {
|
||||||
return fmt.Errorf("could not resolve hostname for %s", hostname)
|
return fmt.Errorf("could not resolve hostname for %s", hostname)
|
||||||
} else if strings.Contains(out, "Connection timed out") {
|
} else if strings.Contains(out, "Connection timed out") {
|
||||||
return fmt.Errorf("connection timed out for %s", hostname)
|
return fmt.Errorf("connection timed out for %s", hostname)
|
||||||
|
} else if strings.Contains(out, "Permission denied") {
|
||||||
|
return fmt.Errorf("ssh auth: permission denied for %s", hostname)
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue