Skip to content
This repository was archived by the owner on Mar 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/private/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export class Docker {
await this.execute(buildCommand, {
cwd: options.directory,
quiet: options.quiet,
env: {
BUILDX_NO_DEFAULT_ATTESTATIONS: '1', // Docker Build adds provenance attestations by default that confuse cdk-assets
},
});
}

Expand Down
39 changes: 39 additions & 0 deletions test/private/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,26 @@ type ShellExecuteMock = jest.SpyInstance<
Parameters<Docker['execute']>
>;

let docker: Docker;

const makeShellExecuteMock = (fn: (params: string[]) => void): ShellExecuteMock =>
jest
.spyOn<{ execute: Docker['execute'] }, 'execute'>(Docker.prototype as any, 'execute')
.mockImplementation(
async (params: string[], _options?: Omit<ShellOptions, 'shellEventPublisher'>) => fn(params)
);

afterEach(() => {
jest.restoreAllMocks();
});

beforeEach(() => {
docker = new Docker(() => {}, 'ignore');
});

describe('Docker', () => {
describe('exists', () => {
<<<<<<< HEAD
let docker: Docker;

const makeShellExecuteMock = (fn: (params: string[]) => void): ShellExecuteMock =>
Expand Down Expand Up @@ -92,4 +110,25 @@ describe('Docker', () => {
expect(imageExists).toBe(false);
});
});

describe('build', () => {
test('includes BUILDX_NO_DEFAULT_ATTESTATIONS env variable in commands', async () => {
const spy = makeShellExecuteMock(() => undefined);

await docker.build({
directory: 'foo',
tag: 'bar',
});

// Verify the options passed to build
expect(spy).toHaveBeenCalledWith(
expect.any(Array),
expect.objectContaining({
env: expect.objectContaining({
BUILDX_NO_DEFAULT_ATTESTATIONS: '1',
}),
})
);
});
});
});
Loading