-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.fs
118 lines (97 loc) · 3.16 KB
/
Build.fs
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
118
open Fake.Core
open Fake.IO
open Fake.IO.FileSystemOperators
open Farmer
open Farmer.Builders
open Helpers
initializeContext()
let root = __SOURCE_DIRECTORY__
let sharedPath = Path.getFullName "src/Shared"
let serverPath = Path.getFullName "src/Server"
let clientPath = Path.getFullName "src/Client"
let deployPath = Path.getFullName "deploy"
let sharedTestsPath = Path.getFullName "tests/Shared"
let serverTestsPath = Path.getFullName "tests/Server"
let clientTestsPath = Path.getFullName "tests/Client"
Target.create "Clean" (fun _ ->
Shell.cleanDir deployPath
Shell.cleanDir (clientPath @@ "output")
)
Target.create "InstallClient" (fun _ -> run yarn "install" root)
Target.create "Bundle" (fun _ ->
[ "server", dotnet $"publish -c Release -o \"{deployPath}\"" serverPath
"client", yarn "bundle" root]
|> runParallel
)
Target.create "Azure" (fun _ ->
let vaultName = "VatsimLiveFeedback-vault"
let secretRef name = $"@Microsoft.KeyVault(VaultName={vaultName};SecretName={name})"
let secrets = [
"VLF_OAuth__ClientId", "oauth-client-id"
"VLF_OAuth__ClientSecret", "oauth-client-secret"
]
let secretSettings = secrets |> List.map (fun (key,name) -> key, secretRef name)
let web = webApp {
name "VatsimLiveFeedback"
zip_deploy "deploy"
link_to_keyvault (ResourceName vaultName)
settings secretSettings
system_identity
runtime_stack Runtime.DotNet50
}
let emptySecret secretName = secret {
name secretName
value (ArmExpression.literal "")
}
let vaultUser =
Environment.environVarOrNone "VLF_KEYVAULT_USER_OBJECTID"
|> Option.bind (fun s -> match System.Guid.TryParse(s) with true, guid -> ObjectId guid |> Some | _ -> None)
let vault = keyVault {
name vaultName
add_secrets (secrets |> List.map (fun (_, name) -> emptySecret name))
add_access_policies [
AccessPolicy.create (web.SystemIdentity, [KeyVault.Secret.List; KeyVault.Secret.Get])
if vaultUser.IsSome then
AccessPolicy.create (vaultUser.Value, KeyVault.Secret.All)
]
}
let deployment = arm {
location Location.WestEurope
add_resources [
web
vault
]
}
deployment
|> Deploy.execute "VatsimLiveFeedback" Deploy.NoParameters
|> ignore
)
Target.create "Run" (fun _ ->
run dotnet "build" sharedPath
[ "server", dotnet "watch run" serverPath
"client", yarn "start" root ]
|> runParallel
)
Target.create "RunTests" (fun _ ->
run dotnet "build" sharedTestsPath
[ "server", dotnet "watch run" serverTestsPath
"client", dotnet "fable watch -o output -s --run webpack-dev-server --config ../../webpack.tests.config.js" clientTestsPath ]
|> runParallel
)
Target.create "Format" (fun _ ->
run dotnet "fantomas . -r" "src"
)
open Fake.Core.TargetOperators
let dependencies () = [
"Clean"
==> "InstallClient"
==> "Bundle"
==> "Azure"
"Clean"
==> "InstallClient"
==> "Run"
"InstallClient"
==> "RunTests"
]
[<EntryPoint>]
let main args = runOrDefault args dependencies