Skip to content

Commit 3dc6839

Browse files
committed
build: allow disabling docker for specific build targets
Introduce a UseDocker flag to DockerBuildContext and skip Docker initialization in BuildLifetime when specific test targets are executed.
1 parent 5d84f3f commit 3dc6839

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

build/artifacts/BuildLifetime.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
using Artifacts.Tasks;
12
using Common.Lifetime;
3+
using Common.Utilities;
24

35
namespace Artifacts;
46

57
public class BuildLifetime : DockerBuildLifetime<BuildContext>
68
{
79
protected override bool UseBaseImage => true;
10+
11+
public override void Setup(BuildContext context, ISetupContext info)
12+
{
13+
var target = context.Argument("target", "Default");
14+
if (target.IsEqualInvariant(nameof(ArtifactsMsBuildFullTest)) || target.IsEqualInvariant(nameof(ArtifactsExecutableTest)))
15+
{
16+
context.UseDocker = false;
17+
}
18+
19+
base.Setup(context, info);
20+
}
821
}

build/common/Context/DockerBuildContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace Common.Context;
44

55
public class DockerBuildContext(ICakeContext context) : BuildContextBase(context)
66
{
7+
public bool UseDocker { get; set; } = true;
8+
79
public bool IsDockerOnLinux { get; set; }
810

911
public IEnumerable<DockerImage> Images { get; set; } = [];

build/common/Lifetime/DockerBuildLifetime.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public override void Setup(TContext context, ISetupContext info)
1212
{
1313
base.Setup(context, info);
1414

15+
if (!context.UseDocker)
16+
{
17+
return;
18+
}
19+
1520
context.IsDockerOnLinux = context.DockerCustomCommand("info --format '{{.OSType}}'").First().Replace("'", string.Empty) == "linux";
1621

1722
var dockerRegistry = context.Argument(Arguments.DockerRegistry, DockerRegistry.DockerHub);

0 commit comments

Comments
 (0)