mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
feat: implement 'caddy deploy' command to deploy global service using caddy:latest image
This commit is contained in:
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/docker/cli/cli/streams"
|
||||
"net/netip"
|
||||
"os"
|
||||
"uncloud/internal/cli/client"
|
||||
"uncloud/internal/cli/client/connector"
|
||||
"uncloud/internal/cli/config"
|
||||
@@ -328,3 +330,8 @@ func (cli *CLI) promptResetMachine() error {
|
||||
// TODO: implement resetting the remote machine.
|
||||
return fmt.Errorf("resetting the remote machine is not implemented yet")
|
||||
}
|
||||
|
||||
// ProgressOut returns an output stream for progress writer.
|
||||
func (cli *CLI) ProgressOut() *streams.Out {
|
||||
return streams.NewOut(os.Stdout)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,43 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"uncloud/internal/api"
|
||||
)
|
||||
|
||||
func (cli *Client) DeployCaddy(ctx context.Context, image string) error {
|
||||
return errors.New("not implemented")
|
||||
const CaddyServiceName = "caddy"
|
||||
|
||||
// NewCaddyDeployment creates a new deployment for a Caddy reverse proxy service.
|
||||
// The service is deployed in global mode to all machines in the cluster. If the image is not provided, the latest
|
||||
// version of the official Caddy Docker image is used.
|
||||
func (cli *Client) NewCaddyDeployment(image string) (*Deployment, error) {
|
||||
if image == "" {
|
||||
// TODO: fetch the latest version tag from the Docker Hub registry.
|
||||
image = "caddy:latest"
|
||||
}
|
||||
|
||||
spec := api.ServiceSpec{
|
||||
Container: api.ContainerSpec{
|
||||
Command: []string{"caddy", "run", "-c", "/config/caddy.json", "--watch"},
|
||||
Image: image,
|
||||
Volumes: []string{"/var/lib/uncloud/caddy:/config"},
|
||||
},
|
||||
Mode: api.ServiceModeGlobal,
|
||||
Name: CaddyServiceName,
|
||||
Ports: []api.PortSpec{
|
||||
{
|
||||
PublishedPort: 80,
|
||||
ContainerPort: 80,
|
||||
Protocol: api.ProtocolTCP,
|
||||
Mode: api.PortModeHost,
|
||||
},
|
||||
{
|
||||
PublishedPort: 443,
|
||||
ContainerPort: 443,
|
||||
Protocol: api.ProtocolTCP,
|
||||
Mode: api.PortModeHost,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return cli.NewDeployment(spec, &RollingStrategy{})
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ type Deployment struct {
|
||||
|
||||
type Plan struct {
|
||||
ServiceID string
|
||||
Operation
|
||||
SequenceOperation
|
||||
}
|
||||
|
||||
// NewDeployment creates a new deployment for the given service specification.
|
||||
|
||||
@@ -73,7 +73,6 @@ func (s *RollingStrategy) planGlobal(
|
||||
return plan, fmt.Errorf("list machines: %w", err)
|
||||
}
|
||||
|
||||
seqOp := &SequenceOperation{}
|
||||
// TODO: figure out how to return a warning if there are machines down. Embed the machinesDown in the plan?
|
||||
// WARNING: failed to run a service container on machine '%s' which is Down.
|
||||
var machinesDown []*pb.MachineInfo
|
||||
@@ -89,9 +88,8 @@ func (s *RollingStrategy) planGlobal(
|
||||
if err != nil {
|
||||
return plan, err
|
||||
}
|
||||
seqOp.Operations = append(seqOp.Operations, ops...)
|
||||
plan.SequenceOperation.Operations = append(plan.SequenceOperation.Operations, ops...)
|
||||
}
|
||||
plan.Operation = seqOp
|
||||
|
||||
return plan, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user