Skip to content

Commit

Permalink
allows extensions (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikey committed Dec 22, 2023
1 parent bdd1fc9 commit e7685a5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
"0",
"--role",
"worker",
"--runtime",
"--runtime-path",
"/tmp/runtime",
"--runtime-cli",
"bls-runtime",
"--workspace",
"/tmp/debug/worker",
"--private-key",
Expand Down
1 change: 1 addition & 0 deletions executor/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (e *Executor) createCmd(paths requestPaths, req execute.Request) *exec.Cmd
cfg := req.Config.Runtime
cfg.Input = paths.input
cfg.FSRoot = paths.fsRoot
cfg.DriversRootPath = e.cfg.DriversRootPath

// Prepare CLI arguments.
// Append the input argument first first.
Expand Down
2 changes: 2 additions & 0 deletions executor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ var defaultConfig = Config{
ExecutableName: blockless.RuntimeCLI(),
FS: afero.NewOsFs(),
Limiter: &noopLimiter{},
DriversRootPath: "",
}

// Config represents the Executor configuration.
type Config struct {
WorkDir string // directory where files needed for the execution are stored
RuntimeDir string // directory where the executable can be found
ExecutableName string // name for the executable
DriversRootPath string // where are cgi drivers stored
FS afero.Fs // FS accessor
Limiter Limiter // Resource limiter for executed processes
}
Expand Down
3 changes: 3 additions & 0 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func New(log zerolog.Logger, options ...Option) (*Executor, error) {
}
cfg.RuntimeDir = runtime

// todo: fix for windows
cfg.DriversRootPath = cfg.RuntimeDir + "/extensions"

// Verify the runtime path is valid.
cliPath := filepath.Join(cfg.RuntimeDir, cfg.ExecutableName)
_, err = cfg.FS.Stat(cliPath)
Expand Down
4 changes: 4 additions & 0 deletions executor/runtime_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func runtimeFlags(cfg execute.BLSRuntimeConfig, permissions []string) []string {
flags = append(flags, "--"+execute.BLSRuntimeFlagFSRoot, cfg.FSRoot)
}

if cfg.DriversRootPath != "" {
flags = append(flags, "--"+execute.BLSRuntimeFlagDrivers, cfg.DriversRootPath)
}

if cfg.Fuel > 0 {
flags = append(flags, "--"+execute.BLSRuntimeFlagFuel, fmt.Sprint(cfg.Fuel))
}
Expand Down
2 changes: 2 additions & 0 deletions models/execute/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type BLSRuntimeConfig struct {
Fuel uint64 `json:"limited_fuel,omitempty"`
Memory uint64 `json:"limited_memory,omitempty"`
Logger string `json:"runtime_logger,omitempty"`
DriversRootPath string `json:"drivers_root_path,omitempty"`
// Fields not allowed to be set in the request.
Input string `json:"-"`
FSRoot string `json:"-"`
Expand All @@ -28,4 +29,5 @@ const (
BLSRuntimeFlagLogger = "runtime-logger"
BLSRuntimeFlagPermission = "permission"
BLSRuntimeFlagEnv = "env"
BLSRuntimeFlagDrivers = "drivers-root-path"
)

0 comments on commit e7685a5

Please sign in to comment.