-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerCli.fs
47 lines (41 loc) · 2.03 KB
/
DockerCli.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
namespace Albelli
open Fake
open Fake.Core
module DockerCli =
let login (username: string) (password: string) (url: string) =
let args =
Arguments.Empty
|> Arguments.append ["login"]
|> Arguments.appendNotEmpty "-u" username
|> Arguments.appendNotEmpty "-p" password
|> Arguments.append [url]
|> Arguments.toArray
let proc =
CreateProcess.fromRawCommand "docker" args
|> CreateProcess.redirectOutput
|> Proc.run
if proc.ExitCode <> 0 then failwithf "docker login failed with exit code %i and message %s" proc.ExitCode proc.Result.Error
let build' (dockerfilePath: string) (dockerImageTag: string) (contextDirectory: string) =
let args =
Arguments.Empty
|> Arguments.append ["build"]
|> Arguments.appendNotEmpty "-f" dockerfilePath
|> Arguments.appendNotEmpty "-t" dockerImageTag
|> Arguments.append [contextDirectory]
|> Arguments.toArray
let proc =
CreateProcess.fromRawCommand "docker" args
|> CreateProcess.redirectOutput
|> Proc.run
if proc.ExitCode <> 0 then failwithf "docker build failed with exit code %i and message %s" proc.ExitCode proc.Result.Error
let build (dockerImageTag: string) (contextDirectory: string) = build' "Dockerfile" dockerImageTag contextDirectory
let push (dockerImageTag: string) =
let args =
Arguments.Empty
|> Arguments.append ["push"; dockerImageTag]
|> Arguments.toArray
let proc =
CreateProcess.fromRawCommand "docker" args
|> CreateProcess.redirectOutput
|> Proc.run
if proc.ExitCode <> 0 then failwithf "docker push failed with exit code %i and message %s" proc.ExitCode proc.Result.Error