arui-scripts 13.3.0-feat-fast-docker-build.3 → 13.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +14 -0
- package/build/bin/index.d.ts +1 -1
- package/build/bin/index.js +13 -13
- package/build/commands/archive-build/index.js +3 -15
- package/build/commands/docker-build/index.js +13 -56
- package/build/commands/docker-build-compiled/index.d.ts +1 -0
- package/build/commands/docker-build-compiled/index.js +53 -0
- package/build/commands/test/index.d.ts +3 -1
- package/build/commands/test/index.js +2 -2
- package/build/commands/util/docker-build.d.ts +14 -0
- package/build/commands/util/docker-build.js +68 -0
- package/build/commands/util/yarn.d.ts +4 -0
- package/build/commands/util/yarn.js +35 -0
- package/build/configs/util/apply-overrides.d.ts +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.js +4 -0
- package/build/templates/dockerfile-compiled.template.d.ts +2 -0
- package/build/templates/dockerfile-compiled.template.js +38 -0
- package/build/tsconfig-local.tsbuildinfo +965 -2589
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# [13.3.0](https://git.moscow.alfaintra.net/ef/arui-scripts/compare/v13.2.1...v13.3.0) (2022-12-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **commands:** use correct naming for docker-build:compiled ([26144f9](https://git.moscow.alfaintra.net/ef/arui-scripts/commit/26144f9a91b94f5c1063fe6e7cfa9c962fca3dbc))
|
|
7
|
+
* **docker-build-compiled:** don't use local dockerfile ([eca88a0](https://git.moscow.alfaintra.net/ef/arui-scripts/commit/eca88a0efef79fd68c349e5e71add934b2f162c2))
|
|
8
|
+
* **docker-build-fast:** don't remove build directory ([0909182](https://git.moscow.alfaintra.net/ef/arui-scripts/commit/09091820f10fffc54702ae6572f6c9a716fe0784))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **docker:** add fast docker build command ([82301a8](https://git.moscow.alfaintra.net/ef/arui-scripts/commit/82301a8d912476fd5516f94083ccd7c5363f4509))
|
|
14
|
+
* **docker-build-compiled:** ignore node_modules automatically ([35b4955](https://git.moscow.alfaintra.net/ef/arui-scripts/commit/35b49550e73472eb6d38af1af832708c7f0bc271))
|
|
15
|
+
* **docker-fast:** don't build anything inside of container ([8f255bd](https://git.moscow.alfaintra.net/ef/arui-scripts/commit/8f255bd8fb9818a8498bddee71ef83ce4a7ba11b))
|
|
16
|
+
|
|
1
17
|
# [13.3.0-feat-fast-docker-build.3](https://git.moscow.alfaintra.net/ef/arui-scripts/compare/v13.3.0-feat-fast-docker-build.2...v13.3.0-feat-fast-docker-build.3) (2022-12-06)
|
|
2
18
|
|
|
3
19
|
|
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ npm install arui-scripts --save-dev
|
|
|
42
42
|
- `arui-scripts start` - запускает WebpackDevServer для фронтенда и webpack в режиме `--watch` для сервера.
|
|
43
43
|
- `arui-scripts build` - компилирует клиент и сервер для использования в production
|
|
44
44
|
- `arui-scripts docker-build` - собирает docker контейнер c production билдом и загружает его в артифактори
|
|
45
|
+
- `arui-scripts docker-build:compiled` - собирает docker контейнер c production билдом, предполагая что код приложения уже скомпилирован
|
|
45
46
|
- `arui-scripts test` - запускает jest тесты.
|
|
46
47
|
- `arui-scripts archive-build` - собирает архив с production билдом
|
|
47
48
|
- `arui-scripts bundle-analyze` - запускает [webpack-bundle-analyzer](https://www.npmjs.com/package/webpack-bundle-analyzer) для prod версии клиентского кода
|
|
@@ -318,6 +319,18 @@ docker run -p 8080:8080 container-name:version ./start.sh
|
|
|
318
319
|
|
|
319
320
|
`Dockerfile` в корне проекта имеет приоритет над overrides.
|
|
320
321
|
|
|
322
|
+
docker compiled
|
|
323
|
+
---
|
|
324
|
+
Команда `arui-scripts docker-build:compiled` во многом аналогична `docker-build`, но вместо сборки проекта использует уже скомпилированный в папку `.build` код.
|
|
325
|
+
При этом в контейнер будут устанавливаться только production зависимости.
|
|
326
|
+
Команду предполагается использовать в CI/CD, когда проект собирается в отдельном шаге и результат сборки уже доступен.
|
|
327
|
+
За счет того, что в контейнер папки node_modules не копируются, а устанавливаются только production зависимости, скорость сборки контейнера значительно увеличивается.
|
|
328
|
+
В процессе сборки так же будет модифицироваться файл `.dockerignore` для того чтобы гарантировано исключить папку `node_modules` из контекста сборки докера.
|
|
329
|
+
|
|
330
|
+
`arui-scripts docker-build:compiled` имеет те же опции, что и `arui-scripts docker-build`.
|
|
331
|
+
Dockerfile при этом будет сгенерирован автоматически, но вы можете переопределить его используя механизм [overrides](#тонкая-настройка).
|
|
332
|
+
Локальный `Dockerfile` в корне проекта в данном случае полностью игнорируется.
|
|
333
|
+
|
|
321
334
|
archive
|
|
322
335
|
---
|
|
323
336
|
|
|
@@ -575,6 +588,7 @@ export default overrides;
|
|
|
575
588
|
- `Dockerfile` - докерфайл, который будет использоваться для сборки контейнера.
|
|
576
589
|
Базовый шаблон [тут](./src/templates/dockerfile.template.ts).
|
|
577
590
|
[`Dockerfile` в корне проекта](#docker) имеет приоритет над overrides.
|
|
591
|
+
- `DockerfileCompiled` - докерфайл, который будет использоваться для сборки контейнера при использовании команды `arui-scripts docker-build:compiled`
|
|
578
592
|
- `nginx` - шаблон конфигурации для nginx внутри контейнера.
|
|
579
593
|
Базовый шаблон [тут](./src/templates/nginx.conf.template.ts).
|
|
580
594
|
[Файл `nginx.conf`](#конфигурация-nginx) в корне имеет приоритет над оверрайдами.
|
package/build/bin/index.d.ts
CHANGED
package/build/bin/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
/* eslint import/no-dynamic-require: 0 */
|
|
4
|
-
const commands =
|
|
5
|
-
'start',
|
|
6
|
-
'build',
|
|
7
|
-
'docker-build',
|
|
8
|
-
'docker-build-
|
|
9
|
-
'test',
|
|
10
|
-
'ensure-yarn',
|
|
11
|
-
'archive-build',
|
|
12
|
-
'bundle-analyze',
|
|
13
|
-
|
|
4
|
+
const commands = {
|
|
5
|
+
start: () => require('../commands/start'),
|
|
6
|
+
build: () => require('../commands/build'),
|
|
7
|
+
'docker-build': () => require('../commands/docker-build'),
|
|
8
|
+
'docker-build:compiled': () => require('../commands/docker-build-compiled'),
|
|
9
|
+
test: () => require('../commands/test'),
|
|
10
|
+
'ensure-yarn': () => require('../commands/ensure-yarn'),
|
|
11
|
+
'archive-build': () => require('../commands/archive-build'),
|
|
12
|
+
'bundle-analyze': () => require('../commands/bundle-analyze'),
|
|
13
|
+
};
|
|
14
14
|
const command = process.argv[2];
|
|
15
|
-
if (!command || commands
|
|
16
|
-
console.error(`Please specify one of available commands: ${commands.map(c => `"${c}"`).join(' ')}`);
|
|
15
|
+
if (!command || !commands[command]) {
|
|
16
|
+
console.error(`Please specify one of available commands: ${Object.keys(commands).map(c => `"${c}"`).join(' ')}`);
|
|
17
17
|
process.exit(-1);
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
commands[command]();
|
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const shelljs_1 = __importDefault(require("shelljs"));
|
|
16
15
|
const tar_1 = __importDefault(require("tar"));
|
|
17
16
|
const path_1 = __importDefault(require("path"));
|
|
18
17
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -20,6 +19,7 @@ const app_configs_1 = __importDefault(require("../../configs/app-configs"));
|
|
|
20
19
|
const exec_1 = __importDefault(require("../util/exec"));
|
|
21
20
|
const nginx_conf_template_1 = __importDefault(require("../../templates/nginx.conf.template"));
|
|
22
21
|
const start_template_1 = __importDefault(require("../../templates/start.template"));
|
|
22
|
+
const yarn_1 = require("../util/yarn");
|
|
23
23
|
const tempDirName = '.archive-build';
|
|
24
24
|
const nginxConfFileName = 'nginx.conf';
|
|
25
25
|
const startScriptFileName = 'start.sh';
|
|
@@ -49,20 +49,8 @@ const packageJsonPath = path_1.default.join(app_configs_1.default.cwd, packageJs
|
|
|
49
49
|
yield exec_1.default('npm run build');
|
|
50
50
|
console.timeEnd('Build application time');
|
|
51
51
|
console.time('Remove build dependencies time');
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const yarnVersion = shelljs_1.default.exec('yarn -v', { silent: true });
|
|
55
|
-
const yarnMajorVersion = Number(yarnVersion.split('.')[0]);
|
|
56
|
-
if (yarnMajorVersion > 1) {
|
|
57
|
-
yield exec_1.default('yarn workspaces focus --production --all');
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
yield exec_1.default('yarn install --production --ignore-optional --frozen-lockfile --ignore-scripts --prefer-offline');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
yield exec_1.default('npm prune --production');
|
|
65
|
-
}
|
|
52
|
+
const pruneCommand = yarn_1.getPruningCommand();
|
|
53
|
+
yield exec_1.default(pruneCommand);
|
|
66
54
|
console.timeEnd('Remove build dependencies time');
|
|
67
55
|
console.time('Archive build time');
|
|
68
56
|
yield Promise.all([
|
|
@@ -12,59 +12,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const path_1 = __importDefault(require("path"));
|
|
16
|
-
const shelljs_1 = __importDefault(require("shelljs"));
|
|
17
15
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
16
|
const app_configs_1 = __importDefault(require("../../configs/app-configs"));
|
|
19
17
|
const dockerfile_template_1 = __importDefault(require("../../templates/dockerfile.template"));
|
|
20
18
|
const nginx_conf_template_1 = __importDefault(require("../../templates/nginx.conf.template"));
|
|
21
19
|
const start_template_1 = __importDefault(require("../../templates/start.template"));
|
|
22
20
|
const exec_1 = __importDefault(require("../util/exec"));
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let dockerRegistry = app_configs_1.default.dockerRegistry;
|
|
26
|
-
const commandLineArguments = process.argv.slice(3);
|
|
27
|
-
commandLineArguments.forEach(arg => {
|
|
28
|
-
let [argName, argValue] = arg.split('=');
|
|
29
|
-
argName = argName.toLowerCase().trim();
|
|
30
|
-
argValue = argValue ? argValue.trim() : '';
|
|
31
|
-
switch (argName) {
|
|
32
|
-
case 'version':
|
|
33
|
-
imageVersion = argValue;
|
|
34
|
-
break;
|
|
35
|
-
case 'name':
|
|
36
|
-
imageName = argValue;
|
|
37
|
-
break;
|
|
38
|
-
case 'registry':
|
|
39
|
-
dockerRegistry = argValue;
|
|
40
|
-
break;
|
|
41
|
-
default:
|
|
42
|
-
console.warn(`Unknown argument ${argName}`);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
const tempDirName = '.docker-build';
|
|
46
|
-
const pathToTempDir = path_1.default.join(app_configs_1.default.cwd, tempDirName);
|
|
47
|
-
const imageFullName = `${dockerRegistry ? `${dockerRegistry}/` : ''}${imageName}:${imageVersion}`;
|
|
21
|
+
const docker_build_1 = require("../util/docker-build");
|
|
22
|
+
const yarn_1 = require("../util/yarn");
|
|
48
23
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const { imageFullName, pathToTempDir, tempDirName } = docker_build_1.getBuildParamsFromArgs();
|
|
49
25
|
try {
|
|
50
26
|
console.log(`Build docker image ${imageFullName}`);
|
|
51
27
|
console.time('Total time');
|
|
52
28
|
console.time('Setting up time');
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
: dockerfile_template_1.default;
|
|
62
|
-
yield Promise.all([
|
|
63
|
-
fs_extra_1.default.writeFile(path_1.default.join(pathToTempDir, 'Dockerfile'), dockerfile, 'utf8'),
|
|
64
|
-
fs_extra_1.default.writeFile(path_1.default.join(pathToTempDir, 'nginx.conf'), nginxConf, 'utf8'),
|
|
65
|
-
fs_extra_1.default.writeFile(path_1.default.join(pathToTempDir, 'start.sh'), start_template_1.default, { encoding: 'utf8', mode: 0o555 }),
|
|
66
|
-
fs_extra_1.default.remove(app_configs_1.default.buildPath),
|
|
67
|
-
]);
|
|
29
|
+
yield docker_build_1.prepareFilesForDocker({
|
|
30
|
+
pathToTempDir,
|
|
31
|
+
dockerfileTemplate: dockerfile_template_1.default,
|
|
32
|
+
nginxConfTemplate: nginx_conf_template_1.default,
|
|
33
|
+
startScript: start_template_1.default,
|
|
34
|
+
allowLocalDockerfile: true,
|
|
35
|
+
});
|
|
36
|
+
yield fs_extra_1.default.remove(app_configs_1.default.buildPath);
|
|
68
37
|
console.timeEnd('Setting up time');
|
|
69
38
|
console.time('Build application time');
|
|
70
39
|
// run build script
|
|
@@ -72,20 +41,8 @@ const imageFullName = `${dockerRegistry ? `${dockerRegistry}/` : ''}${imageName}
|
|
|
72
41
|
console.timeEnd('Build application time');
|
|
73
42
|
if (app_configs_1.default.removeDevDependenciesDuringDockerBuild) {
|
|
74
43
|
console.time('Remove dev dependencies time');
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const yarnVersion = shelljs_1.default.exec('yarn -v', { silent: true });
|
|
78
|
-
const yarnMajorVersion = Number(yarnVersion.split('.')[0]);
|
|
79
|
-
if (yarnMajorVersion > 1) {
|
|
80
|
-
yield exec_1.default('yarn workspaces focus --production --all');
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
yield exec_1.default('yarn install --production --ignore-optional --frozen-lockfile --ignore-scripts --prefer-offline');
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
yield exec_1.default('npm prune --production');
|
|
88
|
-
}
|
|
44
|
+
const pruneCommand = yarn_1.getPruningCommand();
|
|
45
|
+
yield exec_1.default(pruneCommand);
|
|
89
46
|
console.timeEnd('Remove dev dependencies time');
|
|
90
47
|
}
|
|
91
48
|
console.time('Build docker image time');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
16
|
+
const app_configs_1 = __importDefault(require("../../configs/app-configs"));
|
|
17
|
+
const dockerfile_compiled_template_1 = __importDefault(require("../../templates/dockerfile-compiled.template"));
|
|
18
|
+
const nginx_conf_template_1 = __importDefault(require("../../templates/nginx.conf.template"));
|
|
19
|
+
const start_template_1 = __importDefault(require("../../templates/start.template"));
|
|
20
|
+
const exec_1 = __importDefault(require("../util/exec"));
|
|
21
|
+
const docker_build_1 = require("../util/docker-build");
|
|
22
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const { imageFullName, pathToTempDir, tempDirName } = docker_build_1.getBuildParamsFromArgs();
|
|
24
|
+
try {
|
|
25
|
+
console.log(`Build docker image ${imageFullName}`);
|
|
26
|
+
console.time('Total time');
|
|
27
|
+
yield docker_build_1.prepareFilesForDocker({
|
|
28
|
+
pathToTempDir,
|
|
29
|
+
dockerfileTemplate: dockerfile_compiled_template_1.default,
|
|
30
|
+
nginxConfTemplate: nginx_conf_template_1.default,
|
|
31
|
+
startScript: start_template_1.default,
|
|
32
|
+
allowLocalDockerfile: false,
|
|
33
|
+
});
|
|
34
|
+
yield exec_1.default('echo "node_modules" > .dockerignore');
|
|
35
|
+
yield exec_1.default(`docker build -f "./${tempDirName}/Dockerfile" \\
|
|
36
|
+
--build-arg START_SH_LOCATION="./${tempDirName}/start.sh" \\
|
|
37
|
+
--build-arg NGINX_CONF_LOCATION="./${tempDirName}/nginx.conf" -t ${imageFullName} .`);
|
|
38
|
+
yield fs_extra_1.default.remove(pathToTempDir);
|
|
39
|
+
// guard against pushing the image during tests
|
|
40
|
+
if (!app_configs_1.default.debug) {
|
|
41
|
+
yield exec_1.default(`docker push ${imageFullName}`);
|
|
42
|
+
}
|
|
43
|
+
console.timeEnd('Total time');
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
yield fs_extra_1.default.remove(pathToTempDir);
|
|
47
|
+
console.error('Error during docker-build.');
|
|
48
|
+
if (app_configs_1.default.debug) {
|
|
49
|
+
console.error(err);
|
|
50
|
+
}
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
}))();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
process.env.BABEL_ENV = 'test';
|
|
4
4
|
process.env.NODE_ENV = 'test';
|
|
5
5
|
process.env.PUBLIC_URL = '';
|
|
6
|
-
const
|
|
6
|
+
const jestRunner = require('jest');
|
|
7
7
|
const jestConfig = require('../../configs/jest');
|
|
8
8
|
// Makes the script crash on unhandled rejections instead of silently
|
|
9
9
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
@@ -14,4 +14,4 @@ process.on('unhandledRejection', err => {
|
|
|
14
14
|
// Skip 'node', 'arui-scripts' and 'test' arguments and take all the rest (or none if there is no more arguments).
|
|
15
15
|
const argv = process.argv.slice(3);
|
|
16
16
|
argv.push('--config', JSON.stringify(jestConfig));
|
|
17
|
-
|
|
17
|
+
jestRunner.run(argv);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function getBuildParamsFromArgs(): {
|
|
2
|
+
pathToTempDir: string;
|
|
3
|
+
imageFullName: string;
|
|
4
|
+
tempDirName: string;
|
|
5
|
+
};
|
|
6
|
+
declare type PrepareFilesForDockerParams = {
|
|
7
|
+
dockerfileTemplate: string;
|
|
8
|
+
nginxConfTemplate: string;
|
|
9
|
+
startScript: string;
|
|
10
|
+
pathToTempDir: string;
|
|
11
|
+
allowLocalDockerfile: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function prepareFilesForDocker({ dockerfileTemplate, nginxConfTemplate, startScript, pathToTempDir, allowLocalDockerfile, }: PrepareFilesForDockerParams): Promise<void>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.prepareFilesForDocker = exports.getBuildParamsFromArgs = void 0;
|
|
16
|
+
const app_configs_1 = __importDefault(require("../../configs/app-configs"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
|
+
function getBuildParamsFromArgs() {
|
|
20
|
+
let imageVersion = app_configs_1.default.version;
|
|
21
|
+
let imageName = app_configs_1.default.name;
|
|
22
|
+
let dockerRegistry = app_configs_1.default.dockerRegistry;
|
|
23
|
+
const commandLineArguments = process.argv.slice(3);
|
|
24
|
+
commandLineArguments.forEach(arg => {
|
|
25
|
+
let [argName, argValue] = arg.split('=');
|
|
26
|
+
argName = argName.toLowerCase().trim();
|
|
27
|
+
argValue = argValue ? argValue.trim() : '';
|
|
28
|
+
switch (argName) {
|
|
29
|
+
case 'version':
|
|
30
|
+
imageVersion = argValue;
|
|
31
|
+
break;
|
|
32
|
+
case 'name':
|
|
33
|
+
imageName = argValue;
|
|
34
|
+
break;
|
|
35
|
+
case 'registry':
|
|
36
|
+
dockerRegistry = argValue;
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
console.warn(`Unknown argument ${argName}`);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const tempDirName = '.docker-build';
|
|
43
|
+
const pathToTempDir = path_1.default.join(app_configs_1.default.cwd, tempDirName);
|
|
44
|
+
const imageFullName = `${dockerRegistry ? `${dockerRegistry}/` : ''}${imageName}:${imageVersion}`;
|
|
45
|
+
return {
|
|
46
|
+
pathToTempDir,
|
|
47
|
+
imageFullName,
|
|
48
|
+
tempDirName,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.getBuildParamsFromArgs = getBuildParamsFromArgs;
|
|
52
|
+
function prepareFilesForDocker({ dockerfileTemplate, nginxConfTemplate, startScript, pathToTempDir, allowLocalDockerfile, }) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
yield fs_extra_1.default.emptyDir(pathToTempDir);
|
|
55
|
+
const nginxConf = app_configs_1.default.localNginxConf
|
|
56
|
+
? yield fs_extra_1.default.readFile(app_configs_1.default.localNginxConf, 'utf8')
|
|
57
|
+
: nginxConfTemplate;
|
|
58
|
+
const dockerfile = app_configs_1.default.localDockerfile && allowLocalDockerfile
|
|
59
|
+
? yield fs_extra_1.default.readFile(app_configs_1.default.localDockerfile, 'utf8')
|
|
60
|
+
: dockerfileTemplate;
|
|
61
|
+
yield Promise.all([
|
|
62
|
+
fs_extra_1.default.writeFile(path_1.default.join(pathToTempDir, 'Dockerfile'), dockerfile, 'utf8'),
|
|
63
|
+
fs_extra_1.default.writeFile(path_1.default.join(pathToTempDir, 'nginx.conf'), nginxConf, 'utf8'),
|
|
64
|
+
fs_extra_1.default.writeFile(path_1.default.join(pathToTempDir, 'start.sh'), startScript, { encoding: 'utf8', mode: 0o555 }),
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.prepareFilesForDocker = prepareFilesForDocker;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPruningCommand = exports.getYarnVersion = void 0;
|
|
7
|
+
const app_configs_1 = __importDefault(require("../../configs/app-configs"));
|
|
8
|
+
const shelljs_1 = __importDefault(require("shelljs"));
|
|
9
|
+
function getYarnVersion() {
|
|
10
|
+
if (app_configs_1.default.useYarn && shelljs_1.default.which('yarn')) {
|
|
11
|
+
const yarnVersion = shelljs_1.default.exec('yarn -v', { silent: true });
|
|
12
|
+
const yarnMajorVersion = Number(yarnVersion.split('.')[0]);
|
|
13
|
+
return yarnMajorVersion > 1 ? '2+' : '1';
|
|
14
|
+
}
|
|
15
|
+
return 'unavailable';
|
|
16
|
+
}
|
|
17
|
+
exports.getYarnVersion = getYarnVersion;
|
|
18
|
+
function getPruningCommand() {
|
|
19
|
+
const yarnVersion = getYarnVersion();
|
|
20
|
+
switch (yarnVersion) {
|
|
21
|
+
case '1': {
|
|
22
|
+
return 'yarn install --production --ignore-optional --frozen-lockfile --ignore-scripts --prefer-offline';
|
|
23
|
+
}
|
|
24
|
+
case '2+': {
|
|
25
|
+
return 'yarn workspaces focus --production --all';
|
|
26
|
+
}
|
|
27
|
+
case 'unavailable': {
|
|
28
|
+
return 'npm prune --production';
|
|
29
|
+
}
|
|
30
|
+
default: {
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.getPruningCommand = getPruningCommand;
|
package/build/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export type { OverrideFile } from './configs/util/apply-overrides';
|
|
2
2
|
export type { PackageSettings } from './configs/app-configs/available-package-settings';
|
|
3
|
+
export { prepareFilesForDocker } from './commands/util/docker-build';
|
|
4
|
+
export { getBuildParamsFromArgs } from './commands/util/docker-build';
|
package/build/index.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var docker_build_1 = require("./commands/util/docker-build");
|
|
4
|
+
Object.defineProperty(exports, "prepareFilesForDocker", { enumerable: true, get: function () { return docker_build_1.prepareFilesForDocker; } });
|
|
5
|
+
var docker_build_2 = require("./commands/util/docker-build");
|
|
6
|
+
Object.defineProperty(exports, "getBuildParamsFromArgs", { enumerable: true, get: function () { return docker_build_2.getBuildParamsFromArgs; } });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const app_configs_1 = __importDefault(require("../configs/app-configs"));
|
|
7
|
+
const apply_overrides_1 = __importDefault(require("../configs/util/apply-overrides"));
|
|
8
|
+
const yarn_1 = require("../commands/util/yarn");
|
|
9
|
+
const pruneCommand = yarn_1.getPruningCommand();
|
|
10
|
+
const dockerfileTemplate = `
|
|
11
|
+
FROM ${app_configs_1.default.baseDockerImage}
|
|
12
|
+
ARG START_SH_LOCATION
|
|
13
|
+
ARG NGINX_CONF_LOCATION
|
|
14
|
+
|
|
15
|
+
WORKDIR /src
|
|
16
|
+
|
|
17
|
+
# Полу-статичные файлы, могут легко кешироваться
|
|
18
|
+
ADD $START_SH_LOCATION /src/start.sh
|
|
19
|
+
ADD $NGINX_CONF_LOCATION /src/nginx.conf
|
|
20
|
+
|
|
21
|
+
# Зависимости. При некоторой удаче могут кешироваться и соответственно кешировать установку зависимостей
|
|
22
|
+
ADD --chown=nginx:nginx yarn.lock /src/yarn.lock
|
|
23
|
+
ADD --chown=nginx:nginx package.json /src/package.json
|
|
24
|
+
RUN ${pruneCommand} && \\
|
|
25
|
+
yarn cache clean
|
|
26
|
+
|
|
27
|
+
ADD --chown=nginx:nginx . /src
|
|
28
|
+
|
|
29
|
+
# Создаем директории для nginx и выставляем правильные права
|
|
30
|
+
RUN mkdir -p /var/lib/nginx && \
|
|
31
|
+
chown -R nginx:nginx /var/lib/nginx && \
|
|
32
|
+
chown -R nginx:nginx /var/log/nginx && \
|
|
33
|
+
chown -R nginx:nginx /etc/nginx/conf.d
|
|
34
|
+
RUN touch /var/run/nginx.pid && \
|
|
35
|
+
chown -R nginx:nginx /var/run/nginx.pid
|
|
36
|
+
USER nginx
|
|
37
|
+
`;
|
|
38
|
+
exports.default = apply_overrides_1.default('DockerfileCompiled', dockerfileTemplate);
|