Skip to content

Commit e7391e4

Browse files
committed
fix: remove appName from taskConfig and extract it from relative DotnetPath property
1 parent 4ad1185 commit e7391e4

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

dotnet/driver.go

+4-7
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

@@ -499,7 +495,8 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
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()

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)