Skip to content

Commit

Permalink
Merge pull request #2 from NotNite/static-folder
Browse files Browse the repository at this point in the history
  • Loading branch information
goaaats committed Jul 19, 2022
2 parents 0fbfa66 + d070449 commit 299219c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 62 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build Plogon
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v2
with:
dotnet-version: "6.0.x"
- name: Install dependencies
working-directory: Plogon
run: dotnet restore
- name: Build
working-directory: Plogon
run: dotnet build --configuration Release --no-restore
117 changes: 62 additions & 55 deletions Plogon/BuildProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,57 @@ public class BuildProcessor
private readonly DirectoryInfo repoFolder;
private readonly DirectoryInfo manifestFolder;
private readonly DirectoryInfo workFolder;
private readonly DirectoryInfo staticFolder;


private readonly DockerClient dockerClient;

private PluginRepository pluginRepository;
private ManifestStorage manifestStorage;
private DalamudReleases dalamudReleases;

private const string DOCKER_IMAGE = "mcr.microsoft.com/dotnet/sdk";
private const string DOCKER_TAG = "6.0.300";

public BuildProcessor(DirectoryInfo repoFolder, DirectoryInfo manifestFolder, DirectoryInfo workFolder)
public BuildProcessor(DirectoryInfo repoFolder, DirectoryInfo manifestFolder, DirectoryInfo workFolder,
DirectoryInfo staticFolder)
{
this.repoFolder = repoFolder;
this.manifestFolder = manifestFolder;
this.workFolder = workFolder;
this.staticFolder = staticFolder;

this.pluginRepository = new PluginRepository(repoFolder);
this.manifestStorage = new ManifestStorage(manifestFolder);
this.dalamudReleases = new DalamudReleases(workFolder.CreateSubdirectory("dalamud_releases_work"));

this.dockerClient = new DockerClientConfiguration(new Uri("npipe://./pipe/docker_engine")).CreateClient();
this.dockerClient = new DockerClientConfiguration().CreateClient();
}

public async Task SetupDockerImage()
{
await this.dockerClient.Images.CreateImageAsync(new ImagesCreateParameters
{
//FromImage = "fedora/memcached",
FromImage = DOCKER_IMAGE,
//FromSrc = DOCKER_REPO,
Tag = DOCKER_TAG,
}, null, new Progress<JSONMessage>(progress =>
{
Log.Verbose("Docker image pull ({Id}): {Status}", progress.ID, progress.Status);
}));
{
//FromImage = "fedora/memcached",
FromImage = DOCKER_IMAGE,
//FromSrc = DOCKER_REPO,
Tag = DOCKER_TAG,
}, null,
new Progress<JSONMessage>(progress =>
{
Log.Verbose("Docker image pull ({Id}): {Status}", progress.ID, progress.Status);
}));

var images = await this.dockerClient.Images.ListImagesAsync(new ImagesListParameters
{
All = true,
});
}

public ISet<BuildTask> GetTasks()
{
var tasks = new HashSet<BuildTask>();

foreach (var channel in this.manifestStorage.Channels)
{
foreach (var manifest in channel.Value)
Expand Down Expand Up @@ -97,7 +102,7 @@ public async Task<bool> ProcessTask(BuildTask task)
//work.Delete(true);
//work.Create();
}

var repoPath = Repository.Clone(task.Manifest.Plugin.Repository, work.FullName, new CloneOptions
{
Checkout = false,
Expand All @@ -108,9 +113,9 @@ public async Task<bool> ProcessTask(BuildTask task)
return true;
}
});

