mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-23 03:16:09 +08:00
Merge pull request #400 from crazy-max/docker-context-inspect
docker: contextInspect func
This commit is contained in:
commit
d7a84a5d46
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {describe, expect, test} from '@jest/globals';
|
||||
import {describe, expect, it, test} from '@jest/globals';
|
||||
|
||||
import {Docker} from '../../src/docker/docker';
|
||||
|
||||
@ -54,3 +54,14 @@ maybe('pull', () => {
|
||||
}
|
||||
}, 600000);
|
||||
});
|
||||
|
||||
maybe('contextInspect', () => {
|
||||
it('inspect default context', async () => {
|
||||
const contextInfo = await Docker.contextInspect();
|
||||
expect(contextInfo).toBeDefined();
|
||||
console.log('contextInfo', contextInfo);
|
||||
expect(contextInfo?.Name).toBeDefined();
|
||||
expect(contextInfo?.Endpoints).toBeDefined();
|
||||
expect(Object.keys(contextInfo?.Endpoints).length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
@ -118,6 +118,19 @@ describe('context', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('contextInspect', () => {
|
||||
it('call docker context inspect', async () => {
|
||||
const execSpy = jest.spyOn(Exec, 'getExecOutput');
|
||||
await Docker.contextInspect('foo').catch(() => {
|
||||
// noop
|
||||
});
|
||||
expect(execSpy).toHaveBeenCalledWith(`docker`, ['context', 'inspect', '--format=json', 'foo'], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('printVersion', () => {
|
||||
it('call docker version', async () => {
|
||||
const execSpy = jest.spyOn(Exec, 'exec');
|
||||
|
@ -25,7 +25,7 @@ import {Cache} from '../cache';
|
||||
import {Exec} from '../exec';
|
||||
import {Util} from '../util';
|
||||
|
||||
import {ConfigFile} from '../types/docker/docker';
|
||||
import {ConfigFile, ContextInfo} from '../types/docker/docker';
|
||||
|
||||
export class Docker {
|
||||
static get configDir(): string {
|
||||
@ -69,6 +69,22 @@ export class Docker {
|
||||
});
|
||||
}
|
||||
|
||||
public static async contextInspect(name?: string): Promise<ContextInfo> {
|
||||
const args = ['context', 'inspect', '--format=json'];
|
||||
if (name) {
|
||||
args.push(name);
|
||||
}
|
||||
return await Exec.getExecOutput(`docker`, args, {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
}).then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr.trim());
|
||||
}
|
||||
return (<Array<ContextInfo>>JSON.parse(res.stdout.trim()))[0];
|
||||
});
|
||||
}
|
||||
|
||||
public static async printVersion(): Promise<void> {
|
||||
await Exec.exec('docker', ['version']);
|
||||
}
|
||||
|
@ -64,3 +64,33 @@ export interface AuthConfig {
|
||||
identitytoken?: string;
|
||||
registrytoken?: string;
|
||||
}
|
||||
|
||||
export interface ContextInfo {
|
||||
Name: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
Metadata: any;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
Endpoints: Record<string, EndpointInfo>;
|
||||
TLSMaterial: Record<string, Array<string>>;
|
||||
Storage: StorageInfo;
|
||||
}
|
||||
|
||||
export interface EndpointInfo {
|
||||
Host?: string;
|
||||
SkipVerify: boolean;
|
||||
TLSData?: TLSData;
|
||||
}
|
||||
|
||||
export interface TLSData {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
CA: any;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
Key: any;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
Cert: any;
|
||||
}
|
||||
|
||||
export interface StorageInfo {
|
||||
MetadataPath: string;
|
||||
TLSPath: string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user