Skip to content

Commit

Permalink
feat(studio): expose execDocker method
Browse files Browse the repository at this point in the history
  • Loading branch information
themightychris committed Dec 8, 2024
1 parent cf20bdb commit 4436b5e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
35 changes: 31 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ declare module 'git-client' {
}
}

declare module '@iarna/toml' {
export function parse(content: string): any;
}

declare module 'hologit' {
import { Git as GitClient } from 'git-client';
import { Docker } from 'dockerode';

export interface GitOptions {
gitDir: string;
Expand Down Expand Up @@ -65,6 +68,30 @@ declare module 'hologit' {
cacheTo?: string | null;
}

export interface DockerExecOptions {
$relayStderr?: boolean;
$relayStdout?: boolean;
}

export interface StudioContainer {
id?: string;
type?: 'studio';
env?: { [key: string]: string };
defaultUser?: string;
}

export interface HoloSpec {
holospec: {
lens: {
input: string;
container?: string;
package?: string;
command?: string;
[key: string]: any;
};
};
}

export class Git {
static get(): Promise<typeof GitClient>;
constructor(options: GitOptions);
Expand Down Expand Up @@ -297,13 +324,13 @@ declare module 'hologit' {
export class Studio {
static cleanup(): Promise<void>;
static getHab(): Promise<any>;
static getDocker(): Promise<Docker>;
static isEnvironmentStudio(): Promise<boolean>;
static get(gitDir: string): Promise<Studio>;
static execDocker(args: string[], options?: DockerExecOptions): Promise<string>;

constructor(options: { gitDir: string; container: any });
constructor(options: { gitDir: string; container: StudioContainer });

container: any;
container: StudioContainer;
gitDir: string;

isLocal(): boolean;
Expand Down
15 changes: 12 additions & 3 deletions lib/Studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ let hab;
* @param {Object} options - Options for child_process.spawn.
* @returns {Promise<string>} - Resolves with stdout data.
*/
function execDocker(args, options = { $relayStderr: false, $relayStdout: false }) {
function execDocker(args, options = { }) {
logger.debug(`docker ${args.join(' ')}`);

return new Promise((resolve, reject) => {
const dockerProcess = spawn('docker', args, { stdio: 'pipe', ...options });

if (options.$relayStderr !== false) {
if (options.$relayStderr) {
dockerProcess.stderr.pipe(process.stderr);
}

if (options.$relayStdout !== false) {
if (options.$relayStdout) {
dockerProcess.stdout.pipe(process.stdout);
}

Expand Down Expand Up @@ -92,6 +92,15 @@ class Studio {
return Boolean(process.env.STUDIO_TYPE);
}

/**
* Execute a Docker CLI command.
* @param {Array<string>} args - The arguments to pass to the docker command.
* @param {Object} options - Options for child_process.spawn.
* @returns {Promise<string>} - Resolves with stdout data.
*/
static execDocker(args, options = {}) {
return execDocker(args, options);
}

static async get (gitDir) {
const cachedStudio = studioCache.get(gitDir);
Expand Down

0 comments on commit 4436b5e

Please sign in to comment.