Completed
Push — master ( 30e78d...e3fc58 )
by Greg
04:57 queued 02:39
created

Build::enableBuildKit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Robo\Task\Docker;
4
5
/**
6
 * Builds Docker image
7
 *
8
 * ```php
9
 * <?php
10
 * $this->taskDockerBuild()->run();
11
 *
12
 * $this->taskDockerBuild('path/to/dir')
13
 *      ->tag('database')
14
 *      ->run();
15
 *
16
 * ?>
17
 *
18
 * ```
19
 *
20
 * Class Build
21
 * @package Robo\Task\Docker
22
 */
23
class Build extends Base
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $path;
29
    
30
    /**
31
     * @var bool
32
     */
33
    protected $buildKit = false;
34
35
    /**
36
     * @param string $path
37
     */
38
    public function __construct($path = '.')
39
    {
40
        $this->command = "docker build";
41
        $this->path = $path;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getCommand()
48
    {
49
        $command = $this->command;
50
        if ($this->buildKit) {
51
            $command = 'DOCKER_BUILDKIT=1 ' . $command;
52
        }
53
        return $command . ' ' . $this->arguments . ' ' . $this->path;
54
    }
55
56
    /**
57
     * @param string $tag
58
     *
59
     * @return $this
60
     */
61
    public function tag($tag)
62
    {
63
        return $this->option('-t', $tag);
64
    }
65
    
66
    /**
67
     * @return $this
68
     */
69
    public function enableBuildKit()
70
    {
71
        $this->buildKit = true;
72
        return $this;
73
    }
74
}
75