diff --git a/go.sum b/go.sum index bc1a81d..8fec3bf 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -6,12 +7,15 @@ github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731 h1:R/ZjJpjQK github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/urfave/cli-altsrc/v3 v3.0.0-alpha2/go.mod h1:Q79oyIY/z4jtzIrKEK6MUeWC7/szGr46x4QdOaOAIWc= github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkUFnJSo= github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc= github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= diff --git a/internal/archive/targz.go b/internal/archive/targz.go index 32e042f..389d48a 100644 --- a/internal/archive/targz.go +++ b/internal/archive/targz.go @@ -24,7 +24,8 @@ func getIgnoreMatchers(srcFolder string, filepaths ...string) ([]gitignore.Ignor for _, path := range filepaths { matcher, err := gitignore.NewGitIgnore(filepath.Join(srcFolder, path), ".") if err != nil { - return nil, err + zap.L().Debug("Did not file a " + path + " file. Skipping.") + continue } matchers = append(matchers, matcher) diff --git a/internal/commands/altsrc/filesource.go b/internal/commands/altsrc/filesource.go index d87a3c8..bddcccd 100644 --- a/internal/commands/altsrc/filesource.go +++ b/internal/commands/altsrc/filesource.go @@ -169,9 +169,15 @@ func (fvs *fileValueSource) populateFileCache() error { switch fvs.fileType { case "json": // json is a subset of yaml - fvs.cache.populateYAML() + err := fvs.cache.populateYAML() + if err != nil { + return err + } case "yaml": - fvs.cache.populateYAML() + err := fvs.cache.populateYAML() + if err != nil { + return err + } default: return fmt.Errorf("unsupported file type %q", fvs.fileType) } diff --git a/internal/commands/altsrc/flaginit_test.go b/internal/commands/altsrc/flaginit_test.go index 3ae49e1..38c11bd 100644 --- a/internal/commands/altsrc/flaginit_test.go +++ b/internal/commands/altsrc/flaginit_test.go @@ -214,7 +214,10 @@ func Test_InitializeFlagSources(t *testing.T) { }, } - cmd.Run(context.Background(), append([]string{"test"}, tt.args...)) + err := cmd.Run(context.Background(), append([]string{"test"}, tt.args...)) + if err != nil { + return + } assert.Equal(t, fmt.Sprintf("%v", tt.expectValue), flagValue) }) diff --git a/internal/commands/constraints.go b/internal/commands/constraints.go index 296e9dc..c51da5a 100644 --- a/internal/commands/constraints.go +++ b/internal/commands/constraints.go @@ -3,6 +3,7 @@ package commands import ( "fmt" "slices" + "strconv" "strings" ) @@ -21,3 +22,29 @@ func requireIntInRange(value int64, lower int64, upper int64, flagName string) e return nil } + +func requireFloatInRange(value float64, lower float64, upper float64, flagName string) error { + if value < lower || value > upper { + return fmt.Errorf("flag %s must be between %s and %s", + flagName, + strconv.FormatFloat(lower, 'f', -1, 64), + strconv.FormatFloat(upper, 'f', -1, 64)) + } + + return nil +} + +func requireMaxDecimals(value float64, max int, flagName string) error { + var decimals int + stringValue := strconv.FormatFloat(value, 'f', -1, 64) + index := strings.IndexByte(stringValue, '.') + if index > -1 { + decimals = len(stringValue) - index - 1 + } + + if decimals > max { + return fmt.Errorf("flag %s must have a maximum of %d decimal point(s)", flagName, max) + } + + return nil +} \ No newline at end of file diff --git a/internal/commands/deployment.go b/internal/commands/deployment.go index e565b63..9104edc 100644 --- a/internal/commands/deployment.go +++ b/internal/commands/deployment.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "strconv" "github.com/hathora/ci/internal/sdk" "github.com/hathora/ci/internal/sdk/models/shared" @@ -125,6 +126,12 @@ var Deployment = &cli.Command{ addlPorts := cmd.StringSlice(additionalContainerPortsFlag.Name) envVars := cmd.StringSlice(envVarsFlag.Name) + if requestedMemory != (requestedCPU * 2048) { + return fmt.Errorf("invalid memory: %s and cpu: %s requested-memory-mb must be a 2048:1 ratio to requested-cpu", + strconv.FormatFloat(requestedMemory, 'f', -1, 64), + strconv.FormatFloat(requestedCPU, 'f', -1, 64)) + } + additionalContainerPorts, err := parseContainerPorts(addlPorts) if err != nil { return fmt.Errorf("invalid additional container ports: %w", err) @@ -230,6 +237,9 @@ var ( Sources: cli.EnvVars(deploymentEnvVar("REQUESTED_MEMORY_MB")), Usage: "the amount of memory allocated to your process in MB", Required: true, + Action: func(ctx context.Context, cmd *cli.Command, v float64) error { + return requireFloatInRange(v, 1024, 8192, "requested-memory-mb") + }, } requestedCPUFlag = &cli.FloatFlag{ @@ -237,6 +247,18 @@ var ( Sources: cli.EnvVars(deploymentEnvVar("REQUESTED_CPU")), Usage: "the number of cores allocated to your process", Required: true, + Action: func(ctx context.Context, cmd *cli.Command, v float64) error { + rangeErr := requireFloatInRange(v, 0.5, 4, "requested-cpu") + if rangeErr != nil { + return rangeErr + } + decimalErr := requireMaxDecimals(v, 1, "requested-cpu") + if decimalErr != nil { + return decimalErr + } + + return nil + }, } )