@@ -7,6 +7,7 @@ public enum Architecture
77 Arm64 ,
88 Amd64
99}
10+
1011public static class DockerContextExtensions
1112{
1213 public static bool SkipImageForArtifacts ( this ICakeContext context , DockerImage dockerImage )
@@ -43,9 +44,8 @@ public static void DockerBuildImage(this BuildContextBase context, DockerImage d
4344 var tags = context . GetDockerTags ( dockerImage , arch ) ;
4445
4546 var suffix = arch . ToSuffix ( ) ;
46- var platforms = new List < string > { $ "linux/{ suffix } " } ;
4747
48- var buildSettings = new DockerImageBuildSettings
48+ var buildSettings = new DockerBuildXBuildSettings
4949 {
5050 Rm = true ,
5151 Tag = tags . ToArray ( ) ,
@@ -59,10 +59,10 @@ public static void DockerBuildImage(this BuildContextBase context, DockerImage d
5959 $ "VERSION={ context . Version . NugetVersion } "
6060 ] ,
6161 Pull = true ,
62- Platform = string . Join ( "," , platforms ) ,
62+ Platform = [ $ "linux/ { suffix } " ]
6363 } ;
6464
65- context . DockerBuild ( buildSettings , workDir . ToString ( ) , "--output type=docker" ) ;
65+ context . DockerBuildXBuild ( buildSettings , workDir . ToString ( ) , "--output type=docker" ) ;
6666 }
6767
6868 public static void DockerPushImage ( this BuildContextBase context , DockerImage dockerImage )
@@ -74,7 +74,8 @@ public static void DockerPushImage(this BuildContextBase context, DockerImage do
7474 }
7575 }
7676
77- public static void DockerCreateManifest ( this BuildContextBase context , DockerImage dockerImage , bool skipArm64Image = false )
77+ public static void DockerCreateManifest ( this BuildContextBase context , DockerImage dockerImage ,
78+ bool skipArm64Image = false )
7879 {
7980 var manifestTags = context . GetDockerTags ( dockerImage ) ;
8081 foreach ( var tag in manifestTags )
@@ -124,29 +125,18 @@ public static void DockerTestArtifact(this BuildContextBase context, DockerImage
124125 context . DockerTestRun ( tag , dockerImage . Architecture , "sh" , cmd ) ;
125126 }
126127
127- private static void DockerBuild ( this ICakeContext context , DockerImageBuildSettings settings , string path , params string [ ] args )
128+ private static void DockerBuildXBuild ( this ICakeContext context , DockerBuildXBuildSettings settings , string path ,
129+ params string [ ] args )
128130 {
129- GenericDockerRunner < DockerImageBuildSettings > genericDockerRunner =
130- new ( context . FileSystem , context . Environment , context . ProcessRunner , context . Tools ) ;
131+ var runner = new GenericDockerRunner < DockerBuildXBuildSettings > ( context . FileSystem , context . Environment ,
132+ context . ProcessRunner , context . Tools ) ;
131133
132- string str ;
133- switch ( string . IsNullOrEmpty ( path ) )
134- {
135- case false :
136- {
137- string str2 = path . Trim ( ) ;
138- str = str2 . Length <= 1 || ! str2 . StartsWith ( "\" " ) || ! str2 . EndsWith ( "\" " ) ? "\" " + path + "\" " : path ;
139- break ;
140- }
141- default :
142- str = path ;
143- break ;
144- }
145- var additional = args . Concat ( new [ ] { str } ) . ToArray ( ) ;
146- genericDockerRunner . Run ( "buildx build" , settings , additional ) ;
134+ path = $ "\" { path . Trim ( ) . Trim ( '\" ' ) } \" ";
135+ runner . Run ( "buildx build" , settings , [ .. args , path ] ) ;
147136 }
148137
149- private static void DockerTestRun ( this BuildContextBase context , string image , Architecture arch , string command , params string [ ] args )
138+ private static void DockerTestRun ( this BuildContextBase context , string image , Architecture arch , string command ,
139+ params string [ ] args )
150140 {
151141 var settings = GetDockerRunSettings ( context , arch ) ;
152142 context . Information ( $ "Testing image: { image } ") ;
@@ -156,7 +146,9 @@ private static void DockerTestRun(this BuildContextBase context, string image, A
156146 Assert . NotNull ( context . Version ? . GitVersion ) ;
157147 Assert . Contains ( context . Version . GitVersion . FullSemVer ! , output ) ;
158148 }
159- private static IEnumerable < string > GetDockerTags ( this BuildContextBase context , DockerImage dockerImage , Architecture ? arch = null )
149+
150+ private static IEnumerable < string > GetDockerTags ( this BuildContextBase context , DockerImage dockerImage ,
151+ Architecture ? arch = null )
160152 {
161153 var name = dockerImage . DockerImageName ( ) ;
162154 var distro = dockerImage . Distro ;
@@ -171,31 +163,29 @@ private static IEnumerable<string> GetDockerTags(this BuildContextBase context,
171163
172164 if ( distro == Constants . DockerDistroLatest && targetFramework == Constants . VersionLatest )
173165 {
174- tags . AddRange ( new [ ]
175- {
176- $ "{ name } :{ context . Version . Version } ",
177- $ "{ name } :{ context . Version . SemVersion } ",
178- } ) ;
166+ tags . AddRange ( new [ ] { $ "{ name } :{ context . Version . Version } ", $ "{ name } :{ context . Version . SemVersion } ", } ) ;
179167
180168 if ( context . IsStableRelease )
181169 {
182- tags . AddRange ( new [ ]
183- {
170+ tags . AddRange (
171+ [
184172 $ "{ name } :latest",
185173 $ "{ name } :latest-{ targetFramework } ",
186174 $ "{ name } :latest-{ distro } ",
187175 $ "{ name } :latest-{ distro } -{ targetFramework } ",
188- } ) ;
176+ ] ) ;
189177 }
190178 }
191179
192180 if ( ! arch . HasValue ) return tags . Distinct ( ) ;
193181
194182 var suffix = arch . Value . ToSuffix ( ) ;
195183 return tags . Select ( x => $ "{ x } -{ suffix } ") . Distinct ( ) ;
196-
197184 }
198- private static string DockerImageName ( this DockerImage image ) => $ "{ image . Registry } /{ ( image . UseBaseImage ? Constants . DockerBaseImageName : Constants . DockerImageName ) } ";
185+
186+ private static string DockerImageName ( this DockerImage image ) =>
187+ $ "{ image . Registry } /{ ( image . UseBaseImage ? Constants . DockerBaseImageName : Constants . DockerImageName ) } ";
188+
199189 private static DockerContainerRunSettings GetDockerRunSettings ( this BuildContextBase context , Architecture arch )
200190 {
201191 var currentDir = context . MakeAbsolute ( context . Directory ( "." ) ) ;
@@ -221,6 +211,7 @@ private static DockerContainerRunSettings GetDockerRunSettings(this BuildContext
221211 $ "BUILD_SOURCEBRANCH={ context . EnvironmentVariable ( "BUILD_SOURCEBRANCH" ) } "
222212 ] ;
223213 }
214+
224215 if ( context . IsGitHubActionsBuild )
225216 {
226217 settings . Env =
0 commit comments