Merge pull request #42 from crazy-max/buildkit-fix-version
Some checks failed
publish / publish (push) Has been cancelled
Some checks failed
publish / publish (push) Has been cancelled
buildkit: use node info to retrieve version
This commit is contained in:
@@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {beforeEach, describe, expect, it, jest, test} from '@jest/globals';
|
import {beforeEach, describe, expect, it, jest, test} from '@jest/globals';
|
||||||
import * as semver from 'semver';
|
|
||||||
|
|
||||||
import {BuildKit} from '../../src/buildkit/buildkit';
|
import {BuildKit} from '../../src/buildkit/buildkit';
|
||||||
import {Builder} from '../../src/buildx/builder';
|
import {Builder} from '../../src/buildx/builder';
|
||||||
@@ -48,11 +47,15 @@ jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<Bu
|
|||||||
|
|
||||||
describe('getVersion', () => {
|
describe('getVersion', () => {
|
||||||
it('valid', async () => {
|
it('valid', async () => {
|
||||||
|
const builder = new Builder({
|
||||||
|
context: new Context()
|
||||||
|
});
|
||||||
|
const builderInfo = await builder.inspect('builder2');
|
||||||
const buildkit = new BuildKit({
|
const buildkit = new BuildKit({
|
||||||
context: new Context()
|
context: new Context()
|
||||||
});
|
});
|
||||||
const version = await buildkit.getVersion('builder2');
|
const version = await buildkit.getVersion(builderInfo.nodes[0]);
|
||||||
expect(semver.valid(version)).not.toBeNull();
|
expect(version).toBe('v0.11.0');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import {Buildx} from '../buildx/buildx';
|
|||||||
import {Builder} from '../buildx/builder';
|
import {Builder} from '../buildx/builder';
|
||||||
import {Config} from './config';
|
import {Config} from './config';
|
||||||
|
|
||||||
import {BuilderInfo} from '../types/builder';
|
import {BuilderInfo, NodeInfo} from '../types/builder';
|
||||||
|
|
||||||
export interface BuildKitOpts {
|
export interface BuildKitOpts {
|
||||||
context: Context;
|
context: Context;
|
||||||
@@ -46,14 +46,7 @@ export class BuildKit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getVersion(builderName: string): Promise<string | undefined> {
|
public async getVersion(node: NodeInfo): Promise<string | undefined> {
|
||||||
const builderInfo = await this.getBuilderInfo(builderName);
|
|
||||||
if (builderInfo.nodes.length == 0) {
|
|
||||||
// a builder always have on node, should not happen.
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
// TODO: get version for all nodes
|
|
||||||
const node = builderInfo.nodes[0];
|
|
||||||
if (!node.buildkitVersion && node.name) {
|
if (!node.buildkitVersion && node.name) {
|
||||||
try {
|
try {
|
||||||
return await this.getVersionWithinImage(node.name);
|
return await this.getVersionWithinImage(node.name);
|
||||||
@@ -92,8 +85,13 @@ export class BuildKit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async versionSatisfies(builderName: string, range: string): Promise<boolean> {
|
public async versionSatisfies(builderName: string, range: string, builderInfo?: BuilderInfo): Promise<boolean> {
|
||||||
const builderInfo = await this.getBuilderInfo(builderName);
|
if (!builderInfo) {
|
||||||
|
builderInfo = await new Builder({
|
||||||
|
context: this.context,
|
||||||
|
buildx: this.buildx
|
||||||
|
}).inspect(builderName);
|
||||||
|
}
|
||||||
for (const node of builderInfo.nodes) {
|
for (const node of builderInfo.nodes) {
|
||||||
let bkversion = node.buildkitVersion;
|
let bkversion = node.buildkitVersion;
|
||||||
if (!bkversion) {
|
if (!bkversion) {
|
||||||
@@ -113,12 +111,4 @@ export class BuildKit {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getBuilderInfo(name: string): Promise<BuilderInfo> {
|
|
||||||
const builder = new Builder({
|
|
||||||
context: this.context,
|
|
||||||
buildx: this.buildx
|
|
||||||
});
|
|
||||||
return builder.inspect(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user