-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
121 lines (94 loc) · 2.83 KB
/
build.fsx
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
119
120
121
#r @"packages/build/FAKE/tools/FakeLib.dll"
open System
open Fake
let serverPath = "./src/Server" |> FullName
let clientPath = "./src/Client" |> FullName
let deployDir = "./deploy" |> FullName
let platformTool tool winTool =
let tool = if isUnix then tool else winTool
tool
|> ProcessHelper.tryFindFileOnPath
|> function Some t -> t | _ -> failwithf "%s not found" tool
let nodeTool = platformTool "node" "node.exe"
let yarnTool = platformTool "yarn" "yarn.cmd"
let dotnetcliVersion = DotNetCli.GetDotNetSDKVersionFromGlobalJson()
let mutable dotnetCli = "dotnet"
let run cmd args workingDir =
let result =
ExecProcess (fun info ->
info.FileName <- cmd
info.WorkingDirectory <- workingDir
info.Arguments <- args) TimeSpan.MaxValue
if result <> 0 then failwithf "'%s %s' failed" cmd args
Target "Clean" (fun _ ->
CleanDirs [deployDir]
)
Target "InstallDotNetCore" (fun _ ->
dotnetCli <- DotNetCli.InstallDotNetSDK dotnetcliVersion
)
Target "InstallClient" (fun _ ->
printfn "Node version:"
run nodeTool "--version" __SOURCE_DIRECTORY__
printfn "Yarn version:"
run yarnTool "--version" __SOURCE_DIRECTORY__
run yarnTool "install --frozen-lockfile" __SOURCE_DIRECTORY__
run dotnetCli "restore" clientPath
)
Target "RestoreServer" (fun () ->
run dotnetCli "restore" serverPath
)
Target "Build" (fun () ->
run dotnetCli "build" serverPath
run dotnetCli "fable webpack -- -p" clientPath
)
Target "Run" (fun () ->
let server = async {
run dotnetCli "watch run" serverPath
}
let client = async {
run dotnetCli "fable webpack-dev-server" clientPath
}
let browser = async {
Threading.Thread.Sleep 5000
Diagnostics.Process.Start "http://localhost:8080" |> ignore
}
[ server; client; browser]
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
)
Target "Bundle" (fun _ ->
let serverDir = deployDir </> "Server"
let clientDir = deployDir </> "Client"
let publicDir = clientDir </> "public"
let publishArgs = sprintf "publish -c Release -o \"%s\"" serverDir
run dotnetCli publishArgs serverPath
!! "src/Client/public/**/*.*" |> CopyFiles publicDir
!! "src/Client/index.html"
++ "src/Client/landing.css"
|> CopyFiles clientDir
)
let dockerUser = "theimowski"
let dockerImageName = "safe-demo-lambdadays"
let dockerFullName = sprintf "%s/%s" dockerUser dockerImageName
Target "Docker" (fun _ ->
let buildArgs = sprintf "build -t %s ." dockerFullName
run "docker" buildArgs "."
let tagArgs = sprintf "tag %s %s" dockerFullName dockerFullName
run "docker" tagArgs "."
)
Target "Deploy" (fun _ ->
let pushArgs = sprintf "push %s" dockerFullName
run "docker" pushArgs "."
)
"Clean"
==> "InstallDotNetCore"
==> "InstallClient"
==> "Build"
==> "Bundle"
==> "Docker"
==> "Deploy"
"InstallClient"
==> "RestoreServer"
==> "Run"
RunTargetOrDefault "Build"