-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuild.fs
119 lines (98 loc) · 3.66 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
119
open Azure.Data.Tables
open Fake.Core
open Fake.IO
open Farmer
open Farmer.Builders
open Farmer.Search
open Helpers
open System.Text.RegularExpressions
initializeContext()
let sharedPath = Path.getFullName "src/Shared"
let serverPath = Path.getFullName "src/Server"
let clientPath = Path.getFullName "src/Client"
let deployPath = Path.getFullName "deploy"
Target.create "Clean" (fun _ ->
Shell.cleanDir deployPath
run dotnet "fable clean --yes" clientPath
)
Target.create "InstallClient" (fun _ -> run npm "install" ".")
Target.create "Bundle" (fun _ ->
[ "server", dotnet $"publish -c Release -o \"{deployPath}\"" serverPath
"client", dotnet "fable -o output --run npm run build" clientPath ]
|> runParallel
)
Target.create "Azure" (fun _ ->
let searchName : string = "REPLACE WITH AZURE SEARCH NAME"
let storageName : string = "REPLACE WITH STORAGE NAME"
let appServiceName : string = "REPLACE WITH AZURE APP SERVICE NAME"
let azCopyPath : string option = None //REPLACE WITH PATH TO AZCOPY.EXE e.g Some "C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy\AzCopy.exe"
let azureSearch = search {
name searchName
sku Basic
}
let storage = storageAccount {
name storageName
add_private_container "properties"
add_table "postcodes"
}
let web = webApp {
name $"{appServiceName}"
always_on
sku WebApp.Sku.B1
operating_system Linux
runtime_stack Runtime.DotNet80
setting "storageName" storageName
setting "storageConnectionString" storage.Key
setting "searchName" searchName
setting "searchKey" azureSearch.AdminKey
zip_deploy "deploy"
}
let deployment = arm {
location Location.WestEurope
add_resource web
add_resource azureSearch
add_resource storage
output "storageConnectionString" storage.Key
}
// Deploy above resources to Azure
let outputs =
deployment
|> Deploy.execute "SAFE Search 3" Deploy.NoParameters
let connectionString = outputs.["storageConnectionString"]
let accountName, accountKey =
let matcher = Regex.Match(connectionString, "AccountName=(?<AccountName>.*);.*AccountKey=(?<AccountKey>.*)(;|$)")
matcher.Groups.["AccountName"].Value, matcher.Groups.["AccountKey"].Value
let lookupNeedsPriming =
let destinationTable =
let tableClient = TableServiceClient connectionString
tableClient.GetTableClient "postcodes"
destinationTable.Query<TableEntity>(maxPerPage = 1) |> Seq.isEmpty
if lookupNeedsPriming then
let azCopyPath =
azCopyPath
|> Option.defaultWith(fun () -> failwith "No azcopy path found. Please see the readme file for ways to do this manually")
printfn "No data found - now seeding postcode / geo-location lookup table with ~1.8m entries. This will take a few minutes."
CreateProcess.fromRawCommandLine $"{azCopyPath}" $"copy https://compositionalit.blob.core.windows.net/postcodedata https://{storageName}.table.core.windows.net/postcodes --recursive"
|> Proc.run
|> ignore
else
printfn "Postcode lookup already exists, no seeding is required."
)
Target.create "Run" (fun _ ->
run dotnet "build" sharedPath
[ "server", dotnet "watch run" serverPath
"client", dotnet "fable watch -o output --run npm run start" clientPath ]
|> runParallel
)
open Fake.Core.TargetOperators
let dependencies = [
"Clean"
==> "InstallClient"
==> "Bundle"
==> "Azure"
"Clean"
==> "InstallClient"
==> "Run"
]
[<EntryPoint>]
let main args = runOrDefault args