Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
59 changes: 57 additions & 2 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
const tmpDir = path.join('/tmp/.docker-build-push-jest').split(path.sep).join(path.posix.sep);
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
2;
}
return tmpDir;
});
Expand Down Expand Up @@ -280,23 +281,77 @@ bbbb
ccc"`],
['file', './test/Dockerfile'],
['builder', 'builder-git-context-2'],
['push', 'true']
['push', 'true'],
['trace-data', 'true']
]),
[
'buildx',
'build',
'--label', 'dockerfile-path=https://github.com/docker/build-push-action.git#test-jest/./test/Dockerfile',
'--platform', 'linux/amd64,linux/arm64',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=MYSECRET,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=FOO,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=EMPTYLINE,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=EMPTYLINE,src=/tmp/.docker-build-push-jest/.tmpname-
'--file', './test/Dockerfile',
'--builder', 'builder-git-context-2',
'--push',
'https://github.com/docker/build-push-action.git#heads/master'
]
],
[
'0.4.2',
new Map<string, string>([
['context', '.'],
['outputs', 'type=image,dest=./release-out'],
['trace-data', 'true']
]),
[
'buildx',
'build',
'--label', 'dockerfile-path=https://github.com/docker/build-push-action.git#test-jest/Dockerfile',
'--output', 'type=image,dest=./release-out',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--file', 'Dockerfile',
'.'
]
],
[
'0.4.2',
new Map<string, string>([
['context', '.'],
['outputs', 'type=registry,dest=./release-out'],
['trace-data', 'true']
]),
[
'buildx',
'build',
'--label', 'dockerfile-path=https://github.com/docker/build-push-action.git#test-jest/Dockerfile',
'--output', 'type=registry,dest=./release-out',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--file', 'Dockerfile',
'.'
]
],
[
'0.4.2',
new Map<string, string>([
['context', '.'],
['load', 'true'],
['trace-data', 'true']
]),
[
'buildx',
'build',
'--label', 'dockerfile-path=https://github.com/docker/build-push-action.git#test-jest/Dockerfile',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--file', 'Dockerfile',
'--load',
'.'
]
]
,
[
'0.4.2',
new Map<string, string>([
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ inputs:
ssh:
description: "List of SSH agent socket or keys to expose to the build"
required: false

trace-data:
description: "Flag to indicate whether link to dockerfile is added to image labels or not"
default: 'false'
required: false
outputs:
digest:
description: 'Image content-addressable identifier also called a digest'
Expand Down
22 changes: 20 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 24 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function tmpNameSync(options?: tmp.TmpNameOptions): string {
}

export async function getInputs(defaultContext: string): Promise<Inputs> {
return {
let userInputs = {
context: core.getInput('context') || defaultContext,
file: core.getInput('file') || 'Dockerfile',
buildArgs: await getInputList('build-args', true),
Expand All @@ -74,8 +74,30 @@ export async function getInputs(defaultContext: string): Promise<Inputs> {
cacheTo: await getInputList('cache-to', true),
secrets: await getInputList('secrets', true),
githubToken: core.getInput('github-token'),
ssh: await getInputList('ssh')
ssh: await getInputList('ssh'),
traceData: core.getInput('trace-data') || 'false'
};

if (
userInputs.traceData == 'true' && //if user explictly asks to add traceData
(userInputs.load == true ||
userInputs.push == true ||
userInputs.outputs.find(val => val.indexOf('type=image') > -1 || val.indexOf('type=registry') > -1))
) {
//Add link to dockerfile as label
let dockerfilePath = userInputs.file;
let stringToReplace = '';
if (defaultContext.indexOf('#heads')) {
stringToReplace = '.git#heads';
} else if (defaultContext.indexOf('#tags')) {
stringToReplace = '.git#tags';
}

let repoPath = defaultContext.replace(stringToReplace, '/blob');
userInputs.labels.push(`dockerfile-path=${repoPath}/${dockerfilePath}`);
}

return userInputs;
}

export async function getArgs(inputs: Inputs, defaultContext: string, buildxVersion: string): Promise<Array<string>> {
Expand Down