@@ -7,6 +7,7 @@ public enum Architecture
7
7
Arm64 ,
8
8
Amd64
9
9
}
10
+
10
11
public static class DockerContextExtensions
11
12
{
12
13
public static bool SkipImageForArtifacts ( this ICakeContext context , DockerImage dockerImage )
@@ -43,9 +44,8 @@ public static void DockerBuildImage(this BuildContextBase context, DockerImage d
43
44
var tags = context . GetDockerTags ( dockerImage , arch ) ;
44
45
45
46
var suffix = arch . ToSuffix ( ) ;
46
- var platforms = new List < string > { $ "linux/{ suffix } " } ;
47
47
48
- var buildSettings = new DockerImageBuildSettings
48
+ var buildSettings = new DockerBuildXBuildSettings
49
49
{
50
50
Rm = true ,
51
51
Tag = tags . ToArray ( ) ,
@@ -59,10 +59,10 @@ public static void DockerBuildImage(this BuildContextBase context, DockerImage d
59
59
$ "VERSION={ context . Version . NugetVersion } "
60
60
] ,
61
61
Pull = true ,
62
- Platform = string . Join ( "," , platforms ) ,
62
+ Platform = [ $ "linux/ { suffix } " ]
63
63
} ;
64
64
65
- context . DockerBuild ( buildSettings , workDir . ToString ( ) , "--output type=docker" ) ;
65
+ context . DockerBuildXBuild ( buildSettings , workDir . ToString ( ) , "--output type=docker" ) ;
66
66
}
67
67
68
68
public static void DockerPushImage ( this BuildContextBase context , DockerImage dockerImage )
@@ -74,7 +74,8 @@ public static void DockerPushImage(this BuildContextBase context, DockerImage do
74
74
}
75
75
}
76
76
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 )
78
79
{
79
80
var manifestTags = context . GetDockerTags ( dockerImage ) ;
80
81
foreach ( var tag in manifestTags )
@@ -124,29 +125,18 @@ public static void DockerTestArtifact(this BuildContextBase context, DockerImage
124
125
context . DockerTestRun ( tag , dockerImage . Architecture , "sh" , cmd ) ;
125
126
}
126
127
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 )
128
130
{
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 ) ;
131
133
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 ] ) ;
147
136
}
148
137
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 )
150
140
{
151
141
var settings = GetDockerRunSettings ( context , arch ) ;
152
142
context . Information ( $ "Testing image: { image } ") ;
@@ -156,7 +146,9 @@ private static void DockerTestRun(this BuildContextBase context, string image, A
156
146
Assert . NotNull ( context . Version ? . GitVersion ) ;
157
147
Assert . Contains ( context . Version . GitVersion . FullSemVer ! , output ) ;
158
148
}
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 )
160
152
{
161
153
var name = dockerImage . DockerImageName ( ) ;
162
154
var distro = dockerImage . Distro ;
@@ -171,31 +163,29 @@ private static IEnumerable<string> GetDockerTags(this BuildContextBase context,
171
163
172
164
if ( distro == Constants . DockerDistroLatest && targetFramework == Constants . VersionLatest )
173
165
{
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 } ", } ) ;
179
167
180
168
if ( context . IsStableRelease )
181
169
{
182
- tags . AddRange ( new [ ]
183
- {
170
+ tags . AddRange (
171
+ [
184
172
$ "{ name } :latest",
185
173
$ "{ name } :latest-{ targetFramework } ",
186
174
$ "{ name } :latest-{ distro } ",
187
175
$ "{ name } :latest-{ distro } -{ targetFramework } ",
188
- } ) ;
176
+ ] ) ;
189
177
}
190
178
}
191
179
192
180
if ( ! arch . HasValue ) return tags . Distinct ( ) ;
193
181
194
182
var suffix = arch . Value . ToSuffix ( ) ;
195
183
return tags . Select ( x => $ "{ x } -{ suffix } ") . Distinct ( ) ;
196
-
197
184
}
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
+
199
189
private static DockerContainerRunSettings GetDockerRunSettings ( this BuildContextBase context , Architecture arch )
200
190
{
201
191
var currentDir = context . MakeAbsolute ( context . Directory ( "." ) ) ;
@@ -221,6 +211,7 @@ private static DockerContainerRunSettings GetDockerRunSettings(this BuildContext
221
211
$ "BUILD_SOURCEBRANCH={ context . EnvironmentVariable ( "BUILD_SOURCEBRANCH" ) } "
222
212
] ;
223
213
}
214
+
224
215
if ( context . IsGitHubActionsBuild )
225
216
{
226
217
settings . Env =
0 commit comments