Skip to content
Open
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
2 changes: 2 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"nix",
"node",
"npm",
"nub",
"pdm",
"pipenv",
"pixi",
Expand Down Expand Up @@ -146,6 +147,7 @@
"nix",
"node",
"npm",
"nub",
"pdm",
"pipenv",
"pixi",
Expand Down
15 changes: 15 additions & 0 deletions docs/custom-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,21 @@ https://github.com/containerbase/node-re2-prebuild/releases/download/1.20.9/linu
https://github.com/containerbase/node-re2-prebuild/releases/download/1.20.9/linux-x64-108.br
```

## `nub`

Nub releases are downloaded from:

- `https://github.com/nubjs/nub/releases`

Samples:

```txt
https://github.com/nubjs/nub/releases/download/v0.9.3/nub-linux-x64.tar.gz
https://github.com/nubjs/nub/releases/download/v0.9.3/nub-linux-x64.tar.gz.sha256
https://github.com/nubjs/nub/releases/download/v0.9.3/nub-linux-arm64.tar.gz
https://github.com/nubjs/nub/releases/download/v0.9.3/nub-linux-arm64.tar.gz.sha256
```

## `php`

PHP releases are downloaded from:
Expand Down
1 change: 1 addition & 0 deletions packages/base/data/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"nix": {},
"node": {},
"npm": { "type": "npm", "parent": "node" },
"nub": {},
"nuget": { "parent": "mono" },
"paket": { "parent": "dotnet" },
"pdm": { "type": "pip", "parent": "python" },
Expand Down
1 change: 1 addition & 0 deletions packages/base/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const tools = {
nix: {},
node: {},
npm: { type: 'npm', parent: 'node' },
nub: {},
nuget: { parent: 'mono' },
paket: { parent: 'dotnet' },
pdm: { type: 'pip', parent: 'python' },
Expand Down
2 changes: 2 additions & 0 deletions src/cli/install-tool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
YarnVersionResolver,
} from '../tools/node/resolver.ts';
import { NpmBaseInstallService } from '../tools/node/utils.ts';
import { NubInstallService } from '../tools/nub.ts';
import {
ComposerInstallService,
ComposerVersionResolver,
Expand Down Expand Up @@ -182,6 +183,7 @@ async function prepareInstallContainer(): Promise<Container> {
container.bind(INSTALL_TOOL_TOKEN).to(NixInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(NugetInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(NodeInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(NubInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(PaketInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(PhpInstallService);
container.bind(INSTALL_TOOL_TOKEN).to(PixiInstallService);
Expand Down
1 change: 1 addition & 0 deletions src/cli/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const NoPrepareTools = [
'maven',
'mise',
'nix',
'nub',
'nuget',
'npm',
'paket',
Expand Down
75 changes: 75 additions & 0 deletions src/cli/tools/nub.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { arch } from 'node:os';
import { join } from 'node:path';
import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
import { CompressionService, LinkToolService } from '../services/index.ts';
import { NubInstallService } from './nub.ts';
import { scope } from '~test/http-mock.ts';
import { ensurePaths } from '~test/path.ts';
import { checksum, toolContext } from '~test/tool.ts';

const { execaMock } = vi.hoisted(() => ({ execaMock: vi.fn() }));
vi.mock('execa', () => ({ execa: execaMock }));
vi.mock('node:os', async (importOriginal) => ({
...(await importOriginal<typeof import('node:os')>()),
arch: vi.fn(() => 'x64'),
}));

const baseUrl = 'https://github.com';
const archive = 'nub archive';

describe('cli/tools/nub', () => {
beforeAll(async () => {
await ensurePaths(['tmp', 'opt/containerbase/bin']);
});

beforeEach(() => {
vi.mocked(arch).mockReturnValue('x64');
execaMock.mockResolvedValue({ failed: false });
});

test.each([
{ hostArch: 'x64', ghArch: 'x64', version: '0.9.3' },
{ hostArch: 'arm64', ghArch: 'arm64', version: '0.9.2' },
] as const)('install on $ghArch', async ({ hostArch, ghArch, version }) => {
vi.mocked(arch).mockReturnValue(hostArch);
const { svc, pathSvc } = await toolContext(NubInstallService);
const filename = `nub-linux-${ghArch}.tar.gz`;
const releaseUrl = `/nubjs/nub/releases/download/v${version}`;
scope(baseUrl)
.get(`${releaseUrl}/${filename}.sha256`)
.reply(200, `${checksum(archive)} ${filename}\n`)
.get(`${releaseUrl}/${filename}`)
.reply(200, archive);
const extract = vi.spyOn(CompressionService.prototype, 'extract');

await expect(svc.install(version)).resolves.toBeUndefined();

expect(extract).toHaveBeenCalledExactlyOnceWith({
file: expect.stringContaining(filename),
cwd: pathSvc.versionedToolPath('nub', version),
});
});

test('link', async () => {
const { svc, pathSvc } = await toolContext(NubInstallService);
const spy = vi.spyOn(LinkToolService.prototype, 'shellwrapper');

await expect(svc.link('0.9.3')).resolves.toBeUndefined();

expect(spy).toHaveBeenCalledExactlyOnceWith('nub', {
srcDir: join(pathSvc.versionedToolPath('nub', '0.9.3'), 'bin'),
});
});

test('runs the tool test', async () => {
const { svc } = await toolContext(NubInstallService);

await expect(svc.test('0.9.3')).resolves.toBeUndefined();

expect(execaMock).toHaveBeenCalledWith(
'nub',
['--version'],
expect.any(Object),
);
});
});
50 changes: 50 additions & 0 deletions src/cli/tools/nub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../install-tool/base-install.service.ts';

@injectable()
@injectFromHierarchy()
export class NubInstallService extends BaseInstallService {
readonly name = 'nub';

/** The architecture name used by the nub release assets. */
private get ghArch(): string {
Comment thread
jpenilla marked this conversation as resolved.
switch (this.envSvc.arch) {
case 'arm64':
return 'arm64';
case 'amd64':
return 'x64';
}
}

/** Downloads and extracts the nub release, verified against its SHA-256 checksum. */
override async install(version: string): Promise<void> {
const baseUrl = `https://github.com/nubjs/nub/releases/download/v${version}/`;
const filename = `nub-linux-${this.ghArch}.tar.gz`;
const url = `${baseUrl}${filename}`;

const expectedChecksum = await this.getChecksum(`${url}.sha256`);

const file = await this.http.download({
url,
checksumType: 'sha256',
expectedChecksum,
});

await this.pathSvc.ensureToolPath(this.name);
const path = await this.pathSvc.createVersionedToolPath(this.name, version);
// The archive has no top-level folder, so extract without stripping a level.
await this.compress.extract({ file, cwd: path });
}

/** Links the nub binary into the global bin folder. */
override async link(version: string): Promise<void> {
const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin');
await this.shellwrapper({ srcDir: src });
Comment thread
jpenilla marked this conversation as resolved.
}

/** Checks that nub runs without unpacking its embedded runtime. */
override async test(_version: string): Promise<void> {
await this._spawn(this.name, ['--version']);
Comment thread
jpenilla marked this conversation as resolved.
}
}
5 changes: 4 additions & 1 deletion test/latest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ RUN prepare-tool all
RUN set -ex; [ -d /usr/local/erlang ] && echo "works" || exit 1;

#--------------------------------------
# test: apm, bazelisk, buf, bun, deno, devbox, gh, helmfile, kustomize, skopeo, tofu, vendir
# test: apm, bazelisk, buf, bun, deno, devbox, gh, helmfile, kustomize, nub, skopeo, tofu, vendir
#--------------------------------------
FROM base AS teste

Expand All @@ -225,6 +225,9 @@ RUN install-tool buf v1.73.0
# renovate: datasource=npm
RUN install-tool bun 1.4.2

# renovate: datasource=github-releases packageName=nubjs/nub
RUN install-tool nub 0.9.3

# renovate: datasource=github-releases packageName=denoland/deno
RUN install-tool deno 2.9.7

Expand Down
9 changes: 9 additions & 0 deletions test/latest/Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ FROM base AS test-bun
# renovate: datasource=npm
RUN install-tool bun 1.4.2

#--------------------------------------
# Image: nub
#--------------------------------------
FROM base AS test-nub

# renovate: datasource=github-releases packageName=nubjs/nub
RUN install-tool nub 0.9.3

#--------------------------------------
# Image: deno
#--------------------------------------
Expand Down Expand Up @@ -252,6 +260,7 @@ FROM base

COPY --from=test-bazelisk /.dummy /.dummy
COPY --from=test-bun /.dummy /.dummy
COPY --from=test-nub /.dummy /.dummy
COPY --from=test-deno /.dummy /.dummy
COPY --from=test-apko /.dummy /.dummy
COPY --from=test-apm /.dummy /.dummy
Expand Down