From 5b4c1ac02500a255d812ca282b49bf6b2bb28816 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Fri, 5 Jul 2024 16:10:21 +0200 Subject: [PATCH 1/2] buildx: extra test to ensure legit path is not trimmed for localstate Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/buildx/buildx.test.ts | 13 ++++++++++--- .../default/default/dfsz8r57a98zf789pmlyzqp3n | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 __tests__/fixtures/buildx-refs/default/default/dfsz8r57a98zf789pmlyzqp3n diff --git a/__tests__/buildx/buildx.test.ts b/__tests__/buildx/buildx.test.ts index d62e1a1..e11f62d 100644 --- a/__tests__/buildx/buildx.test.ts +++ b/__tests__/buildx/buildx.test.ts @@ -288,6 +288,13 @@ describe('localState', () => { DockerfilePath: '' } as LocalState, ], + [ + 'default/default/dfsz8r57a98zf789pmlyzqp3n', + { + LocalPath: 'https://github.com/docker/actions-toolkit.git#:__tests__/fixtures', + DockerfilePath: 'hello.Dockerfile' + } as LocalState, + ], [ 'default/default/w38vcd5fo5cfvfyig77qjec0v', { @@ -306,14 +313,14 @@ describe('refs', () => { const refs = Buildx.refs({ dir: path.join(fixturesDir, 'buildx-refs') }); - expect(Object.keys(refs).length).toEqual(16); + expect(Object.keys(refs).length).toEqual(17); }); it('returns default builder refs', async () => { const refs = Buildx.refs({ dir: path.join(fixturesDir, 'buildx-refs'), builderName: 'default' }); - expect(Object.keys(refs).length).toEqual(13); + expect(Object.keys(refs).length).toEqual(14); }); it('returns foo builder refs', async () => { const refs = Buildx.refs({ @@ -332,6 +339,6 @@ describe('refs', () => { builderName: 'default', since: new Date('2024-01-10T00:00:00Z') }); - expect(Object.keys(refs).length).toEqual(10); + expect(Object.keys(refs).length).toEqual(11); }); }); diff --git a/__tests__/fixtures/buildx-refs/default/default/dfsz8r57a98zf789pmlyzqp3n b/__tests__/fixtures/buildx-refs/default/default/dfsz8r57a98zf789pmlyzqp3n new file mode 100644 index 0000000..1870ff0 --- /dev/null +++ b/__tests__/fixtures/buildx-refs/default/default/dfsz8r57a98zf789pmlyzqp3n @@ -0,0 +1 @@ +{"LocalPath":"https://github.com/docker/actions-toolkit.git#:__tests__/fixtures","DockerfilePath":"hello.Dockerfile"} From 3bd6acf499b57c75af3b2f18a6465d4669c76123 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Fri, 5 Jul 2024 16:18:20 +0200 Subject: [PATCH 2/2] buildx: make refs dir optional in localState func Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/buildx/buildx.test.ts | 2 +- src/buildx/buildx.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/buildx/buildx.test.ts b/__tests__/buildx/buildx.test.ts index e11f62d..a876780 100644 --- a/__tests__/buildx/buildx.test.ts +++ b/__tests__/buildx/buildx.test.ts @@ -303,7 +303,7 @@ describe('localState', () => { } as LocalState, ] ])('given %p', async (ref: string, expected: LocalState) => { - const localState = Buildx.localState(path.join(fixturesDir, 'buildx-refs'), ref); + const localState = Buildx.localState(ref, path.join(fixturesDir, 'buildx-refs')); expect(localState).toEqual(expected); }); }); diff --git a/src/buildx/buildx.ts b/src/buildx/buildx.ts index 728d9dd..97eb4f8 100644 --- a/src/buildx/buildx.ts +++ b/src/buildx/buildx.ts @@ -177,12 +177,12 @@ export class Buildx { return driverOpts; } - public static localState(dir: string, ref: string): LocalState { + public static localState(ref: string, dir?: string): LocalState { const [builderName, nodeName, id] = ref.split('/'); if (!builderName || !nodeName || !id) { throw new Error(`Invalid build reference: ${ref}`); } - const lsPath = path.join(dir, builderName, nodeName, id); + const lsPath = path.join(dir || Buildx.refsDir, builderName, nodeName, id); if (!fs.existsSync(lsPath)) { throw new Error(`Local state not found in ${lsPath}`); }