1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Support\Images; |
4
|
|
|
|
5
|
|
|
use App\Support\Contracts\ImageRepository as ImageRepositoryContract; |
6
|
|
|
use Symfony\Component\Finder\Finder; |
7
|
|
|
use Symfony\Component\Finder\SplFileInfo; |
8
|
|
|
|
9
|
|
|
class ImageRepository implements ImageRepositoryContract |
10
|
|
|
{ |
11
|
|
|
/** @var string */ |
12
|
|
|
protected $path; |
13
|
|
|
|
14
|
|
|
/** @var string */ |
15
|
|
|
protected $name; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* ImageRepository constructor. |
19
|
|
|
* |
20
|
|
|
* @param $path |
21
|
|
|
* @param $name |
22
|
|
|
*/ |
23
|
|
|
public function __construct($path, $name) |
24
|
|
|
{ |
25
|
|
|
$this->path = $path; |
26
|
|
|
$this->name = $name; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the docker images that are pulled on install. A custom image set name may be specified. |
31
|
|
|
* |
32
|
|
|
* @return array |
33
|
|
|
* @throws \Exception |
34
|
|
|
*/ |
35
|
|
|
public function firstParty() |
36
|
|
|
{ |
37
|
|
|
$images = []; |
38
|
|
|
|
39
|
|
|
foreach ((new Finder)->in($this->path)->directories() as $directory) { |
40
|
|
|
/** @var $directory \Symfony\Component\Finder\SplFileInfo */ |
41
|
|
|
$images[] = new Image($this->getImageName($directory, $this->name), $directory->getRealPath()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $images; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The third party docker images. |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function thirdParty() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
|
|
new Image('mysql:5.7'), |
56
|
|
|
new Image('redis:alpine'), |
57
|
|
|
new Image('andyshinn/dnsmasq'), |
58
|
|
|
new Image('mailhog/mailhog:v1.0.0'), |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Return a full listing of images |
64
|
|
|
* |
65
|
|
|
* @return array |
66
|
|
|
* @throws \Exception |
67
|
|
|
*/ |
68
|
|
|
public function all() |
69
|
|
|
{ |
70
|
|
|
return array_merge($this->firstParty(), $this->thirdParty()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Return the path |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getPath() |
79
|
|
|
{ |
80
|
|
|
return $this->path; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Return the name |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getName() |
89
|
|
|
{ |
90
|
|
|
return $this->name; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the name of the docker image from the directory and image set name. |
95
|
|
|
* |
96
|
|
|
* @param string $imageSetName |
97
|
|
|
* @param SplFileInfo $dir |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
private function getImageName(SplFileInfo $dir, $imageSetName) |
101
|
|
|
{ |
102
|
|
|
return $imageSetName . '-' . $dir->getFileName() . ':latest'; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|