-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate
executable file
·49 lines (46 loc) · 1.58 KB
/
generate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env php
<?php
function copy_dir($src, $dst)
{
if (is_link($src)) {
symlink(readlink($src), $dst);
} elseif (is_dir($src)) {
@mkdir($dst);
foreach (scandir($src) as $file) {
if ($file != '.' && $file != '..') {
copy_dir("$src/$file", "$dst/$file");
}
}
} elseif (is_file($src)) {
copy($src, $dst);
} else {
echo "WARNING: Cannot copy $src (unknown file type)\n";
}
}
function replace_hook_string(string $string, $from, $to): string
{
$walk = function (&$value) {
$value = "{{{$value}}}";
};
if (is_string($from)) {
$from = "{{{$from}}}";
} elseif (is_array($from)) {
array_walk($from, $walk);
}
return str_replace($from, $to, $string);
}
$standard_template = file_get_contents(__DIR__ . '/templates/standard/Dockerfile');
$standard_tags = ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', 'latest'];
foreach ($standard_tags as $tag) {
$content = replace_hook_string($standard_template, 'tag', $tag);
@mkdir(__DIR__ . '/' . $tag);
file_put_contents(__DIR__ . '/' . $tag . '/Dockerfile', $content);
}
// generate alpine
$alpine_template = file_get_contents(__DIR__ . '/templates/alpine/Dockerfile');
$alpine_tags = ['7.2-alpine', '7.3-alpine', '7.4-alpine', '8.0-alpine', '8.1-alpine', '8.2-alpine', '8.3-alpine', 'latest-alpine'];
foreach ($alpine_tags as $tag) {
$content = replace_hook_string($alpine_template, 'tag', $tag);
@mkdir(__DIR__ . '/' . $tag);
file_put_contents(__DIR__ . '/' . $tag . '/Dockerfile', $content);
}