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

chore: update schema and added config example for run service #790

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 20 additions & 4 deletions cmd/config/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ func commandExample(cCtx *cli.Context) error { //nolint:funlen,maintidx
Cpu: 500,
Memory: 1024,
},
Replicas: 1,
Replicas: ptr(uint8(1)),
Networking: &model.ConfigNetworking{
Ingresses: []*model.ConfigIngress{
{
Fqdn: []string{"hasura.example.com"},
},
},
},
},
},
Functions: &model.ConfigFunctions{
Expand All @@ -82,7 +89,14 @@ func commandExample(cCtx *cli.Context) error { //nolint:funlen,maintidx
Cpu: 250,
Memory: 512,
},
Replicas: 1,
Replicas: ptr(uint8(1)),
Networking: &model.ConfigNetworking{
Ingresses: []*model.ConfigIngress{
{
Fqdn: []string{"auth.example.com"},
},
},
},
},
Redirections: &model.ConfigAuthRedirections{
ClientUrl: ptr("https://example.com"),
Expand Down Expand Up @@ -263,7 +277,8 @@ func commandExample(cCtx *cli.Context) error { //nolint:funlen,maintidx
Cpu: 2000,
Memory: 4096,
},
Replicas: 1,
Replicas: ptr(uint8(1)),
Networking: nil,
},
Settings: &model.ConfigPostgresSettings{
Jit: ptr("off"),
Expand Down Expand Up @@ -313,7 +328,8 @@ func commandExample(cCtx *cli.Context) error { //nolint:funlen,maintidx
Cpu: 500,
Memory: 1024,
},
Replicas: 1,
Networking: nil,
Replicas: ptr(uint8(1)),
},
},
Observability: &model.ConfigObservability{
Expand Down
95 changes: 95 additions & 0 deletions cmd/run/config_example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package run

import (
"fmt"

"github.com/nhost/be/services/mimir/model"
"github.com/nhost/be/services/mimir/schema"
"github.com/nhost/cli/clienv"
"github.com/pelletier/go-toml/v2"
"github.com/urfave/cli/v2"
)

func ptr[T any](v T) *T {
return &v
}

func CommandConfigExample() *cli.Command {
return &cli.Command{ //nolint:exhaustruct
Name: "config-example",
Aliases: []string{},
Usage: "Shows an example config file",
Action: commandConfigExample,
Flags: []cli.Flag{},
}
}

func commandConfigExample(cCtx *cli.Context) error { //nolint:funlen
ce := clienv.FromCLI(cCtx)

//nolint:gomnd
cfg := &model.ConfigRunServiceConfig{
Name: "my-run-service",
Image: &model.ConfigRunServiceImage{
Image: "docker.io/org/img:latest",
},
Command: []string{
"start",
},
Environment: []*model.ConfigEnvironmentVariable{
{
Name: "ENV_VAR1",
Value: "value1",
},
{
Name: "ENV_VAR2",
Value: "value2",
},
},
Ports: []*model.ConfigRunServicePort{
{
Port: 8080,
Type: "http",
Publish: ptr(true),
Ingresses: []*model.ConfigIngress{
{
Fqdn: []string{"my-run-service.acme.com"},
},
},
},
},
Resources: &model.ConfigRunServiceResources{
Compute: &model.ConfigRunServiceResourcesCompute{
Cpu: 125,
Memory: 256,
},
Storage: []*model.ConfigRunServiceResourcesStorage{
{
Name: "my-storage",
Capacity: 1,
Path: "/var/lib/my-storage",
},
},
Replicas: 1,
},
}

sch, err := schema.New()
if err != nil {
return fmt.Errorf("failed to create schema: %w", err)
}

cfg, err = sch.FillRunServiceConfig(cfg)
if err != nil {
return fmt.Errorf("failed to validate config: %w", err)
}

b, err := toml.Marshal(cfg)
if err != nil {
return fmt.Errorf("failed to marshal config: %w", err)
}

ce.Println(string(b))

return nil
}
1 change: 1 addition & 0 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func Command() *cli.Command {
CommandConfigEditImage(),
CommandConfigPull(),
CommandConfigValidate(),
CommandConfigExample(),
},
}
}
12 changes: 8 additions & 4 deletions dockercompose/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ func getConfig() *model.ConfigConfig { //nolint:maintidx
Cpu: 1000,
Memory: 300,
},
Replicas: 3,
Replicas: ptr(uint8(3)),
Networking: nil,
},
Method: &model.ConfigAuthMethod{
Anonymous: &model.ConfigAuthMethodAnonymous{
Expand Down Expand Up @@ -206,7 +207,8 @@ func getConfig() *model.ConfigConfig { //nolint:maintidx
Cpu: 1000,
Memory: 700,
},
Replicas: 3,
Replicas: ptr(uint8(3)),
Networking: nil,
},
AdminSecret: "adminSecret",
JwtSecrets: []*model.ConfigJWTSecret{
Expand Down Expand Up @@ -251,7 +253,8 @@ func getConfig() *model.ConfigConfig { //nolint:maintidx
Cpu: 2000,
Memory: 500,
},
Replicas: 1,
Replicas: ptr(uint8(1)),
Networking: nil,
},
Settings: nil,
},
Expand All @@ -278,7 +281,8 @@ func getConfig() *model.ConfigConfig { //nolint:maintidx
Cpu: 500,
Memory: 50,
},
Replicas: 1,
Replicas: ptr(uint8(1)),
Networking: nil,
},
Antivirus: &model.ConfigStorageAntivirus{
Server: ptr("tcp://run-clamav:3310"),
Expand Down
2 changes: 1 addition & 1 deletion examples/myproject/nhost/nhost.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ sharedBuffers = '256MB'
effectiveCacheSize = '768MB'
maintenanceWorkMem = '64MB'
checkpointCompletionTarget = 0.9
walBuffers = -1
walBuffers = "-1"
defaultStatisticsTarget = 100
randomPageCost = 1.1
effectiveIOConcurrency = 200
Expand Down
55 changes: 28 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,43 @@ module github.com/nhost/cli

go 1.21

replace cuelang.org/go => cuelang.org/go v0.4.3

require (
github.com/Yamashou/gqlgenc v0.15.0
github.com/charmbracelet/lipgloss v0.8.0
github.com/Yamashou/gqlgenc v0.15.1
github.com/charmbracelet/lipgloss v0.9.1
github.com/creack/pty v1.1.18
github.com/go-git/go-git/v5 v5.9.0
github.com/google/go-cmp v0.5.9
github.com/hashicorp/go-getter v1.7.2
github.com/nhost/be v0.0.0-20231001065154-f72edc119cf0
github.com/pelletier/go-toml/v2 v2.0.8
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-getter v1.7.3
github.com/nhost/be v0.0.0-20231013070532-b96bf777844b
github.com/pelletier/go-toml/v2 v2.1.0
github.com/urfave/cli/v2 v2.25.7
github.com/wI2L/jsondiff v0.4.0
golang.org/x/mod v0.12.0
golang.org/x/term v0.12.0
golang.org/x/mod v0.13.0
golang.org/x/term v0.13.0
gopkg.in/evanphx/json-patch.v5 v5.7.0
gopkg.in/yaml.v3 v3.0.1
)

require (
cloud.google.com/go v0.110.8 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute v1.23.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.2 // indirect
cloud.google.com/go/iam v1.1.3 // indirect
cloud.google.com/go/storage v1.33.0 // indirect
cuelang.org/go v0.5.0 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/99designs/gqlgen v0.17.38 // indirect
github.com/99designs/gqlgen v0.17.39 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/aws/aws-sdk-go v1.45.16 // indirect
github.com/aws/aws-sdk-go v1.45.25 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
Expand Down Expand Up @@ -68,29 +70,28 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sosodev/duration v1.2.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vektah/gqlparser/v2 v2.5.10 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.143.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.147.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/grpc v1.58.2 // indirect
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)

replace github.com/pelletier/go-toml/v2 => github.com/dbarrosop/go-toml/v2 v2.0.0-20230603161714-891170c4bf79
Loading
Loading