Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/cli/services/path.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs, { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
import { platform } from 'node:os';
import { join } from 'node:path';
import { env } from 'node:process';
import { deleteAsync } from 'del';
import { Container } from 'inversify';
Expand Down Expand Up @@ -145,6 +146,27 @@ describe('cli/services/path.service', () => {
);
});

test('createVersionedToolPath with sub folders', async () => {
await ensurePaths('opt/containerbase/tools');

const path = await pathSvc.createVersionedToolPath(
'jb',
'0.6.0',
'lib',
'bin',
);

expect(path).toBe(rootPath('opt/containerbase/tools/jb/0.6.0/lib/bin'));
// tests don't run as root, so the umask is group writable
const mode = platform() === 'win32' ? 0 : 0o775;
expect((await stat(path)).mode & fileRights).toBe(mode);
expect((await stat(join(path, '..'))).mode & fileRights).toBe(mode);
// an existing folder is fine
await expect(
pathSvc.createVersionedToolPath('jb', '0.6.0', 'lib', 'bin'),
).resolves.toBe(path);
});

test('exportEnv', async () => {
await mkdir(rootPath('usr/local/etc'), { recursive: true });
await pathSvc.exportEnv({ NODE_VERSION: 'v14.17.1' });
Expand Down
17 changes: 13 additions & 4 deletions src/cli/services/path.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,23 @@ export class PathService {
return toolPath;
}

/** Creates the versioned tool path with the configured umask and returns it. */
/**
* Creates the versioned tool path and the optional sub folders below it,
* eg. `bin`, all owned by the configured user with the configured umask.
* Returns the innermost path.
*/
async createVersionedToolPath(
tool: string,
version: string,
...subPaths: string[]
): Promise<string> {
const toolPath = this.versionedToolPath(tool, version);
await this.createDir(toolPath, this.envSvc.umask);
return toolPath;
let path = this.versionedToolPath(tool, version);
await this.createDir(path, this.envSvc.umask);
for (const sub of subPaths) {
path = join(path, sub);
await this.createDir(path, this.envSvc.umask);
Comment thread
viceice marked this conversation as resolved.
}
return path;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/cli/tools/apko.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
Expand Down Expand Up @@ -44,11 +43,11 @@ export class ApkoInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
await this.compress.extract({
file,
cwd: path,
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tools/bazelisk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class BazeliskInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);

const binarypath = join(path, 'bazelisk');
await fs.copyFile(file, binarypath);
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tools/bun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export class BunInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
await this.compress.extract({
file,
cwd: path,
Expand Down
7 changes: 3 additions & 4 deletions src/cli/tools/deno.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
Expand Down Expand Up @@ -42,11 +41,11 @@ export class DenoInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);

await this.compress.extract({
file,
Expand Down
7 changes: 3 additions & 4 deletions src/cli/tools/devbox.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
Expand Down Expand Up @@ -29,11 +28,11 @@ export class DevboxInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
await this.compress.extract({
file,
cwd: path,
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tools/docker/buildx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export class BuildxInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
const bin = join(path, this.name);
await fs.copyFile(file, bin);
await fs.chmod(bin, this.envSvc.umask);
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tools/docker/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export class DockerComposeInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
const bin = join(path, this.name);
await fs.copyFile(file, bin);
await fs.chmod(bin, this.envSvc.umask);
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tools/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export class DockerInstallService extends BaseInstallService {
const url = `https://download.docker.com/linux/static/stable/${this.arch}/docker-${version}.tgz`;
const file = await this.http.download({ url });

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
await this.compress.extract({
file,
cwd: path,
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tools/dotnet/nuget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export class NugetInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
const binary = join(path, filename);
await fs.copyFile(file, binary);
// create shell wrapper to be able to execute it with mono
Expand Down
7 changes: 3 additions & 4 deletions src/cli/tools/flux.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
Expand Down Expand Up @@ -34,11 +33,11 @@ export class FluxInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
await this.compress.extract({
file,
cwd: path,
Expand Down
7 changes: 3 additions & 4 deletions src/cli/tools/haskell/cabal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../../install-tool/base-install.service.ts';
Expand Down Expand Up @@ -49,11 +48,11 @@ export class CabalInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
await this.compress.extract({
file,
cwd: path,
Expand Down
7 changes: 3 additions & 4 deletions src/cli/tools/helm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
Expand All @@ -24,11 +23,11 @@ export class HelmInstallService extends BaseInstallService {
expectedChecksum,
});
await this.pathSvc.ensureToolPath(this.name);
const cwd = path.join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const cwd = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(cwd);
await this.compress.extract({ file, cwd, strip: 1 });
}

Expand Down
7 changes: 3 additions & 4 deletions src/cli/tools/helmfile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
Expand Down Expand Up @@ -27,11 +26,11 @@ export class HelmfileInstallService extends BaseInstallService {
expectedChecksum,
});
await this.pathSvc.ensureToolPath(this.name);
const cwd = path.join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const cwd = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(cwd);
await this.compress.extract({ file, cwd });
}

Expand Down
6 changes: 3 additions & 3 deletions src/cli/tools/jb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export class JsonnetBundlerInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
const target = join(path, this.name);
await fs.copyFile(file, target);
await fs.chmod(target, this.envSvc.umask);
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tools/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export class KubectlInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
await fs.copyFile(file, join(path, filename));
await fs.chmod(join(path, filename), this.envSvc.umask);
}
Expand Down
7 changes: 3 additions & 4 deletions src/cli/tools/kustomize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
Expand Down Expand Up @@ -29,11 +28,11 @@ export class KustomizeInstallService extends BaseInstallService {
expectedChecksum,
});
await this.pathSvc.ensureToolPath(this.name);
const cwd = path.join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const cwd = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(cwd);
await this.compress.extract({ file, cwd });
}

Expand Down
7 changes: 3 additions & 4 deletions src/cli/tools/pixi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';
Expand Down Expand Up @@ -36,11 +35,11 @@ export class PixiInstallService extends BaseInstallService {

await this.pathSvc.ensureToolPath(this.name);

const path = join(
await this.pathSvc.createVersionedToolPath(this.name, version),
const path = await this.pathSvc.createVersionedToolPath(
this.name,
version,
'bin',
);
await fs.mkdir(path);
await this.compress.extract({
file,
cwd: path,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/tools/python/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export abstract class PipBaseInstallService extends PythonBaseInstallService {
}

prefix = path.join(prefix, pythonVersion);
await fs.mkdir(prefix);
await this.pathSvc.createDir(prefix);
await this.createVirtualenv(prefix, env);
await this.installPackage(version, pythonVersion, env, prefix);
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/tools/ruby/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { chmod, mkdir, readFile, rm } from 'node:fs/promises';
import { chmod, readFile, rm } from 'node:fs/promises';
import { join } from 'node:path';
import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is';
import { execa } from 'execa';
Expand Down Expand Up @@ -49,7 +49,7 @@ export abstract class RubyBaseInstallService extends BaseInstallService {
}

prefix = join(prefix, ruby);
await mkdir(prefix);
await this.pathSvc.createDir(prefix);

const res = await execa(
gem,
Expand Down
Loading