-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.cake
74 lines (62 loc) · 2.85 KB
/
build.cake
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
#addin nuget:?package=Cake.Docker&version=0.9.7
using System.Runtime.InteropServices;
using System.Linq;
using System.IO;
using Path = System.IO.Path;
using System.Net.Sockets;
var target = Argument("target", "Setup");
var containerNameOracleDb = "oracle-db-container";
var imageNameOracleDb = "oracle-db-image";
var dockerUsername = Argument("dockerUsername", "");
var dockerPassword = Argument("dockerPassword", "");
Task("DockerLogin")
.Description("Login to docker with Ticket CI credentials")
.Does(() => {
StartProcess("docker", new ProcessSettings
{
Arguments = $"login -u {dockerUsername} -p {dockerPassword}"
});
});
Task("FollowContainerLogs")
.Description("Follow Oracle Db container logs.")
.Does(() => {
StartProcess("docker", new ProcessSettings { Arguments = $"logs {containerNameOracleDb} -f" });
});
Task("CreateContainerImage")
.Description("Creates Oracle dev image.")
.Does(() => {
StartProcess("docker", new ProcessSettings
{
Arguments = $"build -t {imageNameOracleDb} ." ,
WorkingDirectory = "."
});
});
Task("RemoveContainer")
.Description("Stop and Remove Oracle container.")
.Does(() => StartProcess("docker", new ProcessSettings { Arguments = $"rm -f {containerNameOracleDb}" }))
.Does(() => StartProcess("docker", new ProcessSettings { Arguments = $"volume prune -f"}));
Task("RunContainer")
.Description("Runs a new container for Oracle Db.")
.IsDependentOn("RemoveContainer")
.Does(() => {
var hostPath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "volume");
StartProcess("docker", new ProcessSettings { Arguments = $"run --name={containerNameOracleDb} -d -p 8081:8080 -p 22:22 -p 1521:1521 -v {hostPath}:/volume {imageNameOracleDb}" });
});
Task("WaitContainerStartComplete")
.Description("Waits for the Oracle Db container to finish starting.")
.Does(() => {
DockerExec(containerNameOracleDb, "bash", "-c", "\"while ! test -f /home/oracle/setup/.sqlinitdone && ! test -f /home/oracle/setup/.sqliniterror; do echo Waiting for Db start...; sleep 5; done\"");
});
Task("SetupAndWaitContainer")
.Description("Creates Oracle Db container image, runs its container and wait for it to finish.")
.IsDependentOn("SetupImageAndContainer")
.IsDependentOn("WaitContainerStartComplete");
Task("SetupContainer")
.Description("Creates Oracle Db container image and runs its container.")
.IsDependentOn("SetupImageAndContainer")
.IsDependentOn("FollowContainerLogs");
Task("SetupImageAndContainer")
.Description("Creates Oracle Db container image and runs its container.")
.IsDependentOn("CreateContainerImage")
.IsDependentOn("RunContainer");
RunTarget(target);