Skip to content

Commit 47f0432

Browse files
authored
Merge pull request #14 from TibaGroup/fix/task-conf
Use Relative Paths and Extract App Name from DLL's name
2 parents 23b7867 + e7391e4 commit 47f0432

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

dotnet/driver.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ var (
9797
// but that's not expressible in hclspec. Marking both as optional
9898
// and setting checking explicitly later
9999
"dll_path": hclspec.NewAttr("dll_path", "string", true),
100-
"app_name": hclspec.NewAttr("app_name", "string", true),
101100
"runtime_version": hclspec.NewAttr("runtime_version", "string", false),
102101
"gc": hclspec.NewBlock("gc", false, hclspec.NewObject(map[string]*hclspec.Spec{
103102
"enable": hclspec.NewAttr("enable", "bool", false),
@@ -212,9 +211,6 @@ type TaskConfig struct {
212211
// DotnetPath indicates where a dll file is found.
213212
DotnetPath string `codec:"dll_path"`
214213

215-
// AppName indicates the .Net application name.
216-
AppName string `codec:"app_name"`
217-
218214
// SdkVersion indicates which version of dotnet the task must be run
219215
RuntimeVersion *string `codec:"runtime_version"`
220216

@@ -492,14 +488,15 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
492488
return nil, nil, err
493489
}
494490

495-
args := dotnetCmdArgs(taskConfig)
491+
args := dotnetCmdArgs(*cfg, taskConfig)
496492

497493
var fileConfig = new(ConfigFile)
498494
addGcConfig(taskConfig.GC, fileConfig)
499495
addGlobalizationConfig(taskConfig.Globalization, fileConfig)
500496
addThreadingConfig(taskConfig.Threading, fileConfig)
501497

502-
dotnetConfigPath := path.Join(cfg.TaskDir().LocalDir, fmt.Sprintf("%s.runtimeconfig.json", taskConfig.AppName))
498+
appName, _ := getDotnetAppName(taskConfig.DotnetPath)
499+
dotnetConfigPath := path.Join(cfg.TaskDir().LocalDir, fmt.Sprintf("%s.runtimeconfig.json", appName))
503500

504501
if content, err := os.ReadFile(dotnetConfigPath); !os.IsNotExist(err) {
505502
var parsedConfig = new(ConfigFile)
@@ -514,10 +511,10 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
514511
data, _ := json.Marshal(fileConfig)
515512
fo, err := os.Create(dotnetConfigPath)
516513
if err != nil {
517-
return nil, nil, fmt.Errorf("failed to create %s.runtimeconfig.json: %v", taskConfig.AppName, err)
514+
return nil, nil, fmt.Errorf("failed to create %s.runtimeconfig.json: %v", appName, err)
518515
}
519516
if _, err := fo.Write(data); err != nil {
520-
return nil, nil, fmt.Errorf("failed to write %s.runtimeconfig.json: %v", taskConfig.AppName, err)
517+
return nil, nil, fmt.Errorf("failed to write %s.runtimeconfig.json: %v", appName, err)
521518
}
522519
defer func(fo *os.File) {
523520
err := fo.Close()
@@ -625,7 +622,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
625622
return handle, nil, nil
626623
}
627624

628-
func dotnetCmdArgs(taskConfig TaskConfig) []string {
625+
func dotnetCmdArgs(driverConfig drivers.TaskConfig, taskConfig TaskConfig) []string {
629626
var args []string
630627

631628
//Add runtime version
@@ -635,7 +632,7 @@ func dotnetCmdArgs(taskConfig TaskConfig) []string {
635632

636633
// Add the dll
637634
if taskConfig.DotnetPath != "" {
638-
args = append(args, taskConfig.DotnetPath)
635+
args = append(args, fmt.Sprintf("%s/%s", driverConfig.TaskDir().LocalDir, taskConfig.DotnetPath))
639636
}
640637

641638
// Add any args

dotnet/utils.go

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ var (
1717
runtimeVersionRe = regexp.MustCompile(`\b\d+\.\d+\.\d+\b`)
1818
)
1919

20+
func getDotnetAppName(dotnetPath string) (string, error) {
21+
re := regexp.MustCompile(`([^/]+)\.dll$`)
22+
match := re.FindStringSubmatch(dotnetPath)
23+
if len(match) > 1 {
24+
return match[1], nil
25+
} else {
26+
return "", fmt.Errorf("could not extract app name from %s", dotnetPath)
27+
}
28+
}
2029
func getDotnetPath() (string, error) {
2130
switch runtime.GOOS {
2231
case "windows":

example/example.nomad

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ job "example" {
44
driver = "dotnet"
55

66
config {
7-
dll_path = "${NOMAD_TASK_DIR}/TestNomadTask.dll"
8-
app_name = "TestNomadTask"
7+
dll_path = "TestNomadTask.dll"
98
runtime_version = "8.0.8"
109
threading {
1110
min_threads = 10
@@ -32,8 +31,7 @@ job "example" {
3231
driver = "dotnet"
3332

3433
config {
35-
dll_path = "${NOMAD_TASK_DIR}/TestNomadTask.dll"
36-
app_name = "TestNomadTask"
34+
dll_path = "TestNomadTask.dll"
3735
runtime_version = "7.0.20"
3836
threading {
3937
min_threads = 10

0 commit comments

Comments
 (0)