Skip to content

Commit e8e47c0

Browse files
committed
implement docker image and manifest label/annotations
1 parent 9171123 commit e8e47c0

11 files changed

+370
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="DockerBuildDeps (dockerhub)" type="DotNetProject" factoryName=".NET Project">
3+
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build.exe" />
4+
<option name="PROGRAM_PARAMETERS" value="--target=DockerBuildDeps --dotnet_distro=alpine.3.17 --docker_registry=dockerhub --verbosity=diagnostic --push_images=true" />
5+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.." />
6+
<option name="PASS_PARENT_ENVS" value="1" />
7+
<option name="USE_EXTERNAL_CONSOLE" value="0" />
8+
<option name="USE_MONO" value="0" />
9+
<option name="RUNTIME_ARGUMENTS" value="" />
10+
<option name="PROJECT_PATH" value="$PROJECT_DIR$/build/Build.csproj" />
11+
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
12+
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
13+
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
14+
<option name="PROJECT_KIND" value="DotNetCore" />
15+
<option name="PROJECT_TFM" value="net8.0" />
16+
<method v="2">
17+
<option name="Build" />
18+
</method>
19+
</configuration>
20+
</component>

build/.run/DockerBuildDeps.run.xml build/.run/DockerBuildDeps (gihub).run.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="DockerBuildDeps" type="DotNetProject" factoryName=".NET Project">
2+
<configuration default="false" name="DockerBuildDeps (gihub)" type="DotNetProject" factoryName=".NET Project">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build.exe" />
4-
<option name="PROGRAM_PARAMETERS" value="--target=DockerBuildDeps --dotnet_distro=alpine.3.17 --docker_registry=github --verbosity=diagnostic" />
4+
<option name="PROGRAM_PARAMETERS" value="--target=DockerBuildDeps --dotnet_distro=alpine.3.17 --docker_registry=github --verbosity=diagnostic --push_images=true" />
55
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.." />
66
<option name="PASS_PARENT_ENVS" value="1" />
77
<option name="USE_EXTERNAL_CONSOLE" value="0" />
@@ -17,4 +17,4 @@
1717
<option name="Build" />
1818
</method>
1919
</configuration>
20-
</component>
20+
</component>

