Skip to content

Commit

Permalink
sad
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Nov 13, 2023
1 parent f1f9c08 commit 032cde5
Show file tree
Hide file tree
Showing 14 changed files with 1,422 additions and 312 deletions.
15 changes: 15 additions & 0 deletions cmd/config/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ func commandExample(cCtx *cli.Context) error { //nolint:funlen,maintidx
},
},
},
Ai: &model.ConfigAI{
Version: ptr("0.1.0"),
Resources: &model.ConfigAIResources{
Compute: &model.ConfigComputeResources{
Cpu: 256,
Memory: 512,
},
},
Openai: &model.ConfigAIOpenai{
Organization: ptr("org-id"),
ApiKey: "opeanai-api-key",
},
SynchPeriodMinutes: ptr(uint32(10)),
WebhookSecret: "this-is-a-webhook-secret",
},
Hasura: &model.ConfigHasura{
Version: new(string),
JwtSecrets: []*model.ConfigJWTSecret{
Expand Down
2 changes: 1 addition & 1 deletion cmd/run/config_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func commandConfigExample(cCtx *cli.Context) error { //nolint:funlen
},
},
Resources: &model.ConfigRunServiceResources{
Compute: &model.ConfigRunServiceResourcesCompute{
Compute: &model.ConfigComputeResources{
Cpu: 125,
Memory: 256,
},
Expand Down
47 changes: 47 additions & 0 deletions dockercompose/ai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dockercompose

import (
"fmt"

"github.com/nhost/be/services/mimir/model"
"github.com/nhost/be/services/mimir/schema/appconfig"
)

func ai(
cfg *model.ConfigConfig,
) *Service {
envars := appconfig.AIEnv(
cfg,
"http://graphql:8080/v1/graphql",
"postgres://postgres@postgres:5432/local?sslmode=disable",
)

env := make(map[string]string, len(envars))
for _, v := range envars {
env[v.Name] = v.Value
}

return &Service{
Image: fmt.Sprintf("nhost/graphite:%s", *cfg.GetAi().GetVersion()),
DependsOn: map[string]DependsOn{
"graphql": {
Condition: "service_healthy",
},
"postgres": {
Condition: "service_healthy",
},
},
EntryPoint: nil,
Command: []string{
"serve",
},
Environment: env,
ExtraHosts: extraHosts(),
Labels: nil,
Ports: nil,
Restart: "always",
HealthCheck: nil,
Volumes: nil,
WorkingDir: nil,
}
}
71 changes: 71 additions & 0 deletions dockercompose/ai_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package dockercompose //nolint:testpackage

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/nhost/be/services/mimir/model"
)

func expectedAI() *Service {
return &Service{ //nolint:exhaustruct
Image: "nhost/graphite:0.2.5",
DependsOn: map[string]DependsOn{
"graphql": {Condition: "service_healthy"},
"postgres": {Condition: "service_healthy"},
},
Command: []string{"serve"},
Environment: map[string]string{
"ENV1": "VALUE1",
"ENV2": "VALUE2",
"GRAPHITE_BASE_URL": "http://graphite:8090",
"GRAPHITE_WEBHOOK_SECRET": "webhookSecret",
"HASURA_GRAPHQL_ADMIN_SECRET": "adminSecret",
"NHOST_GRAPHQL_URL": "http://graphql:8080/v1/graphql",
"OPENAI_API_KEY": "openaiApiKey",
"OPENAI_ORG": "my-org",
"POSTGRES_CONNECTION": "postgres://postgres@postgres:5432/local?sslmode=disable",
"SYNCH_PERIOD": "10m",
},
ExtraHosts: []string{
"host.docker.internal:host-gateway",
"local.auth.nhost.run:host-gateway",
"local.db.nhost.run:host-gateway",
"local.functions.nhost.run:host-gateway",
"local.graphql.nhost.run:host-gateway",
"local.hasura.nhost.run:host-gateway",
"local.storage.nhost.run:host-gateway",
},
Restart: "always",
}
}

func TestAI(t *testing.T) {
t.Parallel()

cases := []struct {
name string
cfg func() *model.ConfigConfig
useTlS bool
expected func() *Service
}{
{
name: "success",
cfg: getConfig,
expected: expectedAI,
},
}

for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
tc := tc

got := ai(tc.cfg())
if diff := cmp.Diff(tc.expected(), got); diff != "" {
t.Error(diff)
}
})
}
}
5 changes: 5 additions & 0 deletions dockercompose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,5 +506,10 @@ func ComposeFileFromConfig( //nolint:funlen
pgVolumeName: {},
},
}

