Merge branch 'main' of ssh://git.coopcloud.tech:2222/coop-cloud/go-abra into dev

This commit is contained in:
knoflook 2021-08-05 18:57:32 +02:00
commit d7a8e8b2e1
Signed by: knoflook
GPG Key ID: D6A1D0E8FC4FEF1C
2 changed files with 55 additions and 9 deletions

View File

@ -149,6 +149,38 @@ var recipeCreateCommand = &cli.Command{
},
}
var recipeReleaseCommand = &cli.Command{
Name: "release",
Usage: "Release a new recipe version",
ArgsUsage: "<recipe>",
Action: func(c *cli.Context) error {
recipe := c.Args().First()
if recipe == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
}
//TODO: read all local tags and read all upstream tags
// and then ask which you'd like to upgrade to
// ensure that this release isn't in local or upstream already
// after each choice, make change and show diff
//TODO: read the apps catalogue and read the latest version of the recipe
// read the latest local tag of the recipe
// if there are no new changes, and upstream/local point to same commit, there is nothing to update, bail
// if there are changes and the commit they both point to is different, then this is a new release
// figure out the new version
// if the catalogue latest and the local latest are the same, N+1 release
// otherwise, use the local latest tag as the new version
// apply that version to all labels and show diff
//TODO: offer to commit all the things
// offer to make a git tag for that with the new version
// offer to git push that upstream
return nil
},
}
var recipeLintCommand = &cli.Command{
Name: "lint",
Usage: "Recipe configuration linter",
@ -253,6 +285,7 @@ how reliable this app is to deploy and maintain in its current state.
recipeListCommand,
recipeVersionCommand,
recipeCreateCommand,
recipeReleaseCommand,
recipeLintCommand,
},
}

View File

@ -5,11 +5,13 @@ import (
"errors"
"fmt"
"net"
"time"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/client"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
@ -36,20 +38,31 @@ later for more advanced use cases.
return err
}
var ipv4 net.IP
ips, _ := net.LookupIP(host)
for _, ip := range ips {
ipv4 = ip.To4()
}
if string(ipv4) == "" {
return fmt.Errorf("unable to retrieve ipv4 address for %s", host)
resolver := &net.Resolver{
PreferGo: false,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10000),
}
// comrade librehosters DNS resolver https://snopyta.org/service/dns/
return d.DialContext(ctx, "udp", "95.216.24.230:53")
},
}
ctx := context.Background()
ips, err := resolver.LookupIPAddr(ctx, host)
if err != nil {
logrus.Fatal(err)
}
if len(ips) == 0 {
return fmt.Errorf("unable to retrieve ipv4 address for %s", host)
}
ipv4 := ips[0].IP.To4().String()
initReq := swarm.InitRequest{
ListenAddr: "0.0.0.0:2377",
AdvertiseAddr: string(ipv4),
AdvertiseAddr: ipv4,
}
if _, err := cl.SwarmInit(ctx, initReq); err != nil {
return err