Skip to content

Commit

Permalink
Make app path required (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Oct 12, 2024
1 parent 2043a9e commit 06a47bb
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 65 deletions.
115 changes: 101 additions & 14 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,37 @@
"version": "0.2.0",
"configurations": [
{
"name": "Modus Runtime",
"name": "Debug Modus Runtime (pick example)",
"type": "go",
"request": "launch",
"mode": "auto",
"preLaunchTask": "go: generate code",
"program": "${workspaceFolder}/runtime",
"env": {
"MODUS_ENV": "dev",
"MODUS_DEBUG": "true",
"MODUS_DB": "postgresql://postgres:postgres@localhost:5433/my-runtime-db?sslmode=disable"
},
"args": ["--refresh=1s"]
"args": [
"--refresh=1s",
"--appPath",
"${workspaceFolder}/sdk/${input:appLanguage}/examples/${input:exampleApp}/build"
]
},
{
"name": "Modus Runtime (AWS Storage)",
"name": "Debug Modus Runtime (input path)",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/runtime",
"env": {
"MODUS_ENV": "dev",
"MODUS_DEBUG": "true",
"MODUS_DB": "postgresql://postgres:postgres@localhost:5433/my-runtime-db?sslmode=disable"
},
"args": ["--refresh=1s", "--appPath", "${input:appPath}"]
},
{
"name": "Debug Modus Runtime (aws storage)",
"type": "go",
"request": "launch",
"mode": "auto",
Expand All @@ -38,29 +54,100 @@
]
},
{
"name": "modus-go-build simple example",
"type": "go",
"name": "Debug Build Example AssemblyScript App",
"type": "node-terminal",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/sdk/go/tools/modus-go-build",
"args": ["${workspaceFolder}/sdk/go/examples/simple"],
"env": {
"MODUS_DEBUG": "true"
}
"command": "npm install --prefix ${workspaceFolder}/sdk/assemblyscript/src && npm install && npm run build",
"cwd": "${workspaceFolder}/sdk/assemblyscript/examples/${input:exampleApp}"
},
{
"name": "modus-go-build http example",
"name": "Debug Build Example Go App",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/sdk/go/tools/modus-go-build",
"args": ["${workspaceFolder}/sdk/go/examples/http"],
"args": ["${workspaceFolder}/sdk/go/examples/${input:exampleApp}"],
"env": {
"MODUS_DEBUG": "true"
}
}
],
"inputs": [
{
"id": "appPath",
"type": "promptString",
"description": "Enter the path to the Modus app's build directory"
},
{
"id": "appLanguage",
"type": "pickString",
"description": "Choose an app language",
"options": [
{
"label": "AssemblyScript",
"value": "assemblyscript"
},
{
"label": "Go",
"value": "go"
}
]
},
{
"id": "exampleApp",
"type": "pickString",
"description": "Choose a Modus app",
"options": [
{
"label": "Anthropic Model Example",
"value": "anthropic-functions"
},
{
"label": "Auth Example",
"value": "auth"
},
{
"label": "Classification Model Example",
"value": "classification"
},
{
"label": "Collections Example",
"value": "collections"
},
{
"label": "Dgraph Client Example",
"value": "dgraph"
},
{
"label": "Embedding Model Example",
"value": "embedding"
},
{
"label": "GraphQL Client Example",
"value": "graphql"
},
{
"label": "HTTP Client Example",
"value": "http"
},
{
"label": "PostgreSQL Client Example",
"value": "postgresql"
},
{
"label": "Simple Example",
"value": "simple"
},
{
"label": "Text Generation Model Example",
"value": "textgeneration"
},
{
"label": "Vectors API Example",
"value": "vectors"
}
]
},
{
"id": "awsProfile",
"type": "promptString",
Expand Down
17 changes: 0 additions & 17 deletions .vscode/tasks.json

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ In previous releases, the name "Hypermode" was used for all three._
- Add release pipeline for the runtime [#453](https://github.com/hypermodeinc/modus/pull/453) [#454](https://github.com/hypermodeinc/modus/pull/454)
- Remove `go generate` and fix docker build [#455](https://github.com/hypermodeinc/modus/pull/455)
- Remove AWS Secrets Manager client [#456](https://github.com/hypermodeinc/modus/pull/456)
- Make app path required [#457](https://github.com/hypermodeinc/modus/pull/457)

## 2024-10-02 - Version 0.12.7

Expand Down
25 changes: 2 additions & 23 deletions runtime/config/commandline.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"runtime"
"time"
)

var Port int
var ModelHost string
var StoragePath string
var AppPath string
var UseAwsStorage bool
var S3Bucket string
var S3Path string
var RefreshInterval time.Duration
var UseJsonLogging bool

func parseCommandLineFlags() {
flag.StringVar(&AppPath, "appPath", "", "REQUIRED - The path to the Modus app to load and run.")
flag.IntVar(&Port, "port", 8686, "The HTTP port to listen on.")
flag.StringVar(&ModelHost, "modelHost", "", "The base DNS of the host endpoint to the model server.")
flag.StringVar(&StoragePath, "storagePath", getDefaultStoragePath(), "The path to a directory used for local storage.")
flag.BoolVar(&UseAwsStorage, "useAwsStorage", false, "Use AWS S3 for storage instead of the local filesystem.")
flag.StringVar(&S3Bucket, "s3bucket", "", "The S3 bucket to use, if using AWS storage.")
flag.StringVar(&S3Path, "s3path", "", "The path within the S3 bucket to use, if using AWS storage.")
Expand All @@ -49,22 +47,3 @@ func parseCommandLineFlags() {
os.Exit(0)
}
}

func getDefaultStoragePath() string {

// TODO: this logic needs to change. The storage path should be passed in always, by the modus CLI. It should not be inferred.
// See https://linear.app/hypermode/issue/HYP-2323/runtime-instancing-storage-paths

// On Windows, the default is %APPDATA%\Hypermode
if runtime.GOOS == "windows" {
appData := os.Getenv("APPDATA")
return filepath.Join(appData, "Hypermode")
}

// On Unix and macOS, the default is $HOME/.hypermode
homedir, err := os.UserHomeDir()
if err != nil {
return ""
}
return filepath.Join(homedir, ".hypermode")
}
2 changes: 1 addition & 1 deletion runtime/integration_tests/postgresql_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func updateManifest(t *testing.T, jsonManifest []byte) func() {

func TestMain(m *testing.M) {
// setup config
config.StoragePath = testPluginsPath
config.AppPath = testPluginsPath
config.RefreshInterval = refreshPluginInterval
config.Port = httpListenPort

Expand Down
4 changes: 2 additions & 2 deletions runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func main() {

// Load environment variables from plugins path
// note: .env file is optional, so don't log if it's not found
err := godotenv.Load(filepath.Join(config.StoragePath, ".env"))
err := godotenv.Load(filepath.Join(config.AppPath, ".env"))
if err != nil && !os.IsNotExist(err) {
log.Warn().Err(err).Msg("Error reading .env file. Ignoring.")
}
if config.IsDevEnvironment() {
err = godotenv.Load(filepath.Join(config.StoragePath, ".env.local"))
err = godotenv.Load(filepath.Join(config.AppPath, ".env.local"))
if err != nil && !os.IsNotExist(err) {
log.Warn().Err(err).Msg("Error reading .env.local file. Ignoring.")
}
Expand Down
16 changes: 8 additions & 8 deletions runtime/storage/localstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ type localStorageProvider struct {
}

func (stg *localStorageProvider) initialize(ctx context.Context) {
if config.StoragePath == "" {
logger.Fatal(ctx).Msg("A storage path is required when using local storage. Exiting.")
if config.AppPath == "" {
logger.Fatal(ctx).Msg("The -appPath command line argument is required when using local storage. Exiting.")
}

if _, err := os.Stat(config.StoragePath); os.IsNotExist(err) {
if _, err := os.Stat(config.AppPath); os.IsNotExist(err) {
logger.Info(ctx).
Str("path", config.StoragePath).
Str("path", config.AppPath).
Msg("Creating local storage directory.")
err := os.MkdirAll(config.StoragePath, 0755)
err := os.MkdirAll(config.AppPath, 0755)
if err != nil {
logger.Fatal(ctx).Err(err).
Msg("Failed to create local storage directory. Exiting.")
}
} else {
logger.Info(ctx).
Str("path", config.StoragePath).
Str("path", config.AppPath).
Msg("Found local storage directory.")
}
}

func (stg *localStorageProvider) listFiles(ctx context.Context, extension string) ([]FileInfo, error) {
entries, err := os.ReadDir(config.StoragePath)
entries, err := os.ReadDir(config.AppPath)
if err != nil {
return nil, fmt.Errorf("failed to list files in storage directory: %w", err)
}
Expand All @@ -70,7 +70,7 @@ func (stg *localStorageProvider) listFiles(ctx context.Context, extension string
}

func (stg *localStorageProvider) getFileContents(ctx context.Context, name string) ([]byte, error) {
path := filepath.Join(config.StoragePath, name)
path := filepath.Join(config.AppPath, name)
content, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read contents of file %s from local storage: %w", name, err)
Expand Down

0 comments on commit 06a47bb

Please sign in to comment.