Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate manifest deploy to remote builder #3862

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/superfly/fly-go v0.1.26
github.com/superfly/fly-go v0.1.28-0.20240826092218-a776f16963c3
github.com/superfly/graphql v0.2.4
github.com/superfly/lfsc-go v0.1.1
github.com/superfly/macaroon v0.2.14-0.20240702184853-b8ac52a1fc77
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/superfly/fly-go v0.1.26 h1:X0d6aeNNCQAyHgOigbIqTwloBRXJEW5pRFjwT53GY4g=
github.com/superfly/fly-go v0.1.26/go.mod h1:JQke/BwoZqrWurqYkypSlcSo7bIUgCI3eVnqMC6AUj0=
github.com/superfly/fly-go v0.1.28-0.20240826092218-a776f16963c3 h1:/Ynr9pIsvjhvzSGGc0UKHj1+ZNtzFmhgCE78zwVKu7Y=
github.com/superfly/fly-go v0.1.28-0.20240826092218-a776f16963c3/go.mod h1:JQke/BwoZqrWurqYkypSlcSo7bIUgCI3eVnqMC6AUj0=
github.com/superfly/graphql v0.2.4 h1:Av8hSk4x8WvKJ6MTnEwrLknSVSGPc7DWpgT3z/kt3PU=
github.com/superfly/graphql v0.2.4/go.mod h1:CVfDl31srm8HnJ9udwLu6hFNUW/P6GUM2dKcG1YQ8jc=
github.com/superfly/lfsc-go v0.1.1 h1:dGjLgt81D09cG+aR9lJZIdmonjZSR5zYCi7s54+ZU2Q=
Expand Down
19 changes: 19 additions & 0 deletions internal/command/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ func New() *Command {
Description: "Path to a deploy manifest file to use for deployment.",
Hidden: true,
},
flag.Bool{
Name: "delegate",
Description: "Delegate deployment to a remote deployer",
Hidden: true,
},
flag.Bool{
Name: "watch",
Description: "Watch the delegated remote deployment instead of exiting immediately",
Default: false,
Hidden: true,
},
)

return cmd
Expand Down Expand Up @@ -612,6 +623,14 @@ func deployToMachines(
return nil
}

if flag.GetBool(ctx, "delegate") {
// create a manifest and deploy it to a remote deployer
fmt.Fprintln(io.Out, "Generating deploy manifest...")
manifest := NewManifest(app.Name, cfg, args)

return deployRemotely(ctx, manifest)
}

