diff --git a/src/cli/install-tool/install-tool.service.spec.ts b/src/cli/install-tool/install-tool.service.spec.ts index 687ba00cf8..780c94c8a8 100644 --- a/src/cli/install-tool/install-tool.service.spec.ts +++ b/src/cli/install-tool/install-tool.service.spec.ts @@ -10,6 +10,7 @@ import { import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; import { initializeTools, prepareTools } from '../prepare-tool/index.ts'; import { + BuildListService, CacheService, EnvService, LinkToolService, @@ -219,6 +220,22 @@ class StuckInstallService extends TestInstallService { override readonly parent = 'root-only'; } +/** a npm package, which is listed with its type */ +@injectable() +@injectFromHierarchy() +class NpmTypedInstallService extends TestInstallService { + override readonly name = 'npm-typed'; + override readonly type = 'npm'; +} + +/** a dotnet tool, which is listed as a plain tool */ +@injectable() +@injectFromHierarchy() +class DotnetTypedInstallService extends TestInstallService { + override readonly name = 'dotnet-typed'; + override readonly type = 'dotnet'; +} + /** The pointer of a command. */ function linkPath(name: string): string { return rootPath(`opt/containerbase/links/${name}`); @@ -242,6 +259,8 @@ describe('cli/install-tool/install-tool.service', () => { parent.bind(INSTALL_TOOL_TOKEN).to(ChildInstallService); parent.bind(INSTALL_TOOL_TOKEN).to(OrphanInstallService); parent.bind(INSTALL_TOOL_TOKEN).to(StuckInstallService); + parent.bind(INSTALL_TOOL_TOKEN).to(NpmTypedInstallService); + parent.bind(INSTALL_TOOL_TOKEN).to(DotnetTypedInstallService); let child: Container; let install: InstallToolService; @@ -825,6 +844,109 @@ describe('cli/install-tool/install-tool.service', () => { }); }); + describe('build-time list', () => { + /** Makes the install a root install of an image build. */ + function buildTime(): void { + vi.mocked(isDockerBuild).mockResolvedValue(true); + vi.spyOn(EnvService.prototype, 'isRoot', 'get').mockReturnValue(true); + } + + test('records the installs of an image build', async () => { + buildTime(); + const record = vi + .spyOn(BuildListService.prototype, 'record') + .mockResolvedValue(); + + expect(await install.install('multi', '30.0.0')).toBeUndefined(); + expect(await install.install('child', '6.0.0')).toBeUndefined(); + + expect(record).toHaveBeenNthCalledWith( + 1, + { type: 'tool', tool: 'multi', version: '30.0.0' }, + ['multi', 'multi30'], + 'multi', + ); + expect(record).toHaveBeenNthCalledWith( + 2, + { + type: 'tool', + tool: 'child', + version: '6.0.0', + parent: { name: 'multi', version: '30.0.0' }, + }, + ['child'], + 'child', + ); + }); + + test('records the type of a package', async () => { + buildTime(); + const record = vi + .spyOn(BuildListService.prototype, 'record') + .mockResolvedValue(); + + expect(await install.install('npm-typed', '1.0.0')).toBeUndefined(); + expect(await install.install('dotnet-typed', '1.0.0')).toBeUndefined(); + + expect(record).toHaveBeenNthCalledWith( + 1, + { type: 'npm', tool: 'npm-typed', version: '1.0.0' }, + [], + 'npm-typed', + ); + expect(record).toHaveBeenNthCalledWith( + 2, + { type: 'tool', tool: 'dotnet-typed', version: '1.0.0' }, + [], + 'dotnet-typed', + ); + }); + + test('does not record the v2 shell tools', async () => { + buildTime(); + const record = vi.spyOn(BuildListService.prototype, 'record'); + + expect(await install.install('shell-tool', '3.0.0')).toBeUndefined(); + + expect(record).not.toHaveBeenCalled(); + }); + + test('does not record without a root install of an image build', async () => { + const record = vi.spyOn(BuildListService.prototype, 'record'); + + // not root + vi.mocked(isDockerBuild).mockResolvedValue(true); + expect(await install.install('multi', '31.0.0')).toBeUndefined(); + // not an image build + vi.mocked(isDockerBuild).mockResolvedValue(false); + vi.spyOn(EnvService.prototype, 'isRoot', 'get').mockReturnValue(true); + expect(await install.install('multi', '31.1.0')).toBeUndefined(); + + expect(record).not.toHaveBeenCalled(); + }); + + test('uninstall removes the version from the list', async () => { + expect(await install.install('multi', '32.0.0')).toBeUndefined(); + buildTime(); + const remove = vi + .spyOn(BuildListService.prototype, 'remove') + .mockResolvedValue(); + + expect(await install.uninstall('multi', '32.0.0')).toBeUndefined(); + + expect(remove).toHaveBeenCalledExactlyOnceWith('multi', '32.0.0'); + }); + + test('uninstall keeps the list without a root build', async () => { + expect(await install.install('multi', '33.0.0')).toBeUndefined(); + const remove = vi.spyOn(BuildListService.prototype, 'remove'); + + expect(await install.uninstall('multi', '33.0.0')).toBeUndefined(); + + expect(remove).not.toHaveBeenCalled(); + }); + }); + describe('links', () => { test('a command keeps the version which linked it last', async () => { const pathSvc = await child.getAsync(PathService); diff --git a/src/cli/install-tool/install-tool.service.ts b/src/cli/install-tool/install-tool.service.ts index ff60f7091a..74db41884a 100644 --- a/src/cli/install-tool/install-tool.service.ts +++ b/src/cli/install-tool/install-tool.service.ts @@ -5,6 +5,7 @@ import { deleteAsync } from 'del'; import { inject, injectable, multiInject, optional } from 'inversify'; import { initializeTools, prepareTools } from '../prepare-tool/index.ts'; import { + BuildListService, CacheService, EnvService, IpcServer, @@ -43,6 +44,8 @@ export class InstallToolService { @multiInject(INSTALL_TOOL_TOKEN) @optional() private readonly toolSvcs: BaseInstallService[] = []; + @inject(BuildListService) + private readonly _list!: BuildListService; @inject(CacheService) private readonly cacheSvc!: CacheService; @inject(EnvService) @@ -396,6 +399,10 @@ export class InstallToolService { } await this.versionSvc.removeLinks(vTool); + + if (await this.isBuildTime()) { + await this._list.remove(tool, version); + } } } else { logger.fatal({ tool, version }, 'legacy tools cannot be uninstalled'); @@ -602,11 +609,53 @@ export class InstallToolService { if (!this.envSvc.skipTests) { await toolSvc.test(version); } + + await this.recordBuildTimeInstall(toolSvc, version, parent); } finally { this._link.resetContext(); } } + /** + * Whether the install runs as root during an image build, so it is part of + * the image, see `BuildListService`. + */ + private async isBuildTime(): Promise { + return this.envSvc.isRoot && (await isDockerBuild()); + } + + /** + * Records an install of an image build in the build-time list, with the + * commands the version linked, as the current version of the tool. The v2 + * shell tools can't be installed again by the shims, so they are not listed. + */ + private async recordBuildTimeInstall( + toolSvc: BaseInstallService, + version: string, + parent: ToolState | null, + ): Promise { + if ( + toolSvc instanceof V2ToolInstallService || + !(await this.isBuildTime()) + ) { + return; + } + const links = await this.versionSvc.findLinks({ + name: toolSvc.name, + version, + }); + await this._list.record( + { + type: toolSvc.type && toolSvc.type !== 'dotnet' ? toolSvc.type : 'tool', + tool: toolSvc.name, + version, + ...(parent && { parent: parent.tool }), + }, + links.map(({ name }) => name).toSorted(), + toolSvc.alias, + ); + } + /** * Records which shell wrappers the last link step created, so they can be * removed again when the version is uninstalled, and points the commands at diff --git a/src/cli/services/build-list.service.spec.ts b/src/cli/services/build-list.service.spec.ts new file mode 100644 index 0000000000..c1d9ac8cde --- /dev/null +++ b/src/cli/services/build-list.service.spec.ts @@ -0,0 +1,301 @@ +import fs from 'node:fs/promises'; +import { codeBlock } from 'common-tags'; +import type { Container } from 'inversify'; +import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; +import { logger } from '../utils/index.ts'; +import { BuildListService, PathService } from './index.ts'; +import { testContainer } from '~test/di.ts'; +import { ensurePaths } from '~test/path.ts'; + +describe('cli/services/build-list.service', () => { + let child!: Container; + let svc!: BuildListService; + let pathSvc!: PathService; + + beforeAll(async () => { + await ensurePaths(['opt/containerbase', 'var/lib/containerbase']); + }); + + beforeEach(async () => { + child = await testContainer(); + svc = await child.getAsync(BuildListService); + pathSvc = await child.getAsync(PathService); + await fs.rm(pathSvc.toolInstPath, { force: true }); + await fs.rm(pathSvc.volumeToolInstPath, { force: true }); + }); + + test('paths', () => { + expect(pathSvc.toolInstPath).toBe(`${pathSvc.varPath}/tool.inst`); + expect(pathSvc.volumeToolInstPath).toBe(`${pathSvc.installDir}/.tool.inst`); + }); + + test('a missing list is empty', async () => { + expect(await svc.read()).toEqual([]); + }); + + test('records installs and links in the list and its copy', async () => { + await svc.record({ type: 'tool', tool: 'node', version: '22.0.0' }, [ + 'node', + 'npm', + ]); + await svc.record( + { + type: 'npm', + tool: 'renovate', + version: '39.0.0', + parent: { name: 'node', version: '22.0.0' }, + }, + ['renovate'], + ); + + const expected = `${codeBlock` + i tool node 22.0.0 + c node node 22.0.0 + l node node 22.0.0 + l npm node 22.0.0 + i npm renovate 39.0.0 node 22.0.0 + c renovate renovate 39.0.0 node 22.0.0 + l renovate renovate 39.0.0 + `}\n`; + expect(await fs.readFile(pathSvc.toolInstPath, 'utf8')).toBe(expected); + expect(await fs.readFile(pathSvc.volumeToolInstPath, 'utf8')).toBe( + expected, + ); + expect(await svc.read(pathSvc.volumeToolInstPath)).toEqual([ + { kind: 'i', type: 'tool', tool: 'node', version: '22.0.0' }, + { kind: 'c', alias: 'node', tool: 'node', version: '22.0.0' }, + { kind: 'l', command: 'node', tool: 'node', version: '22.0.0' }, + { kind: 'l', command: 'npm', tool: 'node', version: '22.0.0' }, + { + kind: 'i', + type: 'npm', + tool: 'renovate', + version: '39.0.0', + parent: { name: 'node', version: '22.0.0' }, + }, + { + kind: 'c', + alias: 'renovate', + tool: 'renovate', + version: '39.0.0', + parent: { name: 'node', version: '22.0.0' }, + }, + { + kind: 'l', + command: 'renovate', + tool: 'renovate', + version: '39.0.0', + }, + ]); + }); + + test('a recorded version moves to the end, becomes current and keeps its other parents', async () => { + const renovate = (parent: string) => ({ + type: 'npm' as const, + tool: 'renovate', + version: '39.0.0', + parent: { name: 'node', version: parent }, + }); + await svc.record({ type: 'tool', tool: 'node', version: '22.0.0' }, [ + 'node', + ]); + await svc.record(renovate('22.0.0'), ['renovate']); + await svc.record(renovate('24.0.0'), ['renovate']); + // the current version of node again + await svc.record({ type: 'tool', tool: 'node', version: '22.0.0' }, [ + 'node', + 'npm', + ]); + + expect(await fs.readFile(pathSvc.toolInstPath, 'utf8')).toBe( + `${codeBlock` + i npm renovate 39.0.0 node 22.0.0 + i npm renovate 39.0.0 node 24.0.0 + c renovate renovate 39.0.0 node 24.0.0 + l renovate renovate 39.0.0 + i tool node 22.0.0 + c node node 22.0.0 + l node node 22.0.0 + l npm node 22.0.0 + `}\n`, + ); + }); + + test('a later link of a command replaces the older one', async () => { + await svc.record({ type: 'tool', tool: 'node', version: '20.0.0' }, [ + 'node', + 'npm', + 'npx', + ]); + await svc.record({ type: 'tool', tool: 'node', version: '22.0.0' }, [ + 'node', + 'npm', + ]); + + expect(await fs.readFile(pathSvc.toolInstPath, 'utf8')).toBe( + `${codeBlock` + i tool node 20.0.0 + l npx node 20.0.0 + i tool node 22.0.0 + c node node 22.0.0 + l node node 22.0.0 + l npm node 22.0.0 + `}\n`, + ); + }); + + test('one current version per alias', async () => { + await svc.record( + { type: 'tool', tool: 'java-jdk', version: '21.0.0' }, + ['java'], + 'java', + ); + await svc.record( + { type: 'tool', tool: 'java-jre', version: '17.0.0' }, + ['java'], + 'java', + ); + + expect(await fs.readFile(pathSvc.toolInstPath, 'utf8')).toBe( + `${codeBlock` + i tool java-jdk 21.0.0 + i tool java-jre 17.0.0 + c java java-jre 17.0.0 + l java java-jre 17.0.0 + `}\n`, + ); + }); + + test('remove drops the version with its links', async () => { + await svc.record({ type: 'tool', tool: 'node', version: '22.0.0' }, [ + 'node', + ]); + await svc.record({ type: 'tool', tool: 'node', version: '24.0.0' }, [ + 'node', + ]); + + await svc.remove('node', '22.0.0'); + + expect(await fs.readFile(pathSvc.toolInstPath, 'utf8')).toBe( + `${codeBlock` + i tool node 24.0.0 + c node node 24.0.0 + l node node 24.0.0 + `}\n`, + ); + + await svc.remove('node', '24.0.0'); + + expect(await fs.readFile(pathSvc.toolInstPath, 'utf8')).toBe(''); + expect(await fs.readFile(pathSvc.volumeToolInstPath, 'utf8')).toBe(''); + }); + + test('remove of the current version leaves no current version and no links', async () => { + const node = (version: string) => ({ + type: 'tool' as const, + tool: 'node', + version, + }); + await svc.record(node('20.0.0'), ['node', 'npm', 'npx']); + await svc.record(node('22.0.0'), ['node', 'npm', 'npx']); + + await svc.remove('node', '22.0.0'); + + expect(await fs.readFile(pathSvc.toolInstPath, 'utf8')).toBe( + `i tool node 20.0.0\n`, + ); + }); + + test('skips malformed lines', async () => { + await fs.writeFile( + pathSvc.toolInstPath, + `\n${codeBlock` + i tool node 22.0.0 + i tool node + i unknown node 22.0.0 + i npm renovate 39.0.0 node + i tool a 1.0.0 b 2.0.0 c + l node node 22.0.0 extra + l node node + c node node + c node node 22.0.0 extra + c node node 22.0.0 b + x something + l npm node 22.0.0 + c node node 22.0.0 + c renovate renovate 39.0.0 node 22.0.0 + `}\n\n`, + ); + + expect(await svc.read()).toEqual([ + { kind: 'i', type: 'tool', tool: 'node', version: '22.0.0' }, + { kind: 'l', command: 'npm', tool: 'node', version: '22.0.0' }, + { kind: 'c', alias: 'node', tool: 'node', version: '22.0.0' }, + { + kind: 'c', + alias: 'renovate', + tool: 'renovate', + version: '39.0.0', + parent: { name: 'node', version: '22.0.0' }, + }, + ]); + }); + + describe('an unreadable list', () => { + const err = Object.assign(new Error('EACCES'), { code: 'EACCES' }); + + beforeEach(async () => { + await fs.writeFile(pathSvc.toolInstPath, 'i tool node 22.0.0\n'); + }); + + test('read throws', async () => { + vi.spyOn(fs, 'readFile').mockRejectedValueOnce(err); + + await expect(svc.read()).rejects.toThrow('EACCES'); + }); + + test('record keeps the list and only warns', async () => { + vi.spyOn(fs, 'readFile').mockRejectedValueOnce(err); + + await expect( + svc.record({ type: 'tool', tool: 'node', version: '24.0.0' }, []), + ).resolves.toBeUndefined(); + + expect(await fs.readFile(pathSvc.toolInstPath, 'utf8')).toBe( + 'i tool node 22.0.0\n', + ); + expect(logger.warn).toHaveBeenCalledWith( + { err }, + 'cannot read the build-time tool list', + ); + }); + + test('remove keeps the list and only warns', async () => { + vi.spyOn(fs, 'readFile').mockRejectedValueOnce(err); + + await expect(svc.remove('node', '22.0.0')).resolves.toBeUndefined(); + + expect(await fs.readFile(pathSvc.toolInstPath, 'utf8')).toBe( + 'i tool node 22.0.0\n', + ); + expect(logger.warn).toHaveBeenCalledWith( + { err }, + 'cannot read the build-time tool list', + ); + }); + }); + + test('only warns when the list cannot be written', async () => { + const err = new Error('EROFS'); + vi.spyOn(fs, 'writeFile').mockRejectedValueOnce(err); + + await expect( + svc.record({ type: 'tool', tool: 'node', version: '22.0.0' }, []), + ).resolves.toBeUndefined(); + + expect(logger.warn).toHaveBeenCalledWith( + { err }, + 'cannot write the build-time tool list', + ); + }); +}); diff --git a/src/cli/services/build-list.service.ts b/src/cli/services/build-list.service.ts new file mode 100644 index 0000000000..79c8ef2dce --- /dev/null +++ b/src/cli/services/build-list.service.ts @@ -0,0 +1,240 @@ +import fs from 'node:fs/promises'; +import { bindingScopeValues, inject, injectable } from 'inversify'; +import { + type InstallToolType, + installToolTypes, + logger, +} from '../utils/index.ts'; +import { PathService } from './path.service.ts'; +import type { Tool } from './version.schema.ts'; + +/** How a build-time install was done: `install-tool` or `install-`. */ +export type BuildListType = 'tool' | InstallToolType; + +/** An installed tool version, the `i` line of the list. */ +export interface BuildListInstall { + kind: 'i'; + type: BuildListType; + tool: string; + version: string; + /** The parent tool version the tool was installed for. */ + parent?: Tool; +} + +/** A command linked from an installed tool version, the `l` line. */ +export interface BuildListLink { + kind: 'l'; + command: string; + tool: string; + version: string; +} + +/** The current version of a tool, the `c` line. */ +export interface BuildListCurrent { + kind: 'c'; + /** The name the tool is linked as, eg. `java` for `java-jdk`. */ + alias: string; + tool: string; + version: string; + /** The parent tool version the current version was installed for. */ + parent?: Tool; +} + +export type BuildListEntry = + | BuildListInstall + | BuildListLink + | BuildListCurrent; + +/** + * The tools installed into the image at build time, which an empty + * `/opt/containerbase` volume installs again on first use. It is a plain text + * file, kept in `/var/lib/containerbase/tool.inst` next to `tool.prep` and + * copied to `/opt/containerbase/.tool.inst`, so a copy of the folder knows its + * state. It describes the final state of the image: an uninstall removes the + * version, its commands and, when it was the current one, the current line, + * the same as it does in the image. The lines are in install order: + * + * - `i [ ]`: an installed version + * - `l `: a command the version linked, a later link + * of the command replaces it + * - `c [ ]`: the current version + * of the tool, only these lines make a version current + */ +@injectable(bindingScopeValues.Singleton) +export class BuildListService { + @inject(PathService) + private readonly pathSvc!: PathService; + + /** + * Reads and parses a list, `file` is the one in `/var/lib/containerbase` by + * default. A missing file is an empty list, malformed lines are skipped. + * + * @throws when the file exists but can't be read + */ + async read(file = this.pathSvc.toolInstPath): Promise { + return (await readMissingAsEmpty(file)) + .split('\n') + .map((line) => parseLine(line)) + .filter((entry) => entry !== null); + } + + /** + * Records an install which is linked, so it replaces an earlier record of + * the same version, the current version of the `alias` and the earlier links + * of the commands it linked. A failure is only logged, the list never fails + * an install. + * + * @param alias - the name the tool is linked as, the tool name by default + */ + async record( + install: Omit, + commands: readonly string[], + alias = install.tool, + ): Promise { + const { tool, version, parent } = install; + await this.update((list) => { + const entries = list.filter((entry) => { + switch (entry.kind) { + case 'c': + return entry.alias !== alias; + case 'l': + return ( + !commands.includes(entry.command) && + !(entry.tool === tool && entry.version === version) + ); + case 'i': + return !( + entry.tool === tool && + entry.version === version && + entry.parent?.name === parent?.name && + entry.parent?.version === parent?.version + ); + } + }); + entries.push({ kind: 'i', ...install }); + entries.push({ + kind: 'c', + alias, + tool, + version, + ...(parent && { parent }), + }); + for (const command of commands) { + entries.push({ kind: 'l', command, tool, version }); + } + return entries; + }); + } + + /** + * Removes a tool version from the list, with its commands and, when it is + * the current version, the current line, as an uninstall does in the image. + * A failure is only logged. + */ + async remove(tool: string, version: string): Promise { + await this.update((entries) => + entries.filter( + (entry) => !(entry.tool === tool && entry.version === version), + ), + ); + } + + /** + * Reads the list, changes it and writes it. A list which can't be read is + * kept as it is, as writing would replace it with a partial one. A failure + * is only logged. + */ + private async update( + change: (entries: BuildListEntry[]) => BuildListEntry[], + ): Promise { + let entries: BuildListEntry[]; + try { + entries = await this.read(); + } catch (err) { + logger.warn({ err }, 'cannot read the build-time tool list'); + return; + } + await this.write(change(entries)); + } + + /** + * Writes the list to `/var/lib/containerbase` and the copy to + * `/opt/containerbase`. A failure is only logged. + */ + private async write(entries: BuildListEntry[]): Promise { + const content = entries.map((entry) => formatLine(entry)).join('\n'); + const text = content ? `${content}\n` : ''; + try { + await fs.writeFile(this.pathSvc.toolInstPath, text); + await this.pathSvc.writeFile(this.pathSvc.volumeToolInstPath, text); + } catch (err) { + logger.warn({ err }, 'cannot write the build-time tool list'); + } + } +} + +/** + * The text of a list file, empty when it is missing. + * + * @throws when the file can't be read for another reason + */ +async function readMissingAsEmpty(file: string): Promise { + try { + return await fs.readFile(file, 'utf8'); + } catch (err) { + if ((err as NodeJS.ErrnoException).code === 'ENOENT') { + return ''; + } + throw err; + } +} + +/** One line of the list. */ +function formatLine(entry: BuildListEntry): string { + if (entry.kind === 'l') { + return `l ${entry.command} ${entry.tool} ${entry.version}`; + } + const { tool, version, parent } = entry; + const suffix = parent ? ` ${parent.name} ${parent.version}` : ''; + if (entry.kind === 'c') { + return `c ${entry.alias} ${tool} ${version}${suffix}`; + } + return `i ${entry.type} ${tool} ${version}${suffix}`; +} + +/** The entry of a line, `null` for an empty or malformed one. */ +function parseLine(line: string): BuildListEntry | null { + const tokens = line.trim().split(/\s+/); + const [kind, a, b, c, d, e] = tokens; + if (kind === 'l' && tokens.length === 4) { + return { kind, command: a!, tool: b!, version: c! }; + } + if (kind === 'c' && (tokens.length === 4 || tokens.length === 6)) { + return { + kind, + alias: a!, + tool: b!, + version: c!, + ...(d && e && { parent: { name: d, version: e } }), + }; + } + if ( + kind === 'i' && + isBuildListType(a) && + (tokens.length === 4 || tokens.length === 6) + ) { + return { + kind, + type: a, + tool: b!, + version: c!, + ...(d && e && { parent: { name: d, version: e } }), + }; + } + return null; +} + +/** Whether the value is a list type. */ +function isBuildListType(value: string | undefined): value is BuildListType { + return value === 'tool' || installToolTypes.some((t) => t === value); +} diff --git a/src/cli/services/index.ts b/src/cli/services/index.ts index 1c96644956..1a4a33d858 100644 --- a/src/cli/services/index.ts +++ b/src/cli/services/index.ts @@ -1,5 +1,13 @@ import { type Bind, Container, ContainerModule } from 'inversify'; import { AptService } from './apt.service.ts'; +import { + type BuildListCurrent, + type BuildListEntry, + type BuildListInstall, + type BuildListLink, + BuildListService, + type BuildListType, +} from './build-list.service.ts'; import { CacheService } from './cache.service.ts'; import { CompressionService } from './compression.service.ts'; import { DataService } from './data.service.ts'; @@ -35,6 +43,12 @@ export { type InstalledTool, InstalledTools }; export { AptService, + type BuildListCurrent, + type BuildListEntry, + type BuildListInstall, + type BuildListLink, + type BuildListType, + BuildListService, CacheService, CompressionService, DataService, @@ -63,6 +77,7 @@ export { /** Binds the core services, shared by every container. */ function init(options: T): void { options.bind(AptService).toSelf(); + options.bind(BuildListService).toSelf(); options.bind(CacheService).toSelf(); options.bind(CompressionService).toSelf(); options.bind(DataService).toSelf(); diff --git a/src/cli/services/path.service.ts b/src/cli/services/path.service.ts index 8dc4fdc54e..3919c8469a 100644 --- a/src/cli/services/path.service.ts +++ b/src/cli/services/path.service.ts @@ -272,6 +272,22 @@ export class PathService { return join(this.installDir, 'links'); } + /** + * Path to `/var/lib/containerbase/tool.inst`, the tools installed into the + * image at build time, see `BuildListService`. + */ + get toolInstPath(): string { + return join(this.varPath, 'tool.inst'); + } + + /** + * Path to `/opt/containerbase/.tool.inst`, the copy of the build-time list + * which belongs to the state of the folder. + */ + get volumeToolInstPath(): string { + return join(this.installDir, '.tool.inst'); + } + /** * Path to `/opt/containerbase/ssl`. */