Skip to content

Commit

Permalink
Merge pull request #148 from ptr727/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ptr727 authored Apr 12, 2024
2 parents d6bab91 + e7f0830 commit 6570fd6
Show file tree
Hide file tree
Showing 51 changed files with 1,661 additions and 633 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/DockerHubDescription.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
ptr727/nxwitness-lsio,
ptr727/dwspectrum,
ptr727/dwspectrum-lsio,
ptr727/wisenetwave,
ptr727/wisenetwave-lsio,
]

steps:
Expand Down
11 changes: 11 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"recommendations": [
"yzhang.markdown-all-in-one",
"ms-dotnettools.csharp",
"ms-azuretools.vscode-docker",
"github.vscode-github-actions",
"ms-dotnettools.vscode-dotnet-runtime",
"ms-dotnettools.csdevkit",
"streetsidesoftware.code-spell-checker"
]
}
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/CreateMatrix/bin/Debug/net8.0/CreateMatrix.dll",
"args": ["schema"],
"args": ["schema", "--schemaversion=./JSON/Version.schema.json", "--schemamatrix=./JSON/Matrix.schema.json"],
"cwd": "${workspaceFolder}/CreateMatrix/JSON",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "Update Make Files",
"name": "Create Docker and Compose Files",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/CreateMatrix/bin/Debug/net8.0/CreateMatrix.dll",
"args": ["make", "--matrix=./Make/Matrix.json"],
"args": ["make", "--version=./Make/Version.json", "--make=./Make", "--docker=./Docker", "--label=Beta"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
Expand Down
161 changes: 161 additions & 0 deletions CreateMatrix/ComposeFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
using System.Text;
using Serilog;

namespace CreateMatrix;

public class ComposeFile
{
public static void Create(string makePath)
{
// Create local Compose file
var composeFile = CreateComposefile(null);
var filePath = Path.Combine(makePath, "Test.yml");
Log.Logger.Information("Writing Compose file to {Path}", filePath);
File.WriteAllText(filePath, composeFile, Encoding.UTF8);

// 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, Encoding.UTF8);

// 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, Encoding.UTF8);
}

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
var stringBuilder = new StringBuilder();
stringBuilder.Append("""
# Compose file created by CreateMatrix, do not modify by hand
""");
stringBuilder.AppendLine();

// Create volumes
stringBuilder.Append(CreateVolumes());
stringBuilder.AppendLine();

// Create services
stringBuilder.Append(CreateServices(label));
stringBuilder.AppendLine();

return stringBuilder.ToString().Replace("\r\n", "\n").Trim();
}

private static string CreateVolumes()
{
var stringBuilder = new StringBuilder();
stringBuilder.Append("""
volumes:
""");
stringBuilder.AppendLine();

// Create a volume for every product
foreach (var productType in ProductInfo.GetProductTypes())
{
// Standard
stringBuilder.Append(CreateVolume(productType, false));
stringBuilder.AppendLine();

// LSIO
stringBuilder.Append(CreateVolume(productType, true));
stringBuilder.AppendLine();
}

return stringBuilder.ToString();
}

private static string CreateVolume(ProductInfo.ProductType productType, bool lsio)
{
if (lsio)
return $$"""
# Dockerfile : {{ProductInfo.GetDocker(productType, lsio)}}
test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_config:
test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_media:
""";
else
return $$"""
# Dockerfile : {{ProductInfo.GetDocker(productType, lsio)}}
test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_etc:
test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_ini:
test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_var:
test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_media:
"""
;
}

private static string CreateServices(string? label)
{
var stringBuilder = new StringBuilder();
stringBuilder.Append("""
services:
""");
stringBuilder.AppendLine();

// Create a service for every product
int standardPort = 7101, lsioPort = 7201;
foreach (var productType in ProductInfo.GetProductTypes())
{
// Standard
stringBuilder.Append(CreateService(productType, false, standardPort ++, label));
stringBuilder.AppendLine();

// LSIO
stringBuilder.Append(CreateService(productType, true, lsioPort ++, label));
stringBuilder.AppendLine();
}

return stringBuilder.ToString();
}

private static string CreateService(ProductInfo.ProductType productType, bool lsio, int port, string? label)
{
var image = string.IsNullOrEmpty(label) ? $"test_{ProductInfo.GetDocker(productType, lsio).ToLower()}" : $"docker.io/ptr727/{ProductInfo.GetDocker(productType, lsio).ToLower()}:{label}";
var service = $$"""
# Dockerfile : {{ProductInfo.GetDocker(productType, lsio)}}
# Port : {{port}}
{{ProductInfo.GetDocker(productType, lsio).ToLower()}}:
image: {{image}}
container_name: {{ProductInfo.GetDocker(productType, lsio).ToLower()}}-container
restart: unless-stopped
environment:
- TZ=Americas/Los_Angeles
network_mode: bridge
ports:
- {{port}}:7001
""";

if (lsio)
service += $$"""
volumes:
- test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_config:/config
- test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_media:/media
""";
else
service += $$"""
volumes:
- test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_etc:/opt/{{ProductInfo.GetCompany(productType).ToLower()}}/mediaserver/etc
- test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_ini:/home/{{ProductInfo.GetCompany(productType).ToLower()}}/.config/nx_ini
- test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_var:/opt/{{ProductInfo.GetCompany(productType).ToLower()}}/mediaserver/var
- test_{{ProductInfo.GetDocker(productType, lsio).ToLower()}}_media:/media
""";

return service;
}
}
Loading

0 comments on commit 6570fd6

Please sign in to comment.