diff --git a/compile/compile.test.ts b/compile/compile.test.ts index af5139d7a2c..8252abc558e 100644 --- a/compile/compile.test.ts +++ b/compile/compile.test.ts @@ -5,7 +5,7 @@ import assert, { deepEqual, throws } from 'node:assert' import { dirname } from 'node:path' import { DotGit } from '@hackbg/repo' import { Program, Deploy } from '@fadroma/agent' -import { OCIConnection, OCIImage } from '@fadroma/oci' +import * as OCI from '@fadroma/oci' import { getCompiler, RawLocalRustCompiler, ContainerizedLocalRustCompiler } from './compile' import { packageRoot } from './package' @@ -50,7 +50,7 @@ export async function testBuildContainer () { }) new ContainerizedLocalRustCompiler({ //@ts-ignore - dockerImage: new OCIImage({ engine: null, name: 'test' }) as any + dockerImage: new OCI.Image({ engine: null, name: 'test' }) as any }) } diff --git a/compile/compile.ts b/compile/compile.ts index 50f94585027..5f54c0d50f2 100644 --- a/compile/compile.ts +++ b/compile/compile.ts @@ -353,12 +353,12 @@ const DEFAULT_ENGINE_SOCKET = '/var/run/docker.sock' /** Runs the build script in a container. */ export class ContainerizedLocalRustCompiler extends LocalRustCompiler { /** Used to launch build container. */ - engine: OCI.OCIConnection + engine: OCI.Connection /** Path to Docker API endpoint. */ engineSocket: string = this.config.getString('FADROMA_DOCKER', ()=>DEFAULT_ENGINE_SOCKET) /** Tag of the docker image for the build container. */ - buildImage: OCI.OCIImage + buildImage: OCI.Image /** Docker image to use for dockerized builds. */ buildImageTag: string = this.config.getString('FADROMA_BUILD_IMAGE', ()=>'ghcr.io/hackbg/fadroma:master') @@ -377,14 +377,14 @@ export class ContainerizedLocalRustCompiler extends LocalRustCompiler { super(options as Partial) // Set up Docker API handle if (options?.engineSocket) { - this.engine = new OCI.OCIConnection({ url: options.engineSocket }) + this.engine = new OCI.Connection({ url: options.engineSocket }) } else if (options?.engine) { this.engine = options.engine } else { - this.engine = new OCI.OCIConnection() + this.engine = new OCI.Connection() } - if ((options?.buildImageTag as unknown) instanceof OCI.OCIImage) { - this.buildImage = options?.buildImageTag as unknown as OCI.OCIImage + if ((options?.buildImageTag as unknown) instanceof OCI.Image) { + this.buildImage = options?.buildImageTag as unknown as OCI.Image } else if (options?.buildImageTag) { this.buildImage = this.engine.image(options.buildImageTag) } else { diff --git a/devnet/devnet-base.test.ts b/devnet/devnet-base.test.ts index b454a44d056..27b0377f85a 100644 --- a/devnet/devnet-base.test.ts +++ b/devnet/devnet-base.test.ts @@ -2,7 +2,7 @@ import { packageRoot } from './package' import type * as Devnets from './devnet' import Container from './devnet-base' import { Chain, Token } from '@fadroma/agent' -import { OCIContainer, OCIImage } from '@fadroma/oci' +import * as OCI from '@fadroma/oci' import { ok, equal, deepEqual, throws, rejects } from 'node:assert' import { getuid, getgid } from 'node:process' import { resolve } from 'node:path' @@ -38,7 +38,7 @@ export async function testDevnetPlatform < ok(devnet.gasToken) ok(devnet.gasToken instanceof Token.Fungible) ok(typeof devnet.gasToken.denom === 'string') - ok((await devnet.container.image) instanceof OCIImage) + ok((await devnet.container.image) instanceof OCI.Image) const spawnEnv = Impl.containerEnvironment(devnet) deepEqual(spawnEnv.DAEMON, daemon) @@ -62,7 +62,7 @@ export async function testDevnetPlatform < equal(await devnet.created, devnet) equal(devnet.url.toString(), `http://${devnet.nodeHost}:${devnet.nodePort}/`) - ok(devnet.container instanceof OCIContainer) + ok(devnet.container instanceof OCI.Container) equal(devnet.container.name, devnet.chainId) equal(await devnet.started, devnet) diff --git a/devnet/devnet-base.ts b/devnet/devnet-base.ts index 9baebd5f3ce..520ad3553a9 100644 --- a/devnet/devnet-base.ts +++ b/devnet/devnet-base.ts @@ -1,6 +1,6 @@ import portManager, { waitPort } from '@hackbg/port' import { Path, SyncFS, FileFormat } from '@hackbg/file' -import { OCIConnection, OCIImage, OCIContainer } from '@fadroma/oci' +import * as OCI from '@fadroma/oci' import { Core, Program, Chain } from '@fadroma/agent' const { assign, bold, colors, randomBase16, randomColor, } = Core import type { Address, CodeId, Uint128 } from '@fadroma/agent' @@ -27,7 +27,7 @@ export default abstract class DevnetContainer extends Chain.Backend { /** Version of devnet platform. */ platformVersion: string /** Container instance of devnet. */ - container: OCIContainer = new OCIContainer() + container: OCI.Container = new OCI.Container() /** The protocol of the API URL without the trailing colon. */ nodeProtocol: string = 'http' /** The hostname of the API URL. */ diff --git a/devnet/devnet-impl.test.ts b/devnet/devnet-impl.test.ts index 2613000cb9b..3cc5c2033ed 100644 --- a/devnet/devnet-impl.test.ts +++ b/devnet/devnet-impl.test.ts @@ -1,6 +1,6 @@ import { ok, equal, throws } from 'node:assert' -import { OCIConnection, OCIImage, OCIContainer, Mock } from '@fadroma/oci' import { Core } from '@fadroma/agent' +import * as OCI from '@fadroma/oci' import * as Impl from './devnet-impl' const { Console } = Core @@ -66,10 +66,10 @@ export default async () => { platformName: undefined, platformVersion: undefined, genesisAccounts: undefined, - container: Object.assign(new OCIContainer({ + container: Object.assign(new OCI.Container({ id: 'mock-create', - image: new OCIImage({ - engine: OCIConnection.mock(), + image: new OCI.Image({ + engine: OCI.Connection.mock(), name: 'mock' }), }), { @@ -96,10 +96,10 @@ export default async () => { initScript: undefined, stateDir: undefined, stateFile: { save (_) {} }, - container: Object.defineProperties(new OCIContainer({ + container: Object.defineProperties(new OCI.Container({ id: 'mock-start', - image: new OCIImage({ - engine: OCIConnection.mock(), + image: new OCI.Image({ + engine: OCI.Connection.mock(), name: 'mock' }), }), { @@ -131,10 +131,10 @@ export default async () => { await Impl.pauseDevnetContainer({ log: new Console('pauseDevnetContainer'), running: undefined, - container: new OCIContainer({ + container: new OCI.Container({ id: 'mock-pause', - image: Object.assign(new OCIImage({ - engine: OCIConnection.mock(), + image: Object.assign(new OCI.Image({ + engine: OCI.Connection.mock(), name: 'mock' })), }), @@ -144,10 +144,10 @@ export default async () => { log: new Console('deleteDevnetContainer'), stateDir: undefined, paused: undefined, - container: Object.defineProperties(new OCIContainer({ + container: Object.defineProperties(new OCI.Container({ id: 'mock-delete', - image: new OCIImage({ - engine: OCIConnection.mock(), + image: new OCI.Image({ + engine: OCI.Connection.mock(), name: 'mock' }), }), { diff --git a/devnet/devnet-impl.ts b/devnet/devnet-impl.ts index f5f23318304..3b1eec0ce4c 100644 --- a/devnet/devnet-impl.ts +++ b/devnet/devnet-impl.ts @@ -7,7 +7,7 @@ import { onExit } from 'gracy' import portManager from '@hackbg/port' import { Path, SyncFS, FileFormat, XDG } from '@hackbg/file' import { Core, Chain } from '@fadroma/agent' -import { OCIImage, OCIConnection } from '@fadroma/oci' +import * as OCI from '@fadroma/oci' import type { default as DevnetContainer } from './devnet-base' import type { APIMode } from './devnet-base' const { bold } = Core @@ -26,11 +26,11 @@ export function initPort (devnet: $D<'nodePortMode'|'nodePort'>) { export function initContainer (devnet: $D<'log'|'container'>) { devnet.container.log.label = devnet.log.label if (!devnet.container.image) { - devnet.container.image = new OCIImage() + devnet.container.image = new OCI.Image() } devnet.container.image.log.label = devnet.log.label if (!devnet.container.image.engine) { - devnet.container.image.engine = new OCIConnection() + devnet.container.image.engine = new OCI.Connection() } return devnet } diff --git a/devnet/devnet-okp4.ts b/devnet/devnet-okp4.ts index 6023d903225..e09e94d9962 100644 --- a/devnet/devnet-okp4.ts +++ b/devnet/devnet-okp4.ts @@ -4,7 +4,7 @@ import DevnetContainer from './devnet-base' import { connect } from './devnet-impl' import { Core, Token } from '@fadroma/agent' import { OKP4Connection, OKP4MnemonicIdentity } from '@fadroma/cw' -import { OCIContainer, OCIImage } from '@fadroma/oci' +import * as OCI from '@fadroma/oci' import { Path } from '@hackbg/file' const { Error } = Core @@ -55,8 +55,8 @@ export function okp4Version (v: OKP4Version): Partial> { nodePortMode: 'rpc' as APIMode, platform: `okp4_${w}`, waitString: 'indexed block', - container: new OCIContainer({ - image: new OCIImage({ + container: new OCI.Container({ + image: new OCI.Image({ name: `ghcr.io/hackbg/fadroma-devnet-okp4-${v}:master`, dockerfile: new Path(packageRoot, `okp4_${w}.Dockerfile`).absolute }) diff --git a/devnet/devnet-scrt.ts b/devnet/devnet-scrt.ts index 89a9101aa82..d892d9a23c4 100644 --- a/devnet/devnet-scrt.ts +++ b/devnet/devnet-scrt.ts @@ -3,7 +3,7 @@ import type { APIMode } from './devnet-base' import { connect } from './devnet-impl' import DevnetContainer from './devnet-base' import { Token } from '@fadroma/agent' -import { OCIContainer, OCIImage } from '@fadroma/oci' +import * as OCI from '@fadroma/oci' import { ScrtConnection, ScrtMnemonicIdentity } from '@fadroma/scrt' import { Core } from '@fadroma/agent' import { Path } from '@hackbg/file' @@ -101,8 +101,8 @@ function scrtVersion (v: ScrtVersion): Partial> { waitString, nodeBinary: 'secretd', platform: `scrt_${w}`, - container: new OCIContainer({ - image: new OCIImage({ + container: new OCI.Container({ + image: new OCI.Image({ name: `ghcr.io/hackbg/fadroma-devnet-scrt-${v}:master`, dockerfile: new Path(packageRoot, `scrt_${w}.Dockerfile`).absolute }) diff --git a/devnet/devnet.ts b/devnet/devnet.ts index d7179e794cd..d28f479c71e 100644 --- a/devnet/devnet.ts +++ b/devnet/devnet.ts @@ -5,7 +5,7 @@ import { Path, FileFormat, SyncFS, XDG } from '@hackbg/file' import type { CodeId, ChainId, Address, Uint128 } from '@fadroma/agent' import { Core, Program } from '@fadroma/agent' import CLI from '@hackbg/cmds' -import { OCIConnection, OCIContainer, OCIImage } from '@fadroma/oci' +import * as OCI from '@fadroma/oci' import { packageName, packageVersion } from './package' import ScrtContainer from './devnet-scrt' import OKP4Container from './devnet-okp4' @@ -64,7 +64,7 @@ export default class DevnetCLI extends CLI { info: 'list existing devnets', args: '' }, async () => { - const engine = new OCIConnection() + const engine = new OCI.Connection() const devnetsDir = new SyncFS.Directory( XDG({ expanded: true, subdir: 'fadroma' }).data.home, 'devnets' @@ -337,7 +337,7 @@ export default class DevnetCLI extends CLI { info: 'delete broken devnets', args: '' }, async () => { - const engine = new OCIConnection() + const engine = new OCI.Connection() const dataDir = XDG({ expanded: true, subdir: 'fadroma' }).data.home const devnetsDir = new SyncFS.Directory(dataDir, 'devnets') const devnets = devnetsDir.list() diff --git a/oci/oci-impl.ts b/oci/oci-impl.ts index 2db981900c0..e049bc1d0d4 100644 --- a/oci/oci-impl.ts +++ b/oci/oci-impl.ts @@ -1,5 +1,5 @@ import Docker from 'dockerode' -import type { OCIContainer } from './oci' +import { Container as OCIContainer } from './oci' import { OCIConsole as Console, OCIError, bold } from './oci-base' export function toDockerodeOptions ({ @@ -40,7 +40,7 @@ export function toDockerodeOptions ({ exposed.forEach(containerPort=>config.ExposedPorts[containerPort] = {}) - Object.entries(mapped).forEach(([containerPort, hostPort])=> + Object.entries(mapped).forEach(([containerPort, hostPort]: [string, string])=> config.HostConfig.PortBindings[containerPort] = [{ HostPort: hostPort }]) Object.entries(readonly).forEach(([hostPath, containerPath])=> diff --git a/oci/oci.test.ts b/oci/oci.test.ts index 0363e9726f6..fb368c3f0b2 100644 --- a/oci/oci.test.ts +++ b/oci/oci.test.ts @@ -1,5 +1,5 @@ import { Suite } from '@hackbg/ensuite' -import { OCIConnection, OCIImage, OCIContainer, defaultSocketPath } from './oci' +import * as OCI from './oci' import { Core } from '@fadroma/agent' import * as assert from 'node:assert' import { resolve, dirname } from 'node:path' @@ -10,9 +10,9 @@ export default new Suite([ ]) export async function testContainerEngine () { - const engine = new OCIConnection() + const engine = new OCI.Connection() const image = engine.image('hello-world') - assert.ok(image instanceof OCIImage) + assert.ok(image instanceof OCI.Image) assert.equal(image.engine, engine) console.log('Pull or build...') await image.pullOrBuild() @@ -24,7 +24,7 @@ export async function testContainerEngine () { console.log('Build...') await image.build() const container = image.container(`test-hello-${Core.randomBase16()}`) - assert.ok(container instanceof OCIContainer) + assert.ok(container instanceof OCI.Container) assert.equal(container.image, image) assert.equal(await container.exists(), false) console.log('Create container...') diff --git a/oci/oci.ts b/oci/oci.ts index 35297907bad..a16db2f575f 100644 --- a/oci/oci.ts +++ b/oci/oci.ts @@ -17,7 +17,7 @@ export const defaultSocketPath = process.env.DOCKER_HOST || '/var/run/docker.soc export const console = new Console('@fadroma/oci') -export class OCIConnection extends Chain.Connection { +class OCIConnection extends Chain.Connection { static mock (callback?: Function) { return new this({ api: Mock.mockDockerode(callback) }) } @@ -114,7 +114,7 @@ export class OCIConnection extends Chain.Connection { } } -export class OCIImage extends Deploy.ContractTemplate { +class OCIImage extends Deploy.ContractTemplate { constructor (properties: Partial = {}) { super(properties) @@ -284,7 +284,7 @@ export class OCIImage extends Deploy.ContractTemplate { } /** Interface to a Docker container. */ -export class OCIContainer extends Deploy.ContractInstance { +class OCIContainer extends Deploy.ContractInstance { constructor (properties: Partial = {}) { super(properties) @@ -555,3 +555,9 @@ export class LineTransformStream extends Transform { callback(null, output) } } + +export { + OCIConnection as Connection, + OCIImage as Image, + OCIContainer as Container, +} diff --git a/toolbox b/toolbox index 7e06baba950..f3c5a976d55 160000 --- a/toolbox +++ b/toolbox @@ -1 +1 @@ -Subproject commit 7e06baba95062136b32cce3d7dcf6e8492c09cd3 +Subproject commit f3c5a976d55a92d4aba4989f3d404cc692009e51