forked from coop-cloud/abra
Compare commits
29 Commits
2da26852c6
...
a155fe1967
Author | SHA1 | Date | |
---|---|---|---|
a155fe1967 | |||
af4cb53c4c | |||
6b4a108b90 | |||
5a7fe9971a | |||
9564673a10 | |||
cdb84b67c9 | |||
b32bc018f9 | |||
5767eb0eda | |||
75c5908dcd | |||
d22ed11aab | |||
925cb3fe53 | |||
844a902a0f | |||
b307bb6010 | |||
e02f4d1613 | |||
af0d15ef79 | |||
ee00823027 | |||
7c27b72e35 | |||
af6e4285e8 | |||
7dd32ddd25 | |||
62daf78642 | |||
352215dc83 | |||
29fa607190 | |||
7c541ffdfa | |||
7ccc4b4c08 | |||
ef4df35995 | |||
71a9155042 | |||
2a88491d7c | |||
bf79552204 | |||
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"
|
||||||
)
|
)
|
||||||
@ -582,7 +583,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 {
|
||||||
@ -592,12 +593,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 {
|
||||||
@ -607,27 +608,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1052,15 +1061,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
Block a user