-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathComposeFile.cs
More file actions
211 lines (184 loc) · 7.62 KB
/
ComposeFile.cs
File metadata and controls
211 lines (184 loc) · 7.62 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
namespace CreateMatrix;
internal static class ComposeFile
{
public static void Create(DirectoryInfo makeDirectory)
{
string makePath = makeDirectory.FullName;
// Create local Compose file
string composeFile = CreateComposefile(null);
string filePath = Path.Combine(makePath, "Test.yml");
Log.Logger.Information("Writing Compose file to {Path}", filePath);
File.WriteAllText(filePath, composeFile);
// Create develop Compose file
composeFile = CreateComposefile("develop");
filePath = Path.Combine(makePath, "Test-develop.yml");
Log.Logger.Information("Writing Compose file to {Path}", filePath);
File.WriteAllText(filePath, composeFile);
// Create latest Compose file
composeFile = CreateComposefile("latest");
filePath = Path.Combine(makePath, "Test-latest.yml");
Log.Logger.Information("Writing Compose file to {Path}", filePath);
File.WriteAllText(filePath, composeFile);
}
private static string CreateComposefile(string? label)
{
// TODO: Switch to volume sub-paths on Moby v26+
// https://github.com/moby/moby/pull/45687
// Compose file header
StringBuilder stringBuilder = new();
_ = stringBuilder.AppendLineCrlf(
"""
# Compose file created by CreateMatrix, do not modify by hand
"""
);
// Create volumes
_ = stringBuilder.AppendLineCrlf(CreateVolumes());
// Create services
_ = stringBuilder.AppendLineCrlf(CreateServices(label));
return stringBuilder.ToString();
}
private static string CreateVolumes()
{
StringBuilder stringBuilder = new();
_ = stringBuilder.AppendLineCrlf(
"""
volumes:
"""
);
// Create a volume for every product
foreach (ProductInfo.ProductType productType in ProductInfo.GetProductTypes())
{
// Standard
_ = stringBuilder.AppendLineCrlf(CreateVolume(productType, false));
// LSIO
_ = stringBuilder.AppendLineCrlf(CreateVolume(productType, true));
}
return stringBuilder.ToString();
}
private static string CreateVolume(ProductInfo.ProductType productType, bool lsio) =>
lsio
? $$"""
# Dockerfile : {{ProductInfo.GetDocker(productType, lsio)}}
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_config:
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_media:
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_backup:
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_analytics:
"""
: $$"""
# Dockerfile : {{ProductInfo.GetDocker(productType, lsio)}}
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_etc:
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_ini:
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_var:
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_media:
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_backup:
test_{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}_analytics:
""";
private static string CreateServices(string? label)
{
StringBuilder stringBuilder = new();
_ = stringBuilder.AppendLineCrlf(
"""
services:
"""
);
// Create a service for every product
int standardPort = 7101,
lsioPort = 7201;
foreach (ProductInfo.ProductType productType in ProductInfo.GetProductTypes())
{
// Standard
_ = stringBuilder.AppendLineCrlf(
CreateService(productType, false, standardPort++, label)
);
// LSIO
_ = stringBuilder.AppendLineCrlf(CreateService(productType, true, lsioPort++, label));
}
return stringBuilder.ToString();
}
private static string CreateService(
ProductInfo.ProductType productType,
bool lsio,
int port,
string? label
)
{
string image = string.IsNullOrEmpty(label)
? $"test_{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}"
: $"docker.io/ptr727/{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}:{label}";
string service = $$"""
# Dockerfile : {{ProductInfo.GetDocker(productType, lsio)}}
# Port : {{port}}
{{ProductInfo.GetDocker(productType, lsio).ToLowerInvariant()}}:
image: {{image}}
container_name: {{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}-container
restart: unless-stopped
environment:
- TZ=Americas/Los_Angeles
network_mode: bridge
ports:
- {{port}}:7001
""";
if (lsio)
{
service += $$"""
volumes:
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_config:/config
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_media:/media
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_backup:/backup
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_analytics:/analytics
""";
}
else
{
service += $$"""
volumes:
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_etc:/opt/{{ProductInfo.GetCompany(
productType
).ToLowerInvariant()}}/mediaserver/etc
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_ini:/home/{{ProductInfo.GetCompany(
productType
).ToLowerInvariant()}}/.config/nx_ini
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_var:/opt/{{ProductInfo.GetCompany(
productType
).ToLowerInvariant()}}/mediaserver/var
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_media:/media
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_backup:/backup
- test_{{ProductInfo.GetDocker(
productType,
lsio
).ToLowerInvariant()}}_analytics:/analytics
""";
}
return service;
}
}