mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
feat(dns): update caddy deploy command to create ingress records (stubs for now)
This commit is contained in:
+54
-27
@@ -7,6 +7,8 @@ import (
|
|||||||
"github.com/charmbracelet/huh"
|
"github.com/charmbracelet/huh"
|
||||||
"github.com/docker/compose/v2/pkg/progress"
|
"github.com/docker/compose/v2/pkg/progress"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
"maps"
|
"maps"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -132,43 +134,68 @@ func deploy(ctx context.Context, uncli *cli.CLI, opts deployOptions) error {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s service is up to date.\n", client.CaddyServiceName)
|
fmt.Printf("%s service is up to date.\n", client.CaddyServiceName)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if svc.ID == "" {
|
|
||||||
if opts.machine != "" {
|
|
||||||
fmt.Println("This will run a Caddy container on selected machines.")
|
|
||||||
} else {
|
|
||||||
fmt.Println("This will run a Caddy container on each machine.")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if opts.machine != "" {
|
if svc.ID == "" {
|
||||||
fmt.Println("This will perform a rolling update of Caddy containers on selected machines.")
|
if opts.machine != "" {
|
||||||
|
fmt.Println("This will run a Caddy container on selected machines.")
|
||||||
|
} else {
|
||||||
|
fmt.Println("This will run a Caddy container on each machine.")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("This will perform a rolling update of Caddy containers on each machine.")
|
if opts.machine != "" {
|
||||||
|
fmt.Println("This will perform a rolling update of Caddy containers on selected machines.")
|
||||||
|
} else {
|
||||||
|
fmt.Println("This will perform a rolling update of Caddy containers on each machine.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Println("Deployment plan:")
|
||||||
|
fmt.Println(plan.Format(resolver))
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
confirmed, err := confirm()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("confirm deployment: %w", err)
|
||||||
|
}
|
||||||
|
if !confirmed {
|
||||||
|
fmt.Println("Cancelled. No changes were made.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
||||||
|
if _, err = d.Run(ctx); err != nil {
|
||||||
|
return fmt.Errorf("deploy caddy: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, uncli.ProgressOut(), fmt.Sprintf("Deploying service %s (%s mode)", d.Spec.Name, d.Spec.Mode))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
fmt.Println("Deployment plan:")
|
|
||||||
fmt.Println(plan.Format(resolver))
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
if _, err = clusterClient.GetDomain(ctx, nil); err != nil {
|
||||||
|
if status.Convert(err).Code() == codes.NotFound {
|
||||||
|
fmt.Println("Skipping DNS records update as no cluster domain is reserved (see 'uc dns').")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("get cluster domain: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
confirmed, err := confirm()
|
fmt.Println("Updating cluster domain records in Uncloud DNS to point to machines running caddy containers...")
|
||||||
|
records, err := clusterClient.CreateIngressRecords(ctx, client.CaddyServiceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("confirm deployment: %w", err)
|
return fmt.Errorf("update ingress records: %w", err)
|
||||||
}
|
|
||||||
if !confirmed {
|
|
||||||
fmt.Println("Cancelled. No changes were made.")
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
|
fmt.Println("DNS records updated successfully:")
|
||||||
if _, err = d.Run(ctx); err != nil {
|
for _, r := range records {
|
||||||
return fmt.Errorf("deploy caddy: %w", err)
|
fmt.Printf(" %s %s -> %s", r.Name, r.Type, strings.Join(r.Values, ", "))
|
||||||
}
|
}
|
||||||
return nil
|
fmt.Println()
|
||||||
}, uncli.ProgressOut(), fmt.Sprintf("Deploying service %s (%s mode)", d.Spec.Name, d.Spec.Mode))
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func confirm() (bool, error) {
|
func confirm() (bool, error) {
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"regexp"
|
|
||||||
"uncloud/internal/api"
|
|
||||||
|
|
||||||
"github.com/google/go-containerregistry/pkg/name"
|
"github.com/google/go-containerregistry/pkg/name"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||||
|
"regexp"
|
||||||
|
"uncloud/internal/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Reference in New Issue
Block a user