build/build/Cake.Docker/Constants.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Build.Cake.Docker;
2+
3+
/// <summary>
4+
/// Constants
5+
/// </summary>
6+
public static class Constants
7+
{
8+
/// <summary>
9+
/// Used with <see cref="AutoPropertyAttribute.Format"/> when a bool argument defaults to true.
10+
/// </summary>
11+
public const string BoolWithTrueDefaultFormat = "--{0}={1}";
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
namespace Build.Cake.Docker;
2+
3+
/// <summary>
4+
/// Settings for docker buildx build.
5+
/// </summary>
6+
public sealed class DockerBuildXBuildSettings : AutoToolSettings
7+
{
8+
/// <summary>
9+
/// Add a custom host-to-IP mapping (format: "host:ip")
10+
/// </summary>
11+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
12+
public string[] AddHost { get; set; }
13+
/// <summary>
14+
/// Allow extra privileged entitlement (e.g., "network.host", "security.insecure")
15+
/// </summary>
16+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
17+
public string[] Allow { get; set; }
18+
/// <summary>
19+
/// Set build-time variables
20+
/// </summary>
21+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
22+
public string[] BuildArg { get; set; }
23+
/// <summary>
24+
/// Additional build contexts (e.g., name=path)
25+
/// </summary>
26+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
27+
public string[] BuildContext { get; set; }
28+
/// <summary>
29+
/// Override the configured builder instance
30+
/// </summary>
31+
public string Builder { get; set; }
32+
/// <summary>
33+
/// External cache sources (e.g., "user/app:cache", "type=local,src=path/to/dir")
34+
/// </summary>
35+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
36+
public string[] CacheFrom { get; set; }
37+
/// <summary>
38+
/// Cache export destinations (e.g., "user/app:cache", "type=local,dest=path/to/dir")
39+
/// </summary>
40+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
41+
public string[] CacheTo { get; set; }
42+
/// <summary>
43+
/// Optional parent cgroup for the container
44+
/// </summary>
45+
public string CgroupParent { get; set; }
46+
/// <summary>
47+
/// Compress the build context using gzip
48+
/// </summary>
49+
public bool? Compress { get; set; }
50+
/// <summary>
51+
/// Limit the CPU CFS (Completely Fair Scheduler) period
52+
/// </summary>
53+
public Int64? CpuPeriod { get; set; }
54+
/// <summary>
55+
/// Limit the CPU CFS (Completely Fair Scheduler) quota
56+
/// </summary>
57+
public Int64? CpuQuota { get; set; }
58+
/// <summary>
59+
/// CPUs in which to allow execution (0-3, 0,1)
60+
/// </summary>
61+
public string CpusetCpus { get; set; }
62+
/// <summary>
63+
/// MEMs in which to allow execution (0-3, 0,1)
64+
/// </summary>
65+
public string CpusetMems { get; set; }
66+
/// <summary>
67+
/// CPU shares (relative weight)
68+
/// </summary>
69+
public Int64? CpuShares { get; set; }
70+
/// <summary>
71+
/// Skip image verification
72+
/// </summary>
73+
[AutoProperty(Format = Constants.BoolWithTrueDefaultFormat)]
74+
public bool? DisableContentTrust { get; set; }
75+
/// <summary>
76+
/// Name of the Dockerfile (default: "PATH/Dockerfile")
77+
/// </summary>
78+
public string File { get; set; }
79+
/// <summary>
80+
/// Always remove intermediate containers
81+
/// </summary>
82+
public bool? ForceRm { get; set; }
83+
/// <summary>
84+
/// Write the image ID to the file
85+
/// </summary>
86+
public string Iidfile { get; set; }
87+
/// <summary>
88+
/// Container isolation technology
89+
/// </summary>
90+
public string Isolation { get; set; }
91+
/// <summary>
92+
/// Set metadata for an image
93+
/// </summary>
94+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
95+
public string[] Label { get; set; }
96+
/// <summary>
97+
/// Shorthand for "--output=type=docker"
98+
/// </summary>
99+
public bool Load { get; set; }
100+
/// <summary>
101+
/// Memory limit
102+
/// </summary>
103+
public string Memory { get; set; }
104+
/// <summary>
105+
/// Swap limit equal to memory plus swap: &#39;-1&#39; to enable unlimited swap
106+
/// </summary>
107+
public string MemorySwap { get; set; }
108+
/// <summary>
109+
/// Write build result metadata to the file
110+
/// </summary>
111+
public string MetadataFile { get; set; }
112+
/// <summary>
113+
/// Set the networking mode for the "RUN" instructions during build (default "default")
114+
/// </summary>
115+
public string Network { get; set; }
116+
/// <summary>
117+
/// Do not use cache when building the image
118+
/// </summary>
119+
public bool NoCache { get; set; }
120+
/// <summary>
121+
/// Do not cache specified stages
122+
/// </summary>
123+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
124+
public string[] NoCacheFilter { get; set; }
125+
/// <summary>
126+
/// Output destination (format: "type=local,dest=path")
127+
/// </summary>
128+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
129+
public string[] Output { get; set; }
130+
/// <summary>
131+
/// Set target platform for build
132+
/// </summary>
133+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
134+
public string[] Platform { get; set; }
135+
/// <summary>
136+
/// Set type of progress output ("auto", "plain", "tty"). Use plain to show container output (default "auto")
137+
/// </summary>
138+
public string Progress { get; set; }
139+
/// <summary>
140+
/// Always attempt to pull all referenced images
141+
/// </summary>
142+
public bool Pull { get; set; }
143+
/// <summary>
144+
/// Shorthand for "--output=type=registry"
145+
/// </summary>
146+
public bool Push { get; set; }
147+
/// <summary>
148+
/// Suppress the build output and print image ID on success
149+
/// </summary>
150+
public bool Quiet { get; set; }
151+
/// <summary>
152+
/// Remove intermediate containers after a successful build
153+
/// </summary>
154+
[AutoProperty(Format = Constants.BoolWithTrueDefaultFormat)]
155+
public bool? Rm { get; set; }
156+
/// <summary>
157+
/// Secret to expose to the build (format: "id=mysecret[,src=/local/secret]")
158+
/// </summary>
159+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
160+
public string[] Secret { get; set; }
161+
/// <summary>
162+
/// Security options
163+
/// </summary>
164+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
165+
public string[] SecurityOpt { get; set; }
166+
/// <summary>
167+
/// Size of "/dev/shm"
168+
/// </summary>
169+
public string ShmSize { get; set; }
170+
/// <summary>
171+
/// Squash newly built layers into a single new layer
172+
/// </summary>
173+
public bool? Squash { get; set; }
174+
/// <summary>
175+
/// SSH agent socket or keys to expose to the build (format: "default|&lt;id&gt;[=&lt;socket&gt;|&lt;key&gt;[,&lt;key&gt;]]")
176+
/// </summary>
177+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
178+
public string[] Ssh { get; set; }
179+
/// <summary>
180+
/// Name and optionally a tag (format: "name:tag")
181+
/// </summary>
182+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
183+
public string[] Tag { get; set; }
184+
/// <summary>
185+
/// Set the target build stage to build.
186+
/// </summary>
187+
public string Target { get; set; }
188+
/// <summary>
189+
/// Ulimit options (default [])
190+
/// </summary>
191+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
192+
public string[] Ulimit { get; set; }
193+
/// <summary>
194+
/// Set annotation for new image
195+
/// </summary>
196+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
197+
public string[] Annotation { get; set; }
198+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace Build.Cake.Docker;
2+
3+
/// <summary>
4+
/// Settings for docker buildx imagetools create.
5+
/// </summary>
6+
public sealed class DockerBuildXImageToolsCreateSettings : AutoToolSettings
7+
{
8+
/// <summary>
9+
/// Append to existing manifest
10+
/// </summary>
11+
public bool Append { get; set; }
12+
/// <summary>
13+
/// Override the configured builder instance
14+
/// </summary>
15+
public string Builder { get; set; }
16+
/// <summary>
17+
/// Show final image instead of pushing
18+
/// </summary>
19+
public bool DryRun { get; set; }
20+
/// <summary>
21+
/// Read source descriptor from file
22+
/// </summary>
23+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
24+
public string[] File { get; set; }
25+
/// <summary>
26+
/// Set reference for new image
27+
/// </summary>
28+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
29+
public string[] Tag { get; set; }
30+
/// <summary>
31+
/// Set annotation for new image
32+
/// </summary>
33+
[AutoProperty(AutoArrayType = AutoArrayType.List)]
34+
public string[] Annotation { get; set; }
35+
}

build/build/Infra/DockerExtensions.cs

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
namespace Build;
2+
using DockerBuildXBuildSettings = Build.Cake.Docker.DockerBuildXBuildSettings;
3+
using DockerBuildXImageToolsCreateSettings = Build.Cake.Docker.DockerBuildXImageToolsCreateSettings;
24

35
public static class DockerExtensions
46
{
5-
public static void DockerBuildXBuild(this ICakeContext context, DockerBuildXBuildSettings settings, string path,
6-
params string[] args)
7+
public static void DockerBuildXBuild(this ICakeContext context, DockerBuildXBuildSettings settings, DirectoryPath target)
78
{
8-
var runner = new GenericDockerRunner<DockerBuildXBuildSettings>(context.FileSystem, context.Environment,
9-
context.ProcessRunner, context.Tools);
10-
11-
path = $"\"{path.Trim().Trim('\"')}\"";
12-
runner.Run("buildx build", settings, [.. args, path]);
9+
ArgumentNullException.ThrowIfNull(context);
10+
var runner = new GenericDockerRunner<DockerBuildXBuildSettings>(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
11+
runner.Run("buildx build", settings, [target.ToString().EscapeProcessArgument()]);
1312
}
1413

15-
public static void DockerManifestRemove(this ICakeContext context, string tag) => context.DockerCustomCommand($"manifest rm {tag}");
14+
public static void DockerBuildXImageToolsCreate(this ICakeContext context, DockerBuildXImageToolsCreateSettings settings, IEnumerable<string>? target = null)
15+
{
16+
ArgumentNullException.ThrowIfNull(context);
17+
var runner = new GenericDockerRunner<DockerBuildXImageToolsCreateSettings>(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
18+
runner.Run("buildx imagetools create", settings, target?.ToArray() ?? []);
19+
}
1620
}

0 commit comments

Comments
 (0)