md, err := NewMachineDeployment(ctx, args)
if err != nil {
sentry.CaptureExceptionWithAppInfo(ctx, err, "deploy", app)
Expand Down
60 changes: 32 additions & 28 deletions internal/command/deploy/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,41 @@ type MachineDeploymentArgs struct {
RestartMaxRetries int
DeployRetries int
BuildID string
FromManifestID *string
}

func argsFromManifest(manifest *DeployManifest, app *fly.AppCompact) MachineDeploymentArgs {
return MachineDeploymentArgs{
AppCompact: app,
DeploymentImage: manifest.DeploymentImage,
Strategy: manifest.Strategy,
EnvFromFlags: manifest.EnvFromFlags,
PrimaryRegionFlag: manifest.PrimaryRegionFlag,
SkipSmokeChecks: manifest.SkipSmokeChecks,
SkipHealthChecks: manifest.SkipHealthChecks,
SkipDNSChecks: manifest.SkipDNSChecks,
SkipReleaseCommand: manifest.SkipReleaseCommand,
MaxUnavailable: manifest.MaxUnavailable,
RestartOnly: manifest.RestartOnly,
WaitTimeout: manifest.WaitTimeout,
StopSignal: manifest.StopSignal,
LeaseTimeout: manifest.LeaseTimeout,
ReleaseCmdTimeout: manifest.ReleaseCmdTimeout,
Guest: manifest.Guest,
IncreasedAvailability: manifest.IncreasedAvailability,
UpdateOnly: manifest.UpdateOnly,
Files: manifest.Files,
ExcludeRegions: manifest.ExcludeRegions,
OnlyRegions: manifest.OnlyRegions,
ExcludeMachines: manifest.ExcludeMachines,
OnlyMachines: manifest.OnlyMachines,
ProcessGroups: manifest.ProcessGroups,
MaxConcurrent: manifest.MaxConcurrent,
VolumeInitialSize: manifest.VolumeInitialSize,
RestartPolicy: manifest.RestartPolicy,
RestartMaxRetries: manifest.RestartMaxRetries,
DeployRetries: manifest.DeployRetries,
DeploymentImage: manifest.Args.DeploymentImage,
Strategy: manifest.Args.Strategy,
EnvFromFlags: manifest.Args.EnvFromFlags,
PrimaryRegionFlag: manifest.Args.PrimaryRegionFlag,
SkipSmokeChecks: manifest.Args.SkipSmokeChecks,
SkipHealthChecks: manifest.Args.SkipHealthChecks,
SkipDNSChecks: manifest.Args.SkipDNSChecks,
SkipReleaseCommand: manifest.Args.SkipReleaseCommand,
MaxUnavailable: manifest.Args.MaxUnavailable,
RestartOnly: manifest.Args.RestartOnly,
WaitTimeout: manifest.Args.WaitTimeout,
StopSignal: manifest.Args.StopSignal,
LeaseTimeout: manifest.Args.LeaseTimeout,
ReleaseCmdTimeout: manifest.Args.ReleaseCmdTimeout,
Guest: manifest.Args.Guest,
IncreasedAvailability: manifest.Args.IncreasedAvailability,
UpdateOnly: manifest.Args.UpdateOnly,
Files: manifest.Args.Files,
ExcludeRegions: manifest.Args.ExcludeRegions,
OnlyRegions: manifest.Args.OnlyRegions,
ExcludeMachines: manifest.Args.ExcludeMachines,
OnlyMachines: manifest.Args.OnlyMachines,
ProcessGroups: manifest.Args.ProcessGroups,
MaxConcurrent: manifest.Args.MaxConcurrent,
VolumeInitialSize: manifest.Args.VolumeInitialSize,
RestartPolicy: manifest.Args.RestartPolicy,
RestartMaxRetries: manifest.Args.RestartMaxRetries,
DeployRetries: manifest.Args.DeployRetries,
FromManifestID: fly.StringPointer(manifest.ID),
}
}

Expand Down Expand Up @@ -150,6 +152,7 @@ type machineDeployment struct {
volumeInitialSize int
deployRetries int
buildID string
FromManifestID *string
}

func NewMachineDeployment(ctx context.Context, args MachineDeploymentArgs) (_ MachineDeployment, err error) {
Expand Down Expand Up @@ -277,6 +280,7 @@ func NewMachineDeployment(ctx context.Context, args MachineDeploymentArgs) (_ Ma
processGroups: args.ProcessGroups,
deployRetries: args.DeployRetries,
buildID: args.BuildID,
FromManifestID: args.FromManifestID,
}
if err := md.setStrategy(); err != nil {
tracing.RecordError(span, err, "failed to set strategy")
Expand Down
1 change: 1 addition & 0 deletions internal/command/deploy/machines_deploymachinesapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (md *machineDeployment) DeployMachinesApp(ctx context.Context) error {

var status string
metadata := &fly.ReleaseMetadata{
ManifestID: md.FromManifestID,
PostDeploymentInfo: fly.PostDeploymentInfo{
FlyctlVersion: buildinfo.Info().Version.String(),
},
Expand Down
73 changes: 41 additions & 32 deletions internal/command/deploy/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ import (

fly "github.com/superfly/fly-go"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/buildinfo"
"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/flyctl/internal/sentry"
"github.com/superfly/flyctl/iostreams"
)

type DeployManifest struct {
AppName string
Config *appconfig.Config `json:"config"`
ID string `json:"id,omitempty"`
FlyVersion string `json:"fly_version,omitempty"`
AppName string `json:"app_name"`
Config *appconfig.Config `json:"config"`
Args *ManifestArgs `json:"args,omitempty"`
}

type ManifestArgs struct {
DeploymentImage string `json:"deployment_image,omitempty"`
Strategy string `json:"strategy,omitempty"`
EnvFromFlags []string `json:"env_from_flags,omitempty"`
Expand Down Expand Up @@ -53,36 +60,38 @@ type DeployManifest struct {

func NewManifest(AppName string, config *appconfig.Config, args MachineDeploymentArgs) *DeployManifest {
return &DeployManifest{
AppName: AppName,
Config: config,
DeploymentImage: args.DeploymentImage,
Strategy: args.Strategy,
EnvFromFlags: args.EnvFromFlags,
PrimaryRegionFlag: args.PrimaryRegionFlag,
SkipSmokeChecks: args.SkipSmokeChecks,
SkipHealthChecks: args.SkipHealthChecks,
SkipDNSChecks: args.SkipDNSChecks,
SkipReleaseCommand: args.SkipReleaseCommand,
MaxUnavailable: args.MaxUnavailable,
RestartOnly: args.RestartOnly,
WaitTimeout: args.WaitTimeout,
StopSignal: args.StopSignal,
LeaseTimeout: args.LeaseTimeout,
ReleaseCmdTimeout: args.ReleaseCmdTimeout,
Guest: args.Guest,
IncreasedAvailability: args.IncreasedAvailability,
UpdateOnly: args.UpdateOnly,
Files: args.Files,
ExcludeRegions: args.ExcludeRegions,
OnlyRegions: args.OnlyRegions,
ExcludeMachines: args.ExcludeMachines,
OnlyMachines: args.OnlyMachines,
ProcessGroups: args.ProcessGroups,
MaxConcurrent: args.MaxConcurrent,
VolumeInitialSize: args.VolumeInitialSize,
RestartPolicy: args.RestartPolicy,
RestartMaxRetries: args.RestartMaxRetries,
DeployRetries: args.DeployRetries,
AppName: AppName,
Config: config,
ID: fmt.Sprintf("manifest_%d", time.Now().UnixNano()),
FlyVersion: buildinfo.Info().Version.String(),
Args: &ManifestArgs{DeploymentImage: args.DeploymentImage,
Strategy: args.Strategy,
EnvFromFlags: args.EnvFromFlags,
PrimaryRegionFlag: args.PrimaryRegionFlag,
SkipSmokeChecks: args.SkipSmokeChecks,
SkipHealthChecks: args.SkipHealthChecks,
SkipDNSChecks: args.SkipDNSChecks,
SkipReleaseCommand: args.SkipReleaseCommand,
MaxUnavailable: args.MaxUnavailable,
RestartOnly: args.RestartOnly,
WaitTimeout: args.WaitTimeout,
StopSignal: args.StopSignal,
LeaseTimeout: args.LeaseTimeout,
ReleaseCmdTimeout: args.ReleaseCmdTimeout,
Guest: args.Guest,
IncreasedAvailability: args.IncreasedAvailability,
UpdateOnly: args.UpdateOnly,
Files: args.Files,
ExcludeRegions: args.ExcludeRegions,
OnlyRegions: args.OnlyRegions,
ExcludeMachines: args.ExcludeMachines,
OnlyMachines: args.OnlyMachines,
ProcessGroups: args.ProcessGroups,
MaxConcurrent: args.MaxConcurrent,
VolumeInitialSize: args.VolumeInitialSize,
RestartPolicy: args.RestartPolicy,
RestartMaxRetries: args.RestartMaxRetries,
DeployRetries: args.DeployRetries},
}
}

Expand Down
Loading
Loading