@@ -12,13 +12,20 @@ namespace Common.Utilities
12
12
{
13
13
public static class DockerContextExtensions
14
14
{
15
- public static void DockerBuild ( this BuildContextBase context , DockerImage dockerImage )
15
+ public static void DockerBuild ( this BuildContextBase context , DockerImage dockerImage , bool pushImages )
16
16
{
17
+ if ( context . Version == null ) return ;
18
+
17
19
var ( distro , targetFramework , registry , _) = dockerImage ;
18
20
var workDir = Paths . Src . Combine ( "Docker" ) ;
19
21
var tags = context . GetDockerTags ( dockerImage ) ;
20
22
21
- if ( context . Version == null ) return ;
23
+ var platforms = new List < string > { "linux/amd64" } ;
24
+ // if (targetFramework != "3.1" || !distro.StartsWith("alpine"))
25
+ // {
26
+ // platforms.Add("linux/arm64");
27
+ // }
28
+
22
29
var buildSettings = new DockerImageBuildSettings
23
30
{
24
31
Rm = true ,
@@ -32,11 +39,13 @@ public static void DockerBuild(this BuildContextBase context, DockerImage docker
32
39
$ "DISTRO={ distro } ",
33
40
$ "VERSION={ context . Version . NugetVersion } "
34
41
} ,
35
- // Pull = true,
36
- // Platform = platform // TODO this one is not supported on docker versions < 18.02
42
+ Pull = true ,
43
+ Platform = string . Join ( "," , platforms ) ,
37
44
} ;
38
45
39
- context . DockerBuild ( buildSettings , workDir . ToString ( ) ) ;
46
+ var pushArg = pushImages ? "--push" : string . Empty ;
47
+
48
+ context . DockerBuild ( buildSettings , workDir . ToString ( ) , pushArg ) ;
40
49
}
41
50
42
51
public static void DockerPush ( this BuildContextBase context , DockerImage dockerImage )
@@ -69,6 +78,31 @@ public static void DockerTestArtifact(this BuildContextBase context, DockerImage
69
78
context . DockerTestRun ( tag , "sh" , cmd ) ;
70
79
}
71
80
81
+ private static void DockerBuild (
82
+ this ICakeContext context ,
83
+ DockerImageBuildSettings settings ,
84
+ string path , params string [ ] args )
85
+ {
86
+ GenericDockerRunner < DockerImageBuildSettings > genericDockerRunner =
87
+ new ( context . FileSystem , context . Environment , context . ProcessRunner , context . Tools ) ;
88
+
89
+ string str1 ;
90
+ switch ( string . IsNullOrEmpty ( path ) )
91
+ {
92
+ case false :
93
+ {
94
+ string str2 = path . Trim ( ) ;
95
+ str1 = str2 . Length <= 1 || ! str2 . StartsWith ( "\" " ) || ! str2 . EndsWith ( "\" " ) ? "\" " + path + "\" " : path ;
96
+ break ;
97
+ }
98
+ default :
99
+ str1 = path ;
100
+ break ;
101
+ }
102
+ var additional = args . Concat ( new [ ] { str1 } ) . ToArray ( ) ;
103
+ genericDockerRunner . Run ( "buildx build" , settings , additional ) ;
104
+ }
105
+
72
106
private static void DockerTestRun ( this BuildContextBase context , string image , string command , params string [ ] args )
73
107
{
74
108
var settings = GetDockerRunSettings ( context ) ;
0 commit comments