-
Notifications
You must be signed in to change notification settings - Fork 8
/
GenerateStackbrewLibrary.hx
129 lines (117 loc) · 3.43 KB
/
GenerateStackbrewLibrary.hx
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import Update.*;
import sys.io.*;
import haxe.io.*;
using StringTools;
using Lambda;
typedef Entry = {
tags:Array<String>,
?sharedTags:Array<String>,
architectures:Array<String>,
gitCommit:String,
directory:String,
?constraints:Array<String>,
}
class GenerateStackbrewLibrary {
static public function isShared(suffix:String):Bool {
return switch (suffix) {
case "" | "windowsservercore": true;
case _: false;
}
}
static public function verAliases(version:String, suffix:Array<String>):Array<String> {
final versions = [
for (v in [version , verMajorMinorPatch(version), verMajorMinor(version)])
v => v
];
final versions = [
for (v in versions)
for (s in suffix)
s == "" ? v : v + "-" + s
];
versions.sort(function(v1, v2) return v2.length - v1.length);
return versions;
}
static public function fileCommit(file:String):String {
final p = new Process("git", ["log", "-1", "--format=%H", "HEAD", "--", file]);
final commit = p.stdout.readAll().toString().trim();
if (p.exitCode() != 0)
throw p.stderr.readAll().toString().trim();
p.close();
return commit;
}
static public function printEntry(e:Entry):String {
final buf = new StringBuf();
buf.add('Tags: ' + e.tags.join(", ") + "\n");
if (e.sharedTags != null && e.sharedTags.length > 0)
buf.add('SharedTags: ' + e.sharedTags.join(", ") + "\n");
buf.add('Architectures: ' + e.architectures.join(", ") + "\n");
buf.add('GitCommit: ' + e.gitCommit + "\n");
buf.add('Directory: ' + e.directory + "\n");
if (e.constraints != null && e.constraints.length > 0)
buf.add('Constraints: ' + e.constraints.join(", ") + "\n");
return buf.toString();
}
static function main():Void {
final stackbrew = new StringBuf();
stackbrew.add("Maintainers: Andy Li <[email protected]> (@andyli)\n");
stackbrew.add("GitRepo: https://github.com/HaxeFoundation/docker-library-haxe.git\n");
stackbrew.add("\n");
final entries:Array<Entry> = [
for (version in versions)
for (family => variants in variants)
for (i => variant in variants.filter(variant -> version.exclude.indexOf(variant) < 0)) {
final suffix = [variant];
switch [family, i] {
case [Debian, 0]:
suffix.push("");
case [Alpine, 0]:
suffix.push("alpine");
case [WindowsServerCore, _]:
suffix.push("windowsservercore");
suffix.push("");
case _:
//pass
}
{
tags: verAliases(version.version, suffix.filter(function(s) return !isShared(s))),
sharedTags: verAliases(version.version, suffix.filter(isShared)),
architectures: switch (family) {
case WindowsServerCore:
["windows-amd64"];
case Debian:
["amd64", "arm32v7", "arm64v8"];
case Alpine:
["amd64", "arm64v8"];
},
gitCommit: fileCommit(dockerfilePath(version, variant)),
directory: Path.directory(dockerfilePath(version, variant)),
constraints: switch (family) {
case WindowsServerCore:
[variant];
case _:
[];
},
}
}
];
// add "latest" tags
for (family => variants in variants)
for (variant in variants)
{
switch (entries.find(e ->
e.tags.contains('${versions[0].version}-${variant}')
&&
e.sharedTags.contains(versions[0].version)
)) {
case null: //pass
case e:
e.sharedTags.push("latest");
}
}
for (e in entries) {
stackbrew.add(printEntry(e));
stackbrew.add("\n");
}
File.saveContent("haxe", stackbrew.toString());
}
}