@@ -2,6 +2,7 @@ package koyeb
22
33import (
44 "context"
5+ "fmt"
56 "strconv"
67 "strings"
78
@@ -197,6 +198,7 @@ func addServiceDefinitionFlags(flags *pflag.FlagSet) {
197198 flags .String ("instance-type" , "nano" , "Instance type" )
198199 flags .Int64 ("min-scale" , 1 , "Min scale" )
199200 flags .Int64 ("max-scale" , 1 , "Max scale" )
201+ flags .StringSlice ("checks" , []string {"" }, "HTTP healthcheck (<port>:http:<path>) and TCP healthcheck (<port>:tcp)" )
200202}
201203
202204func parseServiceDefinitionFlags (flags * pflag.FlagSet , definition * koyeb.DeploymentDefinition , useDefault bool ) error {
@@ -292,6 +294,46 @@ func parseServiceDefinitionFlags(flags *pflag.FlagSet, definition *koyeb.Deploym
292294 definition .SetScalings ([]koyeb.DeploymentScaling {* scaling })
293295 }
294296
297+ if flags .Lookup ("checks" ).Changed {
298+ checks , _ := flags .GetStringSlice ("checks" )
299+ healthchecks := []koyeb.DeploymentHealthCheck {}
300+
301+ for _ , c := range checks {
302+ healthcheck := koyeb .NewDeploymentHealthCheck ()
303+ components := strings .Split (c , ":" )
304+ componentsCount := len (components )
305+ if componentsCount < 2 || componentsCount > 3 {
306+ return fmt .Errorf (`Invalid checks: "%s", must be either "<port>:http:<path>" or "<port>:tcp"` , c )
307+ }
308+
309+ healthcheckType := components [1 ]
310+ portStr := components [0 ]
311+ port , err := strconv .Atoi (portStr )
312+ if err != nil {
313+ return errors .Errorf (`Invalid port: "%s"` , portStr )
314+ }
315+
316+ switch healthcheckType {
317+ case "http" :
318+ if componentsCount < 3 {
319+ return errors .New ("Missing path definition for http check" )
320+ }
321+ HTTPHealthCheck := koyeb .NewHTTPHealthCheck ()
322+ HTTPHealthCheck .Port = koyeb .PtrInt64 (int64 (port ))
323+ HTTPHealthCheck .Path = koyeb .PtrString (components [2 ])
324+ healthcheck .SetHttp (* HTTPHealthCheck )
325+ case "tcp" :
326+ TCPHealthCheck := koyeb .NewTCPHealthCheck ()
327+ TCPHealthCheck .Port = koyeb .PtrInt64 (int64 (port ))
328+ healthcheck .SetTcp (* TCPHealthCheck )
329+ default :
330+ return fmt .Errorf (`Invalid healthcheck: "%s", must be either "http" or "tcp"` , healthcheckType )
331+ }
332+ healthchecks = append (healthchecks , * healthcheck )
333+ }
334+ definition .SetHealthChecks (healthchecks )
335+ }
336+
295337 // Docker
296338 if useDefault && ! flags .Lookup ("git" ).Changed || flags .Lookup ("docker" ).Changed && ! flags .Lookup ("git" ).Changed {
297339 createDockerSource := koyeb .NewDockerSourceWithDefaults ()
0 commit comments