2
2
3
3
namespace Laravel \VaporCli ;
4
4
5
+ use Illuminate \Support \Collection ;
5
6
use Illuminate \Support \Str ;
6
7
use Symfony \Component \Process \Process ;
7
8
@@ -15,19 +16,43 @@ class Docker
15
16
* @param string $environment
16
17
* @return void
17
18
*/
18
- public static function build ($ path , $ project , $ environment )
19
+ public static function build ($ path , $ project , $ environment, $ cliBuildArgs )
19
20
{
20
21
Process::fromShellCommandline (
21
- sprintf ('docker build --pull --file=%s.Dockerfile --tag=%s . ' ,
22
- $ environment ,
23
- Str::slug ($ project ).': ' .$ environment
24
- ),
22
+ static ::buildCommand ($ project , $ environment , $ cliBuildArgs , Manifest::dockerBuildArgs ($ environment )),
25
23
$ path
26
24
)->setTimeout (null )->mustRun (function ($ type , $ line ) {
27
25
Helpers::write ($ line );
28
26
});
29
27
}
30
28
29
+ /**
30
+ * Create the Docker build command string.
31
+ *
32
+ * @param string $project
33
+ * @param string $environment
34
+ * @param array $cliBuildArgs
35
+ * @param array $manifestBuildArgs
36
+ * @return string
37
+ */
38
+ public static function buildCommand ($ project , $ environment , $ cliBuildArgs , $ manifestBuildArgs )
39
+ {
40
+ return sprintf ('docker build --pull --file=%s.Dockerfile --tag=%s %s. ' ,
41
+ $ environment ,
42
+ Str::slug ($ project ).': ' .$ environment ,
43
+ Collection::make ($ manifestBuildArgs )
44
+ ->merge (Collection::make ($ cliBuildArgs )
45
+ ->mapWithKeys (function ($ value ) {
46
+ [$ key , $ value ] = explode ('= ' , $ value , 2 );
47
+
48
+ return [$ key => $ value ];
49
+ })
50
+ )->map (function ($ value , $ key ) {
51
+ return '--build-arg= ' .escapeshellarg ("{$ key }= {$ value }" ).' ' ;
52
+ })->implode ('' )
53
+ );
54
+ }
55
+
31
56
/**
32
57
* Publish a docker image.
33
58
*
0 commit comments