-
Notifications
You must be signed in to change notification settings - Fork 136
/
dotnet.go
117 lines (100 loc) · 3.21 KB
/
dotnet.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
var (
defaultDotnetDockerImg = "mcr.microsoft.com/dotnet/sdk:3.1.417-buster"
releaseTag string
useSystemCerts bool
)
func initializeDotnetRequirements() {
releaseTag = getEnvWithDefault("RELEASE_TAG", "UNKNOWN_TAG")
}
func sslCerts() error {
fmt.Println("Setting up SSL certificates...")
sslCertsDir := filepath.Join(".", "build", "ssl", "certs")
err := os.MkdirAll(sslCertsDir, os.ModePerm)
if err != nil {
return err
}
if _, err := os.Stat("/etc/ssl/certs/ca-certificates.crt"); err == nil {
err = sh.Run("cp", "/etc/ssl/certs/ca-certificates.crt", filepath.Join(sslCertsDir, "ca-certificates.crt"))
if err != nil {
return err
}
} else if _, err := os.Stat("/etc/ssl/certs/ca-bundle.crt"); err == nil {
err = sh.Run("cp", "/etc/ssl/certs/ca-bundle.crt", filepath.Join(sslCertsDir, "ca-certificates.crt"))
if err != nil {
return err
}
} else if runtime.GOOS == "darwin" {
err = sh.Run("security", "find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain", ">>", filepath.Join(sslCertsDir, "ca-certificates.crt"))
if err != nil {
return err
}
err = sh.Run("security", "find-certificate", "-a", "-p", "/Library/Keychains/System.keychain", ">>", filepath.Join(sslCertsDir, "ca-certificates.crt"))
if err != nil {
return err
}
err = sh.Run("security", "find-certificate", "-a", "-p", "~/Library/Keychains/login.keychain-db", ">>", filepath.Join(sslCertsDir, "ca-certificates.crt"))
if err != nil {
return err
}
} else {
return fmt.Errorf("don't know where to find root CA certs")
}
return nil
}
func dotnetSetup() error {
fmt.Println("Setting up Dotnet...")
if useSystemCerts {
err := sslCerts()
if err != nil {
return err
}
}
return nil
}
// Target for compiling the dotnet Armada REST client
func Dotnet() error {
mg.Deps(initializeDotnetRequirements, dotnetSetup, BootstrapProto)
fmt.Println("Building Dotnet...")
dotnetCmd := dotnetCmd()
client := append(dotnetCmd, "dotnet", "build", "./client/DotNet/Armada.Client", "/t:NSwag")
output, err := dockerOutput(client...)
fmt.Println(output)
if err != nil {
return err
}
client = append(dotnetCmd, "dotnet", "build", "./client/DotNet/ArmadaProject.Io.Client")
output, err = dockerOutput(client...)
fmt.Println(output)
if err != nil {
return err
}
return nil
}
// Pack dotnet clients nuget. Requires RELEASE_TAG env var to be set
func PackNuget() error {
mg.Deps(initializeDotnetRequirements, dotnetSetup, Proto)
fmt.Println("Pack Nuget...")
dotnetCmd := dotnetCmd()
build := append(dotnetCmd, "dotnet", "pack", "client/DotNet/Armada.Client/Armada.Client.csproj", "-c", "Release", "-p:PackageVersion="+releaseTag, "-o", "./bin/client/DotNet")
output, err := dockerOutput(build...)
fmt.Println(output)
if err != nil {
return err
}
build = append(dotnetCmd, "dotnet", "pack", "client/DotNet/ArmadaProject.Io.Client/ArmadaProject.Io.Client.csproj", "-c", "Release", "-p:PackageVersion="+releaseTag, "-o", "./bin/client/DotNet")
output, err = dockerOutput(build...)
fmt.Println(output)
if err != nil {
return err
}
return nil
}