feat(dns): update caddy deploy command to create ingress records (stubs for now)

This commit is contained in:
Pavel Sviderski
2025-02-24 20:33:54 +10:00
parent 2d84059d7f
commit 0ea997e826
2 changed files with 56 additions and 30 deletions
+31 -4
View File
@@ -7,6 +7,8 @@ import (
"github.com/charmbracelet/huh"
"github.com/docker/compose/v2/pkg/progress"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"maps"
"slices"
"strings"
@@ -132,9 +134,7 @@ func deploy(ctx context.Context, uncli *cli.CLI, opts deployOptions) error {
} else {
fmt.Printf("%s service is up to date.\n", client.CaddyServiceName)
}
return nil
}
} else {
if svc.ID == "" {
if opts.machine != "" {
fmt.Println("This will run a Caddy container on selected machines.")
@@ -163,12 +163,39 @@ func deploy(ctx context.Context, uncli *cli.CLI, opts deployOptions) error {
return nil
}
return progress.RunWithTitle(ctx, func(ctx context.Context) error {
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()
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)
}
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 {
return fmt.Errorf("update ingress records: %w", err)
}
fmt.Println("DNS records updated successfully:")
for _, r := range records {
fmt.Printf(" %s %s -> %s", r.Name, r.Type, strings.Join(r.Values, ", "))
}
fmt.Println()
return nil
}
func confirm() (bool, error) {
+2 -3
View File
@@ -4,11 +4,10 @@ import (
"fmt"
"github.com/Masterminds/semver"
"github.com/distribution/reference"
"regexp"
"uncloud/internal/api"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"regexp"
"uncloud/internal/api"
)
const (