hammerkit 2.2.0-next.3 → 2.2.0-next.5

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dockerTask = exports.getCapabilityHostConfig = exports.buildCreateOptions = void 0;
3
+ exports.exportGenerates = exports.dockerTask = exports.getCapabilityHostConfig = exports.buildCreateOptions = void 0;
4
4
  const work_item_executions_1 = require("../planner/work-item-executions");
5
5
  const run_labels_1 = require("../docker/run-labels");
6
6
  const execute_docker_1 = require("./execute-docker");
@@ -197,15 +197,32 @@ async function exportGenerates(environment, container, generates) {
197
197
  });
198
198
  await environment.file.createDirectory(generate.path);
199
199
  await new Promise((resolve, reject) => {
200
+ // tar reports an entry it cannot write as a warning and goes on, which would leave the
201
+ // output short without a failure: a warning fails the export. Its info (such as
202
+ // stripping the / of an absolute path) does not.
203
+ const warnings = [];
200
204
  readable
201
205
  .pipe((0, tar_1.extract)({
202
206
  cwd: generate.path,
203
207
  newer: true,
204
208
  stripComponents: 1,
209
+ onwarn: (code, message) => {
210
+ if (code !== 'TAR_ENTRY_INFO') {
211
+ warnings.push(`${code} ${message}`);
212
+ }
213
+ },
205
214
  }))
206
- .on('close', () => resolve())
215
+ .on('close', () => {
216
+ if (warnings.length > 0) {
217
+ reject(new Error(`export of ${generate.path} failed: ${warnings.join('; ')}`));
218
+ }
219
+ else {
220
+ resolve();
221
+ }
222
+ })
207
223
  .on('error', (err) => reject(err));
208
224
  });
209
225
  }
210
226
  }
227
+ exports.exportGenerates = exportGenerates;
211
228
  //# sourceMappingURL=docker-task.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setUserPermissions = exports.prepareMounts = exports.prepareVolume = exports.pullImage = exports.refuseHostLinks = exports.hostedRoot = void 0;
3
+ exports.setUserPermissions = exports.innermostMount = exports.prepareMounts = exports.prepareVolume = exports.pullImage = exports.refuseHostLinks = exports.hostedRoot = void 0;
4
4
  const pull_1 = require("../docker/pull");
5
5
  const get_docker_executor_1 = require("./get-docker-executor");
6
6
  const path_1 = require("path");
@@ -92,6 +92,7 @@ async function prepareMounts(item, environment) {
92
92
  }
93
93
  }
94
94
  if ((0, work_task_1.isContainerWorkTask)(item.data)) {
95
+ await createOutputFoldersUnderMounts(item.data, environment);
95
96
  for (const gen of item.data.generates) {
96
97
  if (!gen.isFile) {
97
98
  continue;
@@ -108,6 +109,40 @@ async function prepareMounts(item, environment) {
108
109
  }
109
110
  }
110
111
  exports.prepareMounts = prepareMounts;
112
+ // The mount that holds a path, the innermost one when several do (`.` and `./app`
113
+ // for `app/node_modules`: `./app`), or undefined when none does.
114
+ function innermostMount(mounts, path) {
115
+ let found;
116
+ for (const mount of mounts) {
117
+ const holds = mount.containerPath === path || (0, get_container_binds_1.isInside)(path, mount.containerPath);
118
+ if (holds && (!found || mount.containerPath.length > found.containerPath.length)) {
119
+ found = mount;
120
+ }
121
+ }
122
+ return found;
123
+ }
124
+ exports.innermostMount = innermostMount;
125
+ // Docker creates the folder of a volume nested under a bind mount on the host, as root and
126
+ // empty, when the container starts. Its outputs could not be exported into it, so the folder
127
+ // is created here, as the user, before the container starts.
128
+ async function createOutputFoldersUnderMounts(task, environment) {
129
+ for (const gen of task.generates) {
130
+ if (gen.isFile) {
131
+ continue;
132
+ }
133
+ const mount = innermostMount(task.mounts, gen.path);
134
+ // the mount is the output's folder itself: created with the mount above
135
+ if (!mount || mount.containerPath === gen.path) {
136
+ continue;
137
+ }
138
+ const target = (0, path_1.join)(mount.localPath, (0, path_1.relative)(mount.containerPath, gen.path));
139
+ // never outside the mount on the host
140
+ if (target !== mount.localPath && !(0, get_container_binds_1.isInside)(target, mount.localPath)) {
141
+ continue;
142
+ }
143
+ await environment.file.createDirectory(target);
144
+ }
145
+ }
111
146
  async function setUserPermissions(item, container, environment) {
112
147
  if (item.data.user) {
113
148
  // On a server only the volumes: a chown as the container's root on a path of the host
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getContainerBinds = void 0;
3
+ exports.getContainerBinds = exports.isInside = void 0;
4
4
  const path_1 = require("path");
5
5
  const dependency_outputs_1 = require("../planner/utils/dependency-outputs");
6
6
  function isInside(path, parent) {
7
7
  const rel = (0, path_1.relative)(parent, path);
8
8
  return rel !== '' && !rel.startsWith('..') && !(0, path_1.isAbsolute)(rel);
9
9
  }
10
+ exports.isInside = isInside;
10
11
  function getContainerBinds(item) {
11
12
  const sources = item.data.src.map((s) => s.absolutePath);
12
13
  const items = [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hammerkit",
3
3
  "description": "Containerized build tool with incremental caching that runs the same build file locally, in Docker and on Kubernetes.",
4
- "version": "2.2.0-next.3",
4
+ "version": "2.2.0-next.5",
5
5
  "keywords": [
6
6
  "build",
7
7
  "build-tool",