Skip to content

Commit dc28554

Browse files
committed
(build) cleanup
1 parent a32b86a commit dc28554

File tree

9 files changed

+23
-20
lines changed

9 files changed

+23
-20
lines changed

build/Directory.Packages.props

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
<PackageReference Include="Cake.Codecov" Version="1.0.1"/>
44
<PackageReference Include="Cake.Common" Version="1.1.0" />
55
<PackageReference Include="Cake.Compression" Version="0.2.6" />
6-
<PackageReference Include="Cake.Docker" Version="1.0.0" />
76
<PackageReference Include="Cake.Coverlet" Version="2.5.4" />
7+
<PackageReference Include="Cake.Docker" Version="1.0.0" />
88
<PackageReference Include="Cake.Frosting" Version="1.1.0" />
9-
<PackageReference Include="Cake.Incubator" Version="6.0.0" />
9+
<PackageReference Include="Cake.Git" Version="1.1.0" />
10+
<PackageReference Include="Cake.Kudu" Version="1.0.1" />
1011
<PackageReference Include="Cake.Json" Version="6.0.1" />
12+
<PackageReference Include="Cake.Incubator" Version="6.0.0" />
1113
<PackageReference Include="Cake.Wyam" Version="2.2.12" />
1214
</ItemGroup>
1315
</Project>

build/common/Utilities/Models.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public record GitHubCredentials(string UserName, string Token);
1313

1414
public record GitterCredentials(string Token, string RoomId);
1515

16-
public record DockerHubCredentials(string UserName, string Password);
16+
public record DockerCredentials(string UserName, string Password);
1717

1818
public record NugetCredentials(string ApiKey, string ApiUrl);
1919

build/docker/BuildContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class BuildContext : BuildContextBase
1010
public bool IsDockerOnLinux { get; set; }
1111

1212
public Credentials? Credentials { get; set; }
13-
public string DockerRegistry { get; set; } = Constants.GitHubContainerRegistry;
13+
public string DockerRegistryPrefix { get; set; } = Constants.GitHubContainerRegistry;
1414
public IEnumerable<DockerImage> Images { get; set; } = new List<DockerImage>();
1515

1616
public BuildContext(ICakeContext context) : base(context)

build/docker/BuildLifetime.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public override void Setup(BuildContext context)
1515
base.Setup(context);
1616

1717
context.IsDockerOnLinux = context.DockerCustomCommand("info --format '{{.OSType}}'").First().Replace("'", "") == "linux";
18-
context.Credentials = Credentials.GetCredentials(context);
1918

2019
var dockerRegistry = context.Argument("docker_registry", "github").ToLower();
2120
var dotnetVersion = context.Argument("docker_dotnetversion", "").ToLower();
@@ -24,11 +23,13 @@ public override void Setup(BuildContext context)
2423
var versions = string.IsNullOrWhiteSpace(dotnetVersion) ? Constants.VersionsToBuild : new[] { dotnetVersion };
2524
var distros = string.IsNullOrWhiteSpace(dockerDistro) ? Constants.DockerDistrosToBuild : new[] { dockerDistro };
2625

27-
context.DockerRegistry = dockerRegistry == "github" ? Constants.GitHubContainerRegistry : Constants.DockerHubRegistry;
26+
context.DockerRegistryPrefix = dockerRegistry == "github" ? Constants.GitHubContainerRegistry : Constants.DockerHubRegistry;
2827
context.Images = from version in versions
2928
from distro in distros
3029
select new DockerImage(distro, version);
3130

31+
context.Credentials = Credentials.GetCredentials(context, dockerRegistry);
32+
3233
context.StartGroup("Build Setup");
3334

3435
LogBuildInformation(context);

build/docker/Tasks/DockerBuild.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override void Run(BuildContext context)
2626

2727
foreach (var dockerImage in context.Images)
2828
{
29-
context.DockerBuild(dockerImage, context.DockerRegistry);
29+
context.DockerBuild(dockerImage, context.DockerRegistryPrefix);
3030
}
3131
}
3232
}

build/docker/Tasks/DockerPublish.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Cake.Common.Diagnostics;
23
using Cake.Frosting;
34
using Common.Utilities;
45

@@ -21,6 +22,7 @@ public override bool ShouldRun(BuildContext context)
2122

2223
public override void Run(BuildContext context)
2324
{
25+
context.Information($"Docker image prefix: {context.DockerRegistryPrefix}");
2426
var username = context.Credentials?.Docker?.UserName;
2527
if (string.IsNullOrEmpty(username))
2628
{
@@ -35,7 +37,7 @@ public override void Run(BuildContext context)
3537

3638
foreach (var dockerImage in context.Images)
3739
{
38-
context.DockerPush(dockerImage, context.DockerRegistry);
40+
context.DockerPush(dockerImage, context.DockerRegistryPrefix);
3941
}
4042
}
4143
}

build/docker/Tasks/DockerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override void Run(BuildContext context)
2222

2323
foreach (var dockerImage in context.Images)
2424
{
25-
var tags = context.GetDockerTagsForRepository(dockerImage, context.DockerRegistry);
25+
var tags = context.GetDockerTagsForRepository(dockerImage, context.DockerRegistryPrefix);
2626
foreach (var tag in tags)
2727
{
2828
context.DockerTestRun(settings, tag, "/repo", "/showvariable", "FullSemver");

build/docker/Utilities/Credentials.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ namespace Docker.Utilities
66
{
77
public class Credentials
88
{
9-
public GitHubCredentials? GitHub { get; private set; }
10-
public DockerHubCredentials? Docker { get; private set; }
11-
public static Credentials GetCredentials(ICakeContext context) => new()
9+
public DockerCredentials? Docker { get; private set; }
10+
public static Credentials GetCredentials(ICakeContext context, string dockerRegistry) => new()
1211
{
13-
GitHub = new GitHubCredentials(
14-
context.EnvironmentVariable("GITHUB_USERNAME"),
15-
context.EnvironmentVariable("GITHUB_TOKEN")),
16-
17-
Docker = new DockerHubCredentials(
18-
context.EnvironmentVariable("DOCKER_USERNAME"),
19-
context.EnvironmentVariable("DOCKER_PASSWORD")),
12+
Docker = dockerRegistry == "github"
13+
? new DockerCredentials(
14+
context.EnvironmentVariable("GITHUB_USERNAME"),
15+
context.EnvironmentVariable("GITHUB_TOKEN"))
16+
: new DockerCredentials(
17+
context.EnvironmentVariable("DOCKER_USERNAME"),
18+
context.EnvironmentVariable("DOCKER_PASSWORD"))
2019
};
2120
}
2221
}

build/docs/BuildContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Generic;
21
using Cake.Core;
32
using Cake.Wyam;
43
using Common.Utilities;

0 commit comments

Comments
 (0)