var repo = new Repository(repoPath);
Commands.Fetch(repo, "origin", new string[] {task.Manifest.Plugin.Commit}, new FetchOptions
Commands.Fetch(repo, "origin", new string[] { task.Manifest.Plugin.Commit }, new FetchOptions
{
OnProgress = output =>
{
Expand All @@ -134,42 +139,43 @@ public async Task<bool> ProcessTask(BuildTask task)
}

var dalamudAssemblyDir = await this.dalamudReleases.GetDalamudAssemblyDirAsync(task.Channel);

var containerCreateResponse = await this.dockerClient.Containers.CreateContainerAsync(new CreateContainerParameters
{
Image = $"{DOCKER_IMAGE}:{DOCKER_TAG}",

// TODO: This depends on a change in DalamudPackager to extract dependencies on dev machines
// NetworkDisabled = true,

AttachStderr = true,
AttachStdout = true,
HostConfig = new HostConfig

var containerCreateResponse = await this.dockerClient.Containers.CreateContainerAsync(
new CreateContainerParameters
{
Privileged = false,
IpcMode = "none",
AutoRemove = false,
Binds = new List<string>()
Image = $"{DOCKER_IMAGE}:{DOCKER_TAG}",

// TODO: This depends on a change in DalamudPackager to extract dependencies on dev machines
// NetworkDisabled = true,

AttachStderr = true,
AttachStdout = true,
HostConfig = new HostConfig
{
$"{work.FullName}:/work/repo",
$"{dalamudAssemblyDir.FullName}:/work/dalamud:ro",
"D:\\xivbuild\\static:/static:ro",
$"{output.FullName}:/output",
Privileged = false,
IpcMode = "none",
AutoRemove = false,
Binds = new List<string>()
{
$"{work.FullName}:/work/repo",
$"{dalamudAssemblyDir.FullName}:/work/dalamud:ro",
$"{staticFolder.FullName}:/static:ro",
$"{output.FullName}:/output",
}
},
Env = new List<string>
{
$"PLOGON_PROJECT_DIR={task.Manifest.Plugin.ProjectPath}",
$"PLOGON_PLUGIN_NAME={task.InternalName}",
$"PLOGON_PLUGIN_COMMIT={task.Manifest.Plugin.Commit}",
"DALAMUD_LIB_PATH=/work/dalamud/"
},
Entrypoint = new List<string>
{
"/static/entrypoint.sh"
}
},
Env = new List<string>
{
$"PLOGON_PROJECT_DIR={task.Manifest.Plugin.ProjectPath}",
$"PLOGON_PLUGIN_NAME={task.InternalName}",
$"PLOGON_PLUGIN_COMMIT={task.Manifest.Plugin.Commit}",
"DALAMUD_LIB_PATH=/work/dalamud/"
},
Entrypoint = new List<string>
{
"/static/entrypoint.sh"
}
});

});

var startResponse =
await this.dockerClient.Containers.StartContainerAsync(containerCreateResponse.ID,
new ContainerStartParameters());
Expand All @@ -192,23 +198,24 @@ await this.dockerClient.Containers.StartContainerAsync(containerCreateResponse.I
{
var inspectResponse = await this.dockerClient.Containers.InspectContainerAsync(containerCreateResponse.ID);
hasExited = inspectResponse.State.Running == false;

// Get logs from multiplexed stream
var buffer = new byte[4096];
var eof = false;
while (!eof)
{
var result = await logResponse.ReadOutputAsync(buffer, 0, buffer.Length, CancellationToken.None);
eof = result.EOF;

var log = System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count);
Log.Information(log.Replace("\n", string.Empty));
}
}

var containerInspectResponse = await this.dockerClient.Containers.InspectContainerAsync(containerCreateResponse.ID);

var containerInspectResponse =
await this.dockerClient.Containers.InspectContainerAsync(containerCreateResponse.ID);
var exitCode = containerInspectResponse.State.ExitCode;

Log.Information("Container for build exited, exit code: {Code}", exitCode);

await this.dockerClient.Containers.RemoveContainerAsync(containerCreateResponse.ID,
Expand Down
6 changes: 3 additions & 3 deletions Plogon/Manifests/ManifestStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ private void Load()
var channels = new Dictionary<string, IReadOnlyDictionary<string, Manifest>>();

var stableDir = new DirectoryInfo(Path.Combine(this.baseDirectory.FullName, "stable"));
var testingDir = new DirectoryInfo(Path.Combine(this.baseDirectory.FullName, "testing"));
var testingDir = new DirectoryInfo(Path.Combine(this.baseDirectory.FullName, "testing"));

channels.Add(stableDir.Name, GetManifestsInDirectory(stableDir));

foreach (var testingChannelDir in testingDir.EnumerateDirectories())
{
var manifests = GetManifestsInDirectory(testingChannelDir);
Expand All @@ -40,7 +40,7 @@ private void Load()
private static Dictionary<string, Manifest> GetManifestsInDirectory(DirectoryInfo directory)
{
var manifests = new Dictionary<string, Manifest>();

foreach (var manifestDir in directory.EnumerateDirectories())
{
try
Expand Down
11 changes: 7 additions & 4 deletions Plogon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ class Program
/// <param name="outputFolder">The folder used for storing output and state.</param>
/// <param name="manifestFolder">The folder used for storing plugin manifests.</param>
/// <param name="workFolder">The folder to store temporary files and build output in.</param>
static async Task Main(DirectoryInfo outputFolder, DirectoryInfo manifestFolder, DirectoryInfo workFolder)
/// <param name="staticFolder">The 'static' folder that holds script files.</param>
static async Task Main(DirectoryInfo outputFolder, DirectoryInfo manifestFolder, DirectoryInfo workFolder,
DirectoryInfo staticFolder)
{
SetupLogging();

var buildProcessor = new BuildProcessor(outputFolder, manifestFolder, workFolder);
var buildProcessor = new BuildProcessor(outputFolder, manifestFolder, workFolder, staticFolder);
var tasks = buildProcessor.GetTasks();

await buildProcessor.SetupDockerImage();

foreach (var task in tasks)
{
Log.Information("Need: {Name} - {Sha} (have {HaveCommit})", task.InternalName, task.Manifest.Plugin.Commit, task.HaveCommit ?? "nothing");
Log.Information("Need: {Name} - {Sha} (have {HaveCommit})", task.InternalName, task.Manifest.Plugin.Commit,
task.HaveCommit ?? "nothing");
var status = await buildProcessor.ProcessTask(task);

if (!status)
Expand Down
Empty file modified Plogon/static/entrypoint.sh
100644 → 100755
Empty file.

0 comments on commit 299219c

Please sign in to comment.