|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Support\Console\DockerCompose; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\PhpVersion; |
|
6
|
|
|
use App\PorterLibrary; |
|
7
|
|
|
use App\Support\Contracts\ImageRepository; |
|
8
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
9
|
|
|
|
|
10
|
|
|
class YamlBuilder |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var Filesystem */ |
|
13
|
|
|
protected $files; |
|
14
|
|
|
|
|
15
|
|
|
/** @var PorterLibrary */ |
|
16
|
|
|
private $porterLibrary; |
|
17
|
|
|
|
|
18
|
79 |
|
public function __construct(Filesystem $files, PorterLibrary $porterLibrary) |
|
19
|
|
|
{ |
|
20
|
79 |
|
$this->files = $files; |
|
21
|
79 |
|
$this->porterLibrary = $porterLibrary; |
|
22
|
79 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Build the docker-compose.yaml file. |
|
26
|
|
|
* |
|
27
|
|
|
* @param $imageSet |
|
28
|
|
|
* |
|
29
|
|
|
* @throws \Throwable |
|
30
|
|
|
*/ |
|
31
|
4 |
|
public function build(ImageRepository $imageSet) |
|
32
|
|
|
{ |
|
33
|
4 |
|
$this->files->put( |
|
34
|
4 |
|
$this->porterLibrary->dockerComposeFile(), |
|
35
|
4 |
|
view("{$imageSet->getName()}::base")->with([ |
|
36
|
4 |
|
'home' => setting('home'), |
|
37
|
4 |
|
'host_machine_name' => setting('host_machine_name'), |
|
38
|
4 |
|
'activePhpVersions' => PhpVersion::active()->get(), |
|
39
|
4 |
|
'useMysql' => setting('use_mysql') == 'on', |
|
40
|
4 |
|
'useRedis' => setting('use_redis') == 'on', |
|
41
|
4 |
|
'useBrowser' => setting('use_browser') == 'on', |
|
42
|
4 |
|
'imageSet' => $imageSet->getName(), |
|
43
|
4 |
|
'imageSetPath' => $imageSet->getPath(), |
|
44
|
4 |
|
'dockerContext' => $imageSet->getDockerContext(), |
|
45
|
4 |
|
'libraryPath' => $this->porterLibrary->path(), |
|
46
|
4 |
|
])->render() |
|
47
|
|
|
); |
|
48
|
4 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Destroy the docker-compose.yaml file. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function destroy() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->files->delete($this->porterLibrary->dockerComposeFile()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|