From 720cd8569f453f3729f95116aeffbd76673e7626 Mon Sep 17 00:00:00 2001 From: Jyotsna Singh Date: Tue, 3 Nov 2020 17:50:03 +0530 Subject: [PATCH 1/9] Added dockerfile path to image label Signed-off-by: Jyotsna Singh --- dist/index.js | 4 ++++ src/main.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/dist/index.js b/dist/index.js index 4b161e406..1d32713ae 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2373,6 +2373,7 @@ const context = __importStar(__webpack_require__(842)); const exec = __importStar(__webpack_require__(757)); const stateHelper = __importStar(__webpack_require__(647)); const core = __importStar(__webpack_require__(186)); +const github = __importStar(__webpack_require__(438)); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -2387,6 +2388,9 @@ function run() { core.info(`📣 Buildx version: ${buildxVersion}`); const defContext = context.defaultContext(); let inputs = yield context.getInputs(defContext); + //Add dockerfile path to label + let dockerfilePath = core.getInput('file') || 'Dockerfile'; + inputs.labels.push(`org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/${dockerfilePath}`); core.info(`🏃 Starting build...`); const args = yield context.getArgs(inputs, defContext, buildxVersion); yield exec.exec('docker', args).then(res => { diff --git a/src/main.ts b/src/main.ts index 4a0fae7e9..91836549f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,6 +5,7 @@ import * as context from './context'; import * as exec from './exec'; import * as stateHelper from './state-helper'; import * as core from '@actions/core'; +import * as github from '@actions/github'; async function run(): Promise { try { @@ -23,6 +24,12 @@ async function run(): Promise { const defContext = context.defaultContext(); let inputs: context.Inputs = await context.getInputs(defContext); + //Add dockerfile path to label + let dockerfilePath = core.getInput('file') || 'Dockerfile'; + inputs.labels.push( + `org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/${dockerfilePath}` + ); + core.info(`🏃 Starting build...`); const args: string[] = await context.getArgs(inputs, defContext, buildxVersion); await exec.exec('docker', args).then(res => { From ed4d53f122f4cce119d47efb8ac3499719b49b7c Mon Sep 17 00:00:00 2001 From: Jyotsna Date: Wed, 4 Nov 2020 15:49:39 +0530 Subject: [PATCH 2/9] Edited the labels Commit sha: 638eda3fee2d80b61fc1020132d43aaaa590837a, Author: Jyotsna Signed-off-by: Jyotsna --- dist/index.js | 3 ++- src/main.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1d32713ae..3a8ee0197 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2390,7 +2390,8 @@ function run() { let inputs = yield context.getInputs(defContext); //Add dockerfile path to label let dockerfilePath = core.getInput('file') || 'Dockerfile'; - inputs.labels.push(`org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/${dockerfilePath}`); + inputs.labels.push(`org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}`); + inputs.labels.push(`dockerfilePath=${dockerfilePath}`); core.info(`🏃 Starting build...`); const args = yield context.getArgs(inputs, defContext, buildxVersion); yield exec.exec('docker', args).then(res => { diff --git a/src/main.ts b/src/main.ts index 91836549f..b4a2b2e8a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -27,8 +27,9 @@ async function run(): Promise { //Add dockerfile path to label let dockerfilePath = core.getInput('file') || 'Dockerfile'; inputs.labels.push( - `org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/${dockerfilePath}` + `org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}` ); + inputs.labels.push(`dockerfilePath=${dockerfilePath}`); core.info(`🏃 Starting build...`); const args: string[] = await context.getArgs(inputs, defContext, buildxVersion); From be3385a5dd29d918c305292c1870cd33e75ba421 Mon Sep 17 00:00:00 2001 From: Jyotsna Date: Wed, 4 Nov 2020 16:53:29 +0530 Subject: [PATCH 3/9] Edited label key Signed-off-by: Jyotsna --- dist/index.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3a8ee0197..b439e234a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2391,7 +2391,7 @@ function run() { //Add dockerfile path to label let dockerfilePath = core.getInput('file') || 'Dockerfile'; inputs.labels.push(`org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}`); - inputs.labels.push(`dockerfilePath=${dockerfilePath}`); + inputs.labels.push(`dockerfile-path=${dockerfilePath}`); core.info(`🏃 Starting build...`); const args = yield context.getArgs(inputs, defContext, buildxVersion); yield exec.exec('docker', args).then(res => { diff --git a/src/main.ts b/src/main.ts index b4a2b2e8a..063afaa39 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,7 +29,7 @@ async function run(): Promise { inputs.labels.push( `org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}` ); - inputs.labels.push(`dockerfilePath=${dockerfilePath}`); + inputs.labels.push(`dockerfile-path=${dockerfilePath}`); core.info(`🏃 Starting build...`); const args: string[] = await context.getArgs(inputs, defContext, buildxVersion); From f31af72910f7a89622494f5ce21044b4b726513d Mon Sep 17 00:00:00 2001 From: Jyotsna Date: Thu, 5 Nov 2020 12:12:33 +0530 Subject: [PATCH 4/9] Moved changes to context module, added check to prevent overriding user input Signed-off-by: Jyotsna --- src/context.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/context.ts b/src/context.ts index fc7a81d34..e1fad6dde 100644 --- a/src/context.ts +++ b/src/context.ts @@ -54,7 +54,8 @@ export function tmpNameSync(options?: tmp.TmpNameOptions): string { } export async function getInputs(defaultContext: string): Promise { - return { + + let userInputs = { context: core.getInput('context') || defaultContext, file: core.getInput('file') || 'Dockerfile', buildArgs: await getInputList('build-args', true), @@ -75,6 +76,20 @@ export async function getInputs(defaultContext: string): Promise { githubToken: core.getInput('github-token'), ssh: await getInputList('ssh') }; + + //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){ + userInputs.labels.push( + `${sourceLabelKey}=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}` + ); + } + + //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> { From dd55519eee56167f02ae7dae5adb519d26072391 Mon Sep 17 00:00:00 2001 From: Jyotsna Date: Thu, 5 Nov 2020 12:36:20 +0530 Subject: [PATCH 5/9] Removed changes from main module Signed-off-by: Jyotsna --- dist/index.js | 16 ++++++++++------ src/context.ts | 3 +-- src/main.ts | 8 -------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/dist/index.js b/dist/index.js index b439e234a..28bb07beb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2373,7 +2373,6 @@ const context = __importStar(__webpack_require__(842)); const exec = __importStar(__webpack_require__(757)); const stateHelper = __importStar(__webpack_require__(647)); const core = __importStar(__webpack_require__(186)); -const github = __importStar(__webpack_require__(438)); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -2388,10 +2387,6 @@ function run() { core.info(`📣 Buildx version: ${buildxVersion}`); const defContext = context.defaultContext(); let inputs = yield context.getInputs(defContext); - //Add dockerfile path to label - let dockerfilePath = core.getInput('file') || 'Dockerfile'; - inputs.labels.push(`org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}`); - inputs.labels.push(`dockerfile-path=${dockerfilePath}`); core.info(`🏃 Starting build...`); const args = yield context.getArgs(inputs, defContext, buildxVersion); yield exec.exec('docker', args).then(res => { @@ -12069,7 +12064,7 @@ function tmpNameSync(options) { exports.tmpNameSync = tmpNameSync; function getInputs(defaultContext) { return __awaiter(this, void 0, void 0, function* () { - return { + let userInputs = { context: core.getInput('context') || defaultContext, file: core.getInput('file') || 'Dockerfile', buildArgs: yield getInputList('build-args', true), @@ -12090,6 +12085,15 @@ function getInputs(defaultContext) { githubToken: core.getInput('github-token'), ssh: yield getInputList('ssh') }; + //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) { + userInputs.labels.push(`${sourceLabelKey}=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}`); + } + //Add dockerfile path as label + let dockerfilePath = userInputs.file; + userInputs.labels.push(`dockerfile-path=${dockerfilePath}`); + return userInputs; }); } exports.getInputs = getInputs; diff --git a/src/context.ts b/src/context.ts index e1fad6dde..13a771dcd 100644 --- a/src/context.ts +++ b/src/context.ts @@ -54,7 +54,6 @@ export function tmpNameSync(options?: tmp.TmpNameOptions): string { } export async function getInputs(defaultContext: string): Promise { - let userInputs = { context: core.getInput('context') || defaultContext, file: core.getInput('file') || 'Dockerfile', @@ -79,7 +78,7 @@ export async function getInputs(defaultContext: string): Promise { //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){ + if (userInputs.labels.find(val => val.startsWith(sourceLabelKey) == true) == null) { userInputs.labels.push( `${sourceLabelKey}=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}` ); diff --git a/src/main.ts b/src/main.ts index 063afaa39..4a0fae7e9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,6 @@ import * as context from './context'; import * as exec from './exec'; import * as stateHelper from './state-helper'; import * as core from '@actions/core'; -import * as github from '@actions/github'; async function run(): Promise { try { @@ -24,13 +23,6 @@ async function run(): Promise { const defContext = context.defaultContext(); let inputs: context.Inputs = await context.getInputs(defContext); - //Add dockerfile path to label - let dockerfilePath = core.getInput('file') || 'Dockerfile'; - inputs.labels.push( - `org.opencontainers.image.source=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}` - ); - inputs.labels.push(`dockerfile-path=${dockerfilePath}`); - core.info(`🏃 Starting build...`); const args: string[] = await context.getArgs(inputs, defContext, buildxVersion); await exec.exec('docker', args).then(res => { From e2bf0d0cc1b3c850720619d9737512ea7907b862 Mon Sep 17 00:00:00 2001 From: Jyotsna Date: Thu, 5 Nov 2020 13:53:15 +0530 Subject: [PATCH 6/9] Test failures fixed, added 3 new test cases Signed-off-by: Jyotsna --- __tests__/context.test.ts | 56 +++++++++++++++++++++++++++++++++++++++ dist/index.js | 21 +++++++++------ src/context.ts | 25 ++++++++++------- 3 files changed, 84 insertions(+), 18 deletions(-) diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index d38a5700f..f50d6a127 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -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; }); @@ -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', @@ -154,6 +157,59 @@ describe('getArgs', () => { '--push', 'https://github.com/docker/build-push-action.git#heads/master' ] + ], + [ + '0.4.2', + new Map([ + ['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([ + ['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([ + ['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', diff --git a/dist/index.js b/dist/index.js index 28bb07beb..e26627912 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12085,14 +12085,19 @@ function getInputs(defaultContext) { githubToken: core.getInput('github-token'), ssh: yield getInputList('ssh') }; - //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) { - userInputs.labels.push(`${sourceLabelKey}=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}`); - } - //Add dockerfile path as label - let dockerfilePath = userInputs.file; - userInputs.labels.push(`dockerfile-path=${dockerfilePath}`); + 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; }); } diff --git a/src/context.ts b/src/context.ts index 13a771dcd..c6269838d 100644 --- a/src/context.ts +++ b/src/context.ts @@ -76,17 +76,22 @@ export async function getInputs(defaultContext: string): Promise { ssh: await getInputList('ssh') }; - //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) { - userInputs.labels.push( - `${sourceLabelKey}=https://github.com/${github.context.repo.owner}/${github.context.repo.repo}` - ); - } + 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}`); + //Add dockerfile path as label + let dockerfilePath = userInputs.file; + userInputs.labels.push(`dockerfile-path=${dockerfilePath}`); + } return userInputs; } From cf7e6e140f8740b68c2adbf5b1171c647921d457 Mon Sep 17 00:00:00 2001 From: Jyotsna Date: Wed, 11 Nov 2020 20:19:52 +0530 Subject: [PATCH 7/9] Added new trace-Data input. changed label value to link to dockerfile Signed-off-by: Jyotsna --- action.yml | 5 ++++- dist/index.js | 20 ++++++++------------ src/context.ts | 21 ++++++++------------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/action.yml b/action.yml index cf1c5809b..106ae8fe8 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/dist/index.js b/dist/index.js index e26627912..a945c4a8e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12083,20 +12083,16 @@ function getInputs(defaultContext) { cacheTo: yield getInputList('cache-to', true), secrets: yield getInputList('secrets', true), githubToken: core.getInput('github-token'), - ssh: yield getInputList('ssh') + ssh: yield getInputList('ssh'), + traceData: core.getInput('trace-data') || 'false' }; - 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 + 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; - userInputs.labels.push(`dockerfile-path=${dockerfilePath}`); + userInputs.labels.push(`dockerfile-path=${defaultContext}/${dockerfilePath}`); } return userInputs; }); diff --git a/src/context.ts b/src/context.ts index c6269838d..dcf266faf 100644 --- a/src/context.ts +++ b/src/context.ts @@ -73,24 +73,19 @@ export async function getInputs(defaultContext: string): Promise { 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.load == true || - userInputs.push == true || - userInputs.outputs.find(val => val.indexOf('type=image') > -1 || val.indexOf('type=registry') > -1) + 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 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 + //Add link to dockerfile as label let dockerfilePath = userInputs.file; - userInputs.labels.push(`dockerfile-path=${dockerfilePath}`); + userInputs.labels.push(`dockerfile-path=${defaultContext}/${dockerfilePath}`); } return userInputs; From 065688b98f19e6a15ae3120c74591aa51acb50cc Mon Sep 17 00:00:00 2001 From: Jyotsna Date: Wed, 11 Nov 2020 20:35:08 +0530 Subject: [PATCH 8/9] Fixed link to dockerfile Signed-off-by: Jyotsna --- dist/index.js | 3 ++- src/context.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index a945c4a8e..05918831b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12092,7 +12092,8 @@ function getInputs(defaultContext) { userInputs.outputs.find(val => val.indexOf('type=image') > -1 || val.indexOf('type=registry') > -1))) { //Add link to dockerfile as label let dockerfilePath = userInputs.file; - userInputs.labels.push(`dockerfile-path=${defaultContext}/${dockerfilePath}`); + let repoPath = defaultContext.replace('#head', '/blob'); + userInputs.labels.push(`dockerfile-path=${repoPath}/${dockerfilePath}`); } return userInputs; }); diff --git a/src/context.ts b/src/context.ts index dcf266faf..a6adfce8b 100644 --- a/src/context.ts +++ b/src/context.ts @@ -85,7 +85,8 @@ export async function getInputs(defaultContext: string): Promise { ) { //Add link to dockerfile as label let dockerfilePath = userInputs.file; - userInputs.labels.push(`dockerfile-path=${defaultContext}/${dockerfilePath}`); + let repoPath = defaultContext.replace('#head', '/blob'); + userInputs.labels.push(`dockerfile-path=${repoPath}/${dockerfilePath}`); } return userInputs; From c59c0cec43bb5c8fed0f1ecfd6c14b0da21a318c Mon Sep 17 00:00:00 2001 From: Jyotsna Date: Wed, 11 Nov 2020 21:07:49 +0530 Subject: [PATCH 9/9] Fixed link to dockerfile Signed-off-by: Jyotsna --- __tests__/context.test.ts | 47 ++++++++++++++++++++++++++++----------- dist/index.js | 9 +++++++- src/context.ts | 9 +++++++- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index f50d6a127..b27df0878 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -147,8 +147,31 @@ 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', + '--file', './test/Dockerfile', + '--builder', 'builder-git-context-2', + '--push', + 'https://github.com/docker/build-push-action.git#heads/master' + ] + ], + [ + '0.4.2', + new Map([ + ['context', 'https://github.com/docker/build-push-action.git#heads/master'], + ['tag', 'localhost:5000/name/app:latest'], + ['platforms', 'linux/amd64,linux/arm64'], + ['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'], + ['file', './test/Dockerfile'], + ['builder', 'builder-git-context-2'], + ['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', @@ -162,14 +185,13 @@ describe('getArgs', () => { '0.4.2', new Map([ ['context', '.'], - ['labels', 'org.opencontainers.image.source=UserProvidedSourceLabel'], - ['outputs', 'type=image,dest=./release-out'] + ['outputs', 'type=image,dest=./release-out'], + ['trace-data', 'true'] ]), [ 'buildx', 'build', - '--label', 'org.opencontainers.image.source=UserProvidedSourceLabel', - '--label', 'dockerfile-path=Dockerfile', + '--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', @@ -180,13 +202,13 @@ describe('getArgs', () => { '0.4.2', new Map([ ['context', '.'], - ['outputs', 'type=registry,dest=./release-out'] + ['outputs', 'type=registry,dest=./release-out'], + ['trace-data', 'true'] ]), [ 'buildx', 'build', - '--label', 'org.opencontainers.image.source=https://github.com/docker/build-push-action.git', - '--label', 'dockerfile-path=Dockerfile', + '--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', @@ -197,14 +219,13 @@ describe('getArgs', () => { '0.4.2', new Map([ ['context', '.'], - ['labels', 'org.opencontainers.image.source=UserProvidedSourceLabel'], - ['load', 'true'] + ['load', 'true'], + ['trace-data', 'true'] ]), [ 'buildx', 'build', - '--label', 'org.opencontainers.image.source=UserProvidedSourceLabel', - '--label', 'dockerfile-path=Dockerfile', + '--label', 'dockerfile-path=https://github.com/docker/build-push-action.git#test-jest/Dockerfile', '--iidfile', '/tmp/.docker-build-push-jest/iidfile', '--file', 'Dockerfile', '--load', diff --git a/dist/index.js b/dist/index.js index 05918831b..952ae2273 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12092,7 +12092,14 @@ function getInputs(defaultContext) { 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 repoPath = defaultContext.replace('#head', '/blob'); + 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; diff --git a/src/context.ts b/src/context.ts index a6adfce8b..3c9731f9a 100644 --- a/src/context.ts +++ b/src/context.ts @@ -85,7 +85,14 @@ export async function getInputs(defaultContext: string): Promise { ) { //Add link to dockerfile as label let dockerfilePath = userInputs.file; - let repoPath = defaultContext.replace('#head', '/blob'); + 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}`); }