Skip to content

Commit

Permalink
Add deploy.release_command_vm directive to set release machine size (#…
Browse files Browse the repository at this point in the history
…4085)

* Add deploy.release_command_vm directive to set release machine size

* Another example
  • Loading branch information
dangra authored Nov 26, 2024
1 parent 17c8034 commit c4780b9
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 10 deletions.
5 changes: 3 additions & 2 deletions internal/appconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ type Metrics struct {
}

type Deploy struct {
ReleaseCommand string `toml:"release_command,omitempty" json:"release_command,omitempty"`
ReleaseCommandTimeout *fly.Duration `toml:"release_command_timeout,omitempty" json:"release_command_timeout,omitempty"`
Strategy string `toml:"strategy,omitempty" json:"strategy,omitempty"`
MaxUnavailable *float64 `toml:"max_unavailable,omitempty" json:"max_unavailable,omitempty"`
WaitTimeout *fly.Duration `toml:"wait_timeout,omitempty" json:"wait_timeout,omitempty"`
ReleaseCommand string `toml:"release_command,omitempty" json:"release_command,omitempty"`
ReleaseCommandTimeout *fly.Duration `toml:"release_command_timeout,omitempty" json:"release_command_timeout,omitempty"`
ReleaseCommandCompute *Compute `toml:"release_command_vm,omitempty" json:"release_command_vm,omitempty"`
}

type File struct {
Expand Down
11 changes: 8 additions & 3 deletions internal/appconfig/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,14 @@ func TestToDefinition(t *testing.T) {
},

"deploy": map[string]any{
"release_command": "release command",
"strategy": "rolling-eyes",
"max_unavailable": 0.2,
"strategy": "rolling-eyes",
"max_unavailable": 0.2,
"release_command": "release command",
"release_command_timeout": "3m0s",
"release_command_vm": map[string]any{
"size": "performance-2x",
"memory": "8g",
},
},
"env": map[string]any{
"FOO": "BAR",
Expand Down
13 changes: 12 additions & 1 deletion internal/appconfig/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ func (c *Config) ToReleaseMachineConfig() (*fly.MachineConfig, error) {
mConfig.Files = nil
fly.MergeFiles(mConfig, c.MergedFiles)

// Guest
if v := c.Deploy.ReleaseCommandCompute; v != nil {
guest, err := c.computeToGuest(v)
if err != nil {
return nil, err
}
mConfig.Guest = guest
}

return mConfig, nil
}

Expand Down Expand Up @@ -436,8 +445,10 @@ func (c *Config) toMachineGuest() (*fly.MachineGuest, error) {
}

// At most one compute after group flattening
compute := c.Compute[0]
return c.computeToGuest(c.Compute[0])
}

func (c *Config) computeToGuest(compute *Compute) (*fly.MachineGuest, error) {
size := fly.DefaultVMSize
switch {
case compute.Size != "":
Expand Down
5 changes: 5 additions & 0 deletions internal/appconfig/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func TestToReleaseMachineConfig(t *testing.T) {
Timeout: fly.MustParseDuration("10s"),
Signal: fly.Pointer("SIGTERM"),
},
Guest: &fly.MachineGuest{
CPUKind: "performance",
CPUs: 2,
MemoryMB: 4096,
},
}

got, err := cfg.ToReleaseMachineConfig()
Expand Down
11 changes: 8 additions & 3 deletions internal/appconfig/serde_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,14 @@ func TestLoadTOMLAppConfigReferenceFormat(t *testing.T) {
},

Deploy: &Deploy{
ReleaseCommand: "release command",
Strategy: "rolling-eyes",
MaxUnavailable: fly.Pointer(0.2),
Strategy: "rolling-eyes",
MaxUnavailable: fly.Pointer(0.2),
ReleaseCommand: "release command",
ReleaseCommandTimeout: fly.MustParseDuration("3m"),
ReleaseCommandCompute: &Compute{
Size: "performance-2x",
Memory: "8g",
},
},

Env: map[string]string{
Expand Down
3 changes: 3 additions & 0 deletions internal/appconfig/testdata/full-reference.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ host_dedication_id = "06031957"

[deploy]
release_command = "release command"
release_command_timeout = "3m"
release_command_vm.size = "performance-2x"
release_command_vm.memory = "8g"
strategy = "rolling-eyes"
max_unavailable = 0.2

Expand Down
4 changes: 4 additions & 0 deletions internal/appconfig/testdata/tomachine.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ swap_size_mb = 512

[deploy]
release_command = "migrate-db"
release_command_timeout = "3m"
[deploy.release_command_vm]
size = "performance-2x"
memory = "4G"

[[restart]]
policy = "always"
Expand Down
4 changes: 3 additions & 1 deletion internal/command/deploy/machines_releasecommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ func (md *machineDeployment) launchInputForReleaseCommand(origMachineRaw *fly.Ma
// We can ignore the error because ToReleaseMachineConfig fails only
// if it can't split the command and we test that at initialization
mConfig, _ := md.appConfig.ToReleaseMachineConfig()
mConfig.Guest = md.inferReleaseCommandGuest()
mConfig.Image = md.img
if mConfig.Guest == nil {
mConfig.Guest = md.inferReleaseCommandGuest()
}
md.setMachineReleaseData(mConfig)

if hdid := md.appConfig.HostDedicationID; hdid != "" {
Expand Down

0 comments on commit c4780b9

Please sign in to comment.