-
Notifications
You must be signed in to change notification settings - Fork 4
/
dotnet_dockerfile.go
57 lines (45 loc) · 1.13 KB
/
dotnet_dockerfile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dockerfile
import (
"fmt"
"os"
"os/exec"
"regexp"
"github.com/FelipeMCassiano/gorvus/internal/builders"
"github.com/jedib0t/go-pretty/v6/text"
)
func DotNetDockerFileBuilder(input DockerfileData) error {
if len(input.ProjectName) == 0 {
pN, err := setProjectName()
if err != nil {
os.Exit(1)
}
input.ProjectName = pN
}
if len(input.EntryFile) >= 1 {
fmt.Println(text.FgYellow.Sprintf("> This language doens't needs to specify the Entry File"))
os.Exit(1)
}
cmd := exec.Command("dotnet", "--version")
dotnetVersionOutput, err := cmd.CombinedOutput()
if err != nil {
return err
}
versionPattern := `(\d+)\.`
re := regexp.MustCompile(versionPattern)
matches := re.FindStringSubmatch(string(dotnetVersionOutput))
if len(matches) < 2 {
return fmt.Errorf("failed to extract Dotnet version number")
}
input.Version = matches[1]
datafile, err := templatesContent.ReadFile("templates/dotnet_dockerfile.tmpl")
if err != nil {
return err
}
file, err := os.Create("Dockerfile")
if err != nil {
return err
}
defer file.Close()
builders.ApplyTemplate(file, string(datafile), input)
return nil
}