From c59c0cec43bb5c8fed0f1ecfd6c14b0da21a318c Mon Sep 17 00:00:00 2001 From: Jyotsna Date: Wed, 11 Nov 2020 21:07:49 +0530 Subject: [PATCH] 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 f50d6a1..b27df08 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 0591883..952ae22 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 a6adfce..3c9731f 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}`); }