-
-
Notifications
You must be signed in to change notification settings - Fork 259
/
update.js
81 lines (75 loc) · 2.13 KB
/
update.js
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
const Handlebars = require("handlebars");
const Promise = require("bluebird");
const merge = require("lodash.merge");
const fs = Promise.promisifyAll(require("fs"));
const path = require("path");
const versions = [
{
baseImage: "ghcr.io/alexcheng1982/docker-apache2-php8",
phpVersion: "8.1",
magento2Version: "2.4.6-p5",
openSearchVersion: "2",
mysqlVersion: "8.0.0",
composerInstallArgs: "",
},
{
baseImage: "ghcr.io/alexcheng1982/docker-apache2-php8",
phpVersion: "8.1",
magento2Version: "2.4.5-p5",
openSearchVersion: "1",
mysqlVersion: "8.0.0",
composerInstallArgs: "",
},
{
baseImage: "ghcr.io/alexcheng1982/docker-apache2-php8",
phpVersion: "8.1",
magento2Version: "2.4.4-p6",
openSearchVersion: "1",
mysqlVersion: "8.0.0",
composerInstallArgs: "",
},
];
function getVersionDir(version) {
return path.join(__dirname, "versions", version);
}
function writeFile(context, version, fileName, template) {
return fs
.readFileAsync(path.join(__dirname, template || `${fileName}.hbs`), "utf8")
.then((content) => Handlebars.compile(content)(context))
.then((content) =>
fs.writeFileAsync(path.join(getVersionDir(version), fileName), content)
);
}
function copyFile(fileName, version) {
return fs.copyFileAsync(
path.join(__dirname, fileName),
path.join(getVersionDir(version), fileName)
);
}
function createVersionDir(version) {
const dir = getVersionDir(version);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
const filesToCopy = [
"auth.json",
"install-magento",
"install-sampledata",
"env",
];
const templatedFiles = ["Dockerfile", "docker-compose.yaml"];
Promise.map(versions, (versionConfig) => {
const context = merge({}, versionConfig);
const version = versionConfig.magento2Version;
createVersionDir(version);
return Promise.map(filesToCopy, (fileToCopy) =>
copyFile(fileToCopy, version)
).then((_) =>
Promise.map(templatedFiles, (templatedFile) =>
writeFile(context, version, templatedFile)
)
);
})
.then(() => console.log("Updated successfully"))
.catch(console.error);