-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.fsx
95 lines (75 loc) · 3.01 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "packages/FAKE/tools/FakeLib.dll"
open Fake
open System
open System.IO
open FSharp.Data
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let fsiPath = "packages/FSharp.Compiler.Tools/tools/fsiAnyCpu.exe"
// --------------------------------------------------------------------------------------
// For deployed run - compile as an executable
// --------------------------------------------------------------------------------------
Target "clean" (fun _ ->
CleanDirs ["bin"]
)
Target "build" (fun _ ->
[ "gallery-csv-service.sln" ]
|> MSBuildRelease "" "Rebuild"
|> Log ""
)
"clean" ==> "build"
// --------------------------------------------------------------------------------------
// For local run - automatically reloads scripts
// --------------------------------------------------------------------------------------
let startServers () =
ExecProcessWithLambdas
(fun info ->
info.FileName <- System.IO.Path.GetFullPath fsiPath
info.Arguments <- "--load:src/debug.fsx"
info.WorkingDirectory <- __SOURCE_DIRECTORY__)
TimeSpan.MaxValue false ignore ignore
Target "start" (fun _ ->
async { return startServers() }
|> Async.Ignore
|> Async.Start
let mutable started = false
while not started do
try
use wc = new System.Net.WebClient()
started <- wc.DownloadString("http://localhost:8897/") |> String.IsNullOrWhiteSpace |> not
with _ ->
System.Threading.Thread.Sleep(1000)
printfn "Waiting for servers to start...."
traceImportant "Servers started...."
System.Diagnostics.Process.Start("http://localhost:8897/") |> ignore
)
Target "run" (fun _ ->
traceImportant "Press any key to stop!"
Console.ReadLine() |> ignore
)
"start" ==> "run"
// --------------------------------------------------------------------------------------
// Azure - deploy copies the binary to wwwroot/bin
// --------------------------------------------------------------------------------------
let newName prefix f =
Seq.initInfinite (sprintf "%s_%d" prefix) |> Seq.skipWhile (f >> not) |> Seq.head
Target "deploy" (fun _ ->
// Pick a subfolder that does not exist
let wwwroot = "../wwwroot"
let subdir = newName "deploy" (fun sub -> not (Directory.Exists(wwwroot </> sub)))
// Deploy everything into new empty folder
let deployroot = wwwroot </> subdir
CleanDir deployroot
CleanDir (deployroot </> "bin")
CopyRecursive "bin" (deployroot </> "bin") false |> ignore
let config = File.ReadAllText("web.config").Replace("%DEPLOY_SUBDIRECTORY%", subdir)
File.WriteAllText(wwwroot </> "web.config", config)
// Try to delete previous folders, but ignore failures
for dir in Directory.GetDirectories(wwwroot) do
if Path.GetFileName(dir) <> subdir then
try CleanDir dir; DeleteDir dir with _ -> ()
)
"build" ==> "deploy"
RunTargetOrDefault "run"