if cfg.Ai != nil {
c.Services["graphite"] = ai(cfg)
}

return c, nil
}
15 changes: 15 additions & 0 deletions dockercompose/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ import (

func getConfig() *model.ConfigConfig { //nolint:maintidx
return &model.ConfigConfig{
Ai: &model.ConfigAI{
Version: ptr("0.2.5"),
Resources: &model.ConfigAIResources{
Compute: &model.ConfigComputeResources{
Cpu: 128,
Memory: 256,
},
},
Openai: &model.ConfigAIOpenai{
Organization: ptr("my-org"),
ApiKey: "openaiApiKey",
},
SynchPeriodMinutes: ptr(uint32(10)),
WebhookSecret: "webhookSecret",
},
Auth: &model.ConfigAuth{
Resources: &model.ConfigResources{
Compute: &model.ConfigResourcesCompute{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/go-git/go-git/v5 v5.9.0
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-getter v1.7.3
github.com/nhost/be v0.0.0-20231107151453-7e54cb68abc2
github.com/nhost/be v0.0.0-20231113140342-c5f8b3f03973
github.com/pelletier/go-toml/v2 v2.1.0
github.com/urfave/cli/v2 v2.25.7
github.com/wI2L/jsondiff v0.4.0
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ github.com/nhost/be v0.0.0-20231107143741-114c8c189274 h1:53zsrfBgz1EjWIz04btAbO
github.com/nhost/be v0.0.0-20231107143741-114c8c189274/go.mod h1:wYw8iVi1dZG6IAK0eCSOFAWHAISTa+9sjGA6Vx/x1Sg=
github.com/nhost/be v0.0.0-20231107151453-7e54cb68abc2 h1:KhTGs5SUCi7zWYAS9Dag2POf6ok6rWUCW+On8KakoME=
github.com/nhost/be v0.0.0-20231107151453-7e54cb68abc2/go.mod h1:wYw8iVi1dZG6IAK0eCSOFAWHAISTa+9sjGA6Vx/x1Sg=
github.com/nhost/be v0.0.0-20231113130936-fe9b215c1d17 h1:IE/NEWv8Iv30LxBytuMKGsnaNq/TzocHPlVryJscfqg=
github.com/nhost/be v0.0.0-20231113130936-fe9b215c1d17/go.mod h1:wYw8iVi1dZG6IAK0eCSOFAWHAISTa+9sjGA6Vx/x1Sg=
github.com/nhost/be v0.0.0-20231113133139-09c9d8a8c3f9 h1:Nsr5h17eQoHL4CC/5HXjJif/73lzyATK1eCllM5s66Q=
github.com/nhost/be v0.0.0-20231113133139-09c9d8a8c3f9/go.mod h1:wYw8iVi1dZG6IAK0eCSOFAWHAISTa+9sjGA6Vx/x1Sg=
github.com/nhost/be v0.0.0-20231113135039-85e7b28890bc h1:+UrISMw4hTj5aYQ1oH840V2PDMG9M6vlNwIfLnNrdwo=
github.com/nhost/be v0.0.0-20231113135039-85e7b28890bc/go.mod h1:wYw8iVi1dZG6IAK0eCSOFAWHAISTa+9sjGA6Vx/x1Sg=
github.com/nhost/be v0.0.0-20231113140342-c5f8b3f03973 h1:fNwP+4nwKJ1sltLpOwkfNB/rdUwHXjDoS+tsDVQ0zK4=
github.com/nhost/be v0.0.0-20231113140342-c5f8b3f03973/go.mod h1:wYw8iVi1dZG6IAK0eCSOFAWHAISTa+9sjGA6Vx/x1Sg=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
Expand Down
4 changes: 2 additions & 2 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

go = prev.go_1_21.overrideAttrs
(finalAttrs: previousAttrs: rec {
version = "1.21.3";
version = "1.21.4";

src = final.fetchurl {
url = "https://go.dev/dl/go${version}.src.tar.gz";
sha256 = "sha256-GG8rb4yLcE5paCGwmrIEGlwe4T3LwxVqE63PdZMe5Ig=";
sha256 = "sha256-R7Jqg9K2WjwcG8rOJztpvuSaentRaKdgTe09JqN714c=";
};

});
Expand Down
Loading

0 comments on commit 032cde5

Please sign in to comment.