mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-29 16:11:05 +01:00
Merge pull request #642 from tgstation/638-ChangeDMRead
Updates to the DreamMaker model
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
namespace Tgstation.Server.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Status of the <see cref="DreamMaker"/> for an <see cref="Instance"/>
|
||||
/// </summary>
|
||||
#pragma warning disable CA1717 // Only FlagsAttribute enums should have plural names
|
||||
public enum CompilerStatus
|
||||
#pragma warning restore CA1717 // Only FlagsAttribute enums should have plural names
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="DreamMaker"/> is idle
|
||||
/// </summary>
|
||||
Idle,
|
||||
/// <summary>
|
||||
/// The <see cref="Repository"/> is being copied
|
||||
/// </summary>
|
||||
Copying,
|
||||
/// <summary>
|
||||
/// Pre-compile scripts are running
|
||||
/// </summary>
|
||||
PreCompile,
|
||||
/// <summary>
|
||||
/// The .dme is having it's server side modifications applied
|
||||
/// </summary>
|
||||
Modifying,
|
||||
/// <summary>
|
||||
/// DreamMaker is running
|
||||
/// </summary>
|
||||
Compiling,
|
||||
/// <summary>
|
||||
/// The DMAPI is being verified
|
||||
/// </summary>
|
||||
Verifying,
|
||||
/// <summary>
|
||||
/// Post-compile scripts are running
|
||||
/// </summary>
|
||||
PostCompile,
|
||||
/// <summary>
|
||||
/// The compile results are being duplicated
|
||||
/// </summary>
|
||||
Duplicating,
|
||||
/// <summary>
|
||||
/// The configuration is being linked to the compile results
|
||||
/// </summary>
|
||||
Symlinking,
|
||||
/// <summary>
|
||||
/// A failed compile job is being erased
|
||||
/// </summary>
|
||||
Cleanup
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,21 @@
|
||||
using Tgstation.Server.Api.Models.Internal;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Tgstation.Server.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the state of the DreamMaker compiler. Create action starts a new compile. Delete action cancels the current compile
|
||||
/// </summary>
|
||||
public sealed class DreamMaker : DreamMakerSettings
|
||||
public class DreamMaker
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="CompilerStatus"/> of the compiler
|
||||
/// The .dme file <see cref="DreamMaker"/> tries to compile with without the extension
|
||||
/// </summary>
|
||||
public CompilerStatus Status { get; set; }
|
||||
public string ProjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The port used during compilation to validate the DMAPI
|
||||
/// </summary>
|
||||
[Required]
|
||||
public ushort? ApiValidationPort { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Tgstation.Server.Api.Models.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Configurable settings for <see cref="DreamMaker"/>
|
||||
/// </summary>
|
||||
public class DreamMakerSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// The .dme file <see cref="DreamMakerSettings"/> tries to compile with without the extension
|
||||
/// </summary>
|
||||
public string ProjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The port used during compilation to validate the DMAPI
|
||||
/// </summary>
|
||||
[Required]
|
||||
public ushort? ApiValidationPort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -25,11 +25,11 @@ namespace Tgstation.Server.Api.Rights
|
||||
/// </summary>
|
||||
CancelCompile = 4,
|
||||
/// <summary>
|
||||
/// User may modify <see cref="Models.Internal.DreamMakerSettings.ProjectName"/>
|
||||
/// User may modify <see cref="Models.DreamMaker.ProjectName"/>
|
||||
/// </summary>
|
||||
SetDme = 8,
|
||||
/// <summary>
|
||||
/// User may modify <see cref="Models.Internal.DreamMakerSettings.ApiValidationPort"/>
|
||||
/// User may modify <see cref="Models.DreamMaker.ApiValidationPort"/>
|
||||
/// </summary>
|
||||
SetApiValidationPort = 16,
|
||||
/// <summary>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<FileVersion>4.0.0.0</FileVersion>
|
||||
<PackageTags>json web api tgstation-server tgstation ss13 byond</PackageTags>
|
||||
<PackageReleaseNotes>Prototype release</PackageReleaseNotes>
|
||||
<Version>4.0.0.0-preview6002</Version>
|
||||
<Version>4.0.0.0-preview6003</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<DebugType>Full</DebugType>
|
||||
<Version>4.0.0.0-preview9104</Version>
|
||||
<Version>4.0.0.0-preview9105</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>Cyberboss</Authors>
|
||||
<Company>/tg/station 13</Company>
|
||||
|
||||
@@ -37,9 +37,6 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
/// </summary>
|
||||
const string DmeExtension = "dme";
|
||||
|
||||
/// <inheritdoc />
|
||||
public CompilerStatus Status { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IByondManager"/> for <see cref="DreamMaker"/>
|
||||
/// </summary>
|
||||
@@ -85,6 +82,11 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
/// </summary>
|
||||
readonly ILogger<DreamMaker> logger;
|
||||
|
||||
/// <summary>
|
||||
/// If a compile job is running
|
||||
/// </summary>
|
||||
bool compiling;
|
||||
|
||||
/// <summary>
|
||||
/// Construct <see cref="DreamMaker"/>
|
||||
/// </summary>
|
||||
@@ -241,7 +243,7 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Models.CompileJob> Compile(Models.RevisionInformation revisionInformation, DreamMakerSettings dreamMakerSettings, DreamDaemonSecurity securityLevel, uint apiValidateTimeout, IRepository repository, CancellationToken cancellationToken)
|
||||
public async Task<Models.CompileJob> Compile(Models.RevisionInformation revisionInformation, Api.Models.DreamMaker dreamMakerSettings, DreamDaemonSecurity securityLevel, uint apiValidateTimeout, IRepository repository, CancellationToken cancellationToken)
|
||||
{
|
||||
if (revisionInformation == null)
|
||||
throw new ArgumentNullException(nameof(revisionInformation));
|
||||
@@ -268,10 +270,9 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
|
||||
lock (this)
|
||||
{
|
||||
if (Status != CompilerStatus.Idle)
|
||||
throw new JobException("There is already a compile in progress!");
|
||||
|
||||
Status = CompilerStatus.Copying;
|
||||
if (compiling)
|
||||
throw new JobException("There is already a compile job in progress!");
|
||||
compiling = true;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -302,7 +303,6 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
async Task CleanupFailedCompile(bool cancelled)
|
||||
{
|
||||
logger.LogTrace("Cleaning compile directory...");
|
||||
Status = CompilerStatus.Cleanup;
|
||||
var chatTask = chat.SendUpdateMessage(cancelled ? "Deploy cancelled!" : "Deploy failed!", cancellationToken);
|
||||
try
|
||||
{
|
||||
@@ -330,13 +330,11 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
using (repository)
|
||||
await repository.CopyTo(fullDirA, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Status = CompilerStatus.PreCompile;
|
||||
|
||||
//run precompile scripts
|
||||
var resolvedGameDirectory = ioManager.ResolvePath(ioManager.ConcatPath(job.DirectoryName.ToString(), ADirectoryName));
|
||||
await eventConsumer.HandleEvent(EventType.CompileStart, new List<string> { resolvedGameDirectory, repoOrigin }, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Status = CompilerStatus.Modifying;
|
||||
|
||||
//determine the dme
|
||||
if (job.DmeName == null)
|
||||
{
|
||||
logger.LogTrace("Searching for available .dmes...");
|
||||
@@ -351,20 +349,12 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
|
||||
await ModifyDme(job, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Status = CompilerStatus.Compiling;
|
||||
|
||||
//run compiler, verify api
|
||||
job.ByondVersion = byondLock.Version.ToString();
|
||||
|
||||
var exitCode = await RunDreamMaker(byondLock.DreamMakerPath, job, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var apiValidated = false;
|
||||
if (exitCode == 0)
|
||||
{
|
||||
Status = CompilerStatus.Verifying;
|
||||
|
||||
apiValidated = await VerifyApi(apiValidateTimeout, securityLevel, job, byondLock, dreamMakerSettings.ApiValidationPort.Value, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
var apiValidated = exitCode == 0 && await VerifyApi(apiValidateTimeout, securityLevel, job, byondLock, dreamMakerSettings.ApiValidationPort.Value, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (!apiValidated)
|
||||
{
|
||||
@@ -374,17 +364,14 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
}
|
||||
|
||||
logger.LogTrace("Running post compile event...");
|
||||
Status = CompilerStatus.PostCompile;
|
||||
await eventConsumer.HandleEvent(EventType.CompileComplete, new List<string> { ioManager.ResolvePath(ioManager.ConcatPath(job.DirectoryName.ToString(), ADirectoryName)) }, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
logger.LogTrace("Duplicating compiled game...");
|
||||
Status = CompilerStatus.Duplicating;
|
||||
|
||||
//duplicate the dmb et al
|
||||
await ioManager.CopyDirectory(dirA, dirB, null, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
logger.LogTrace("Applying static game file symlinks...");
|
||||
Status = CompilerStatus.Symlinking;
|
||||
|
||||
//symlink in the static data
|
||||
var symATask = configuration.SymlinkStaticFilesTo(fullDirA, cancellationToken);
|
||||
@@ -411,7 +398,7 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
}
|
||||
finally
|
||||
{
|
||||
Status = CompilerStatus.Idle;
|
||||
compiling = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Api.Models.Internal;
|
||||
using Tgstation.Server.Host.Components.Repository;
|
||||
|
||||
namespace Tgstation.Server.Host.Components.Compiler
|
||||
@@ -11,21 +10,16 @@ namespace Tgstation.Server.Host.Components.Compiler
|
||||
/// </summary>
|
||||
public interface IDreamMaker
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="CompilerStatus"/> of <see cref="IDreamMaker"/>
|
||||
/// </summary>
|
||||
CompilerStatus Status { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts a compile
|
||||
/// </summary>
|
||||
/// <param name="revisionInformation">The <see cref="Models.RevisionInformation"/> being compiled from the <paramref name="repository"/></param>
|
||||
/// <param name="dreamMakerSettings">The <see cref="DreamMakerSettings"/> for the compile</param>
|
||||
/// <param name="dreamMakerSettings">The <see cref="Api.Models.DreamMaker"/> for the compile</param>
|
||||
/// <param name="securityLevel">The <see cref="DreamDaemonSecurity"/> level allowed for API validation</param>
|
||||
/// <param name="apiValidateTimeout">The time in seconds to wait while validating the API</param>
|
||||
/// <param name="repository">The <see cref="IRepository"/> to copy from</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the partially populated <see cref="Models.CompileJob"/> for the operation. In particular, note the <see cref="Models.CompileJob.RevisionInformation"/> field will only have it's <see cref="Api.Models.Internal.RevisionInformation.CommitSha"/> field populated</returns>
|
||||
Task<Models.CompileJob> Compile(Models.RevisionInformation revisionInformation, DreamMakerSettings dreamMakerSettings, DreamDaemonSecurity securityLevel, uint apiValidateTimeout, IRepository repository, CancellationToken cancellationToken);
|
||||
Task<Models.CompileJob> Compile(Models.RevisionInformation revisionInformation, Api.Models.DreamMaker dreamMakerSettings, DreamDaemonSecurity securityLevel, uint apiValidateTimeout, IRepository repository, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -51,11 +51,11 @@ namespace Tgstation.Server.Host.Controllers
|
||||
public override async Task<IActionResult> Read(CancellationToken cancellationToken)
|
||||
{
|
||||
var instance = instanceManager.GetInstance(Instance);
|
||||
var projectName = await DatabaseContext.DreamMakerSettings.Where(x => x.InstanceId == Instance.Id).Select(x => x.ProjectName).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
|
||||
var dreamMakerSettings = await DatabaseContext.DreamMakerSettings.Where(x => x.InstanceId == Instance.Id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Json(new Api.Models.DreamMaker
|
||||
{
|
||||
ProjectName = projectName,
|
||||
Status = instance.DreamMaker.Status
|
||||
ProjectName = dreamMakerSettings.ProjectName,
|
||||
ApiValidationPort = dreamMakerSettings.ApiValidationPort
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Tgstation.Server.Host.Models
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed class DreamMakerSettings : Api.Models.Internal.DreamMakerSettings
|
||||
public sealed class DreamMakerSettings : Api.Models.DreamMaker
|
||||
{
|
||||
/// <summary>
|
||||
/// The row Id
|
||||
|
||||
Reference in New Issue
Block a user