Skip to content

Commit

Permalink
Allow machine checks without a service (#3720)
Browse files Browse the repository at this point in the history
* Allow machine checks without a service

Some customers want to be able to use machine checks for apps that only
use private communications, which is a very fair use case. In order to
allow for this, we just allow putting machine_checks at the top level of
a fly.toml

* Fixed weird indenting

My editor was apparently hiding this from me
  • Loading branch information
billyb2 committed Jul 10, 2024
1 parent 71f6022 commit 2b35303
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/appconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Config struct {
Files []File `toml:"files,omitempty" json:"files,omitempty"`
HostDedicationID string `toml:"host_dedication_id,omitempty" json:"host_dedication_id,omitempty"`

MachineChecks []*ServiceMachineCheck `toml:"machine_checks,omitempty" json:"machine_checks,omitempty"`

Restart []Restart `toml:"restart,omitempty" json:"restart,omitempty"`

Compute []*Compute `toml:"vm,omitempty" json:"vm,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions internal/appconfig/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ func TestToDefinition(t *testing.T) {
},
},
},
"machine_checks": []any{
map[string]any{
"command": []any{"curl", "https://fly.io"},
"image": "curlimages/curl",
"entrypoint": []any{"/bin/sh"},
"kill_signal": "SIGKILL",
"kill_timeout": "5s",
},
},
"experimental": map[string]any{
"cmd": []any{"cmd"},
"entrypoint": []any{"entrypoint"},
Expand Down
10 changes: 10 additions & 0 deletions internal/appconfig/serde_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ func TestLoadTOMLAppConfigReferenceFormat(t *testing.T) {
},
},

MachineChecks: []*ServiceMachineCheck{
{
Command: []string{"curl", "https://fly.io"},
Entrypoint: []string{"/bin/sh"},
Image: "curlimages/curl",
KillSignal: fly.StringPointer("SIGKILL"),
KillTimeout: fly.MustParseDuration("5s"),
},
},

Statics: []Static{
{
GuestPath: "/path/to/statics",
Expand Down
7 changes: 7 additions & 0 deletions internal/appconfig/testdata/full-reference.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ host_dedication_id = "06031957"
Content-Type = "application/json"
Authorization = "super-duper-secret"

[[machine_checks]]
command = ["curl", "https://fly.io"]
image = "curlimages/curl"
entrypoint = ["/bin/sh"]
kill_timeout = "5s"
kill_signal = "SIGKILL"

[[services]]
internal_port = 8081
protocol = "tcp"
Expand Down
1 change: 1 addition & 0 deletions internal/command/deploy/machinebasedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (md *machineDeployment) runTestMachines(ctx context.Context, machineToTest
return nil
}
})
machineChecks = append(machineChecks, md.appConfig.MachineChecks...)

if len(machineChecks) == 0 {
span.AddEvent("no machine checks")
Expand Down
18 changes: 18 additions & 0 deletions test/preflight/fly_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,24 @@ func TestFlyDeploy_DeployMachinesCheck(t *testing.T) {
require.Contains(f, output, "Test Machine")
}

func TestFlyDeploy_NoServiceDeployMachinesCheck(t *testing.T) {
f := testlib.NewTestEnvFromEnv(t)
appName := f.CreateRandomAppName()
f.Fly("launch --org %s --name %s --region %s --image nginx --internal-port 80 --ha=false", f.OrgSlug(), appName, f.PrimaryRegion())
appConfig := f.ReadFile("fly.toml")
appConfig += `
[[machine_checks]]
image = "curlimages/curl"
entrypoint = ["/bin/sh", "-c"]
command = ["curl http://[$FLY_TEST_MACHINE_IP]:80"]
`
f.WriteFlyToml(appConfig)
f.OverrideAuthAccessToken(f.Fly("tokens deploy").StdOut().String())
deployRes := f.Fly("deploy")
output := deployRes.StdOutString()
require.Contains(f, output, "Test Machine")
}

func TestFlyDeploy_DeployMachinesCheckCanary(t *testing.T) {
f := testlib.NewTestEnvFromEnv(t)
appName := f.CreateRandomAppName()
Expand Down

0 comments on commit 2b35303

Please sign in to comment.