Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
56 changes: 56 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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 @@ -146,6 +147,8 @@ describe('getArgs', () => {
[
'buildx',
'build',
'--label', 'org.opencontainers.image.source=https://github.com/docker/build-push-action.git',
'--label', 'dockerfile-path=./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',
Expand All @@ -154,6 +157,59 @@ describe('getArgs', () => {
'--push',
'https://github.com/docker/build-push-action.git#heads/master'
]
],
[
'0.4.2',
new Map<string, string>([
['context', '.'],
['labels', 'org.opencontainers.image.source=UserProvidedSourceLabel'],
['outputs', 'type=image,dest=./release-out']
]),
[
'buildx',
'build',
'--label', 'org.opencontainers.image.source=UserProvidedSourceLabel',
'--label', 'dockerfile-path=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']
]),
[
'buildx',
'build',
'--label', 'org.opencontainers.image.source=https://github.com/docker/build-push-action.git',
'--label', 'dockerfile-path=Dockerfile',
'--output', 'type=registry,dest=./release-out',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--file', 'Dockerfile',
'.'
]
],
[
'0.4.2',
new Map<string, string>([
['context', '.'],
['labels', 'org.opencontainers.image.source=UserProvidedSourceLabel'],
['load', 'true']
]),
[
'buildx',
'build',
'--label', 'org.opencontainers.image.source=UserProvidedSourceLabel',
'--label', 'dockerfile-path=Dockerfile',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--file', 'Dockerfile',
'--load',
'.'
]
]
])(
'given %p with %p as inputs, returns %p',
Expand Down
16 changes: 15 additions & 1 deletion dist/index.js

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

21 changes: 20 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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 @@ -75,6 +75,25 @@ export async function getInputs(defaultContext: string): Promise<Inputs> {
githubToken: core.getInput('github-token'),
ssh: await getInputList('ssh')
};

if (
userInputs.load == true ||
userInputs.push == true ||
userInputs.outputs.find(val => val.indexOf('type=image') > -1 || val.indexOf('type=registry') > -1)
) {
//Add repo as source-label if not already supplied by user
const sourceLabelKey = 'org.opencontainers.image.source';
if (userInputs.labels.find(val => val.startsWith(sourceLabelKey) == true) == null) {
const githubOwnerRepoUrl = defaultContext.split('#')[0];
userInputs.labels.push(`${sourceLabelKey}=${githubOwnerRepoUrl}`);
}

//Add dockerfile path as label
let dockerfilePath = userInputs.file;
userInputs.labels.push(`dockerfile-path=${dockerfilePath}`);
}

return userInputs;
}

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