-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommon.fs
More file actions
75 lines (63 loc) · 2.49 KB
/
Common.fs
File metadata and controls
75 lines (63 loc) · 2.49 KB
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
module Common
open System
open Fake.Core
open Fake.DotNet
let tee f x =
f x |> ignore
x
let invokeAsync f = async { f () }
let isRelease (targets : Target list) =
targets
|> Seq.map(fun t -> t.Name)
|> Seq.exists ((=)"CreateRelease")
let configuration (targets : Target list) =
let defaultVal = if isRelease targets then "Release" else "Debug"
match Environment.environVarOrDefault "CONFIGURATION" defaultVal with
| "Debug" -> DotNet.BuildConfiguration.Debug
| "Release" -> DotNet.BuildConfiguration.Release
| config -> DotNet.BuildConfiguration.Custom config
let DotNetWatch watchCmd workingDir =
DotNet.exec
(fun p ->
{ p with WorkingDirectory = workingDir
CustomParams = Some "--no-hot-reload" })
(sprintf "watch %s" watchCmd)
""
|> ignore
let DotNetRun workingDir =
DotNet.exec
(fun p -> { p with WorkingDirectory = workingDir })
(sprintf "run")
""
|> ignore
let runMigrations migrationsPath connectionString =
let args = sprintf "--connectionstring \"%s\"" connectionString
DotNet.exec (fun o -> { o with WorkingDirectory = migrationsPath }) "run" args
|> (fun res -> if not res.OK then String.Join(", ", res.Errors) |> failwith)
module Tools =
let platformTool tool winTool =
let tool = if Environment.isUnix then tool else winTool
match ProcessUtils.tryFindFileOnPath tool with
| Some t -> t
| _ ->
let errorMsg =
tool + " was not found in path. " +
"Please install it and make sure it's available from your path. " +
"See https://safe-stack.github.io/docs/quickstart/#install-pre-requisites for more info"
failwith errorMsg
let docker = platformTool "docker" "docker.exe"
let helm = platformTool "helm" "helm.exe"
let kubectl = platformTool "kubectl" "kubectl.exe"
let private createProcess cmd args workingDir =
let arguments = args |> Arguments.OfArgs
Command.RawCommand (cmd, arguments)
|> CreateProcess.fromCommand
|> CreateProcess.withWorkingDirectory workingDir
|> CreateProcess.ensureExitCode
let runTool cmd args workingDir =
createProcess cmd args workingDir
|> Proc.run
|> ignore
let docker (args: string list) = Tools.runTool Tools.docker args
let kubectl (args: string list) = Tools.runTool Tools.kubectl args
let helm (args: string list) = Tools.runTool Tools.helm args