Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context-subdir input #532

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions __tests__/context.test.ts
Expand Up @@ -491,6 +491,43 @@ nproc=3`],
'.'
]
],
[
15,
'0.7.0',
new Map<string, string>([
['context-subdir', 'test'],
['load', 'false'],
['no-cache', 'false'],
['pull', 'false'],
['push', 'false'],
]),
[
'buildx',
'build',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--metadata-file', '/tmp/.docker-build-push-jest/metadata-file',
'https://github.com/docker/build-push-action.git#refs/heads/test-jest:test'
]
],
[
16,
'0.7.0',
new Map<string, string>([
['context', './test'],
['context-subdir', 'should-be-ignored'],
['load', 'false'],
['no-cache', 'false'],
['pull', 'false'],
['push', 'false'],
]),
[
'buildx',
'build',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--metadata-file', '/tmp/.docker-build-push-jest/metadata-file',
'./test'
]
],
])(
'[%d] given %p with %p as inputs, returns %p',
async (num: number, buildxVersion: string, inputs: Map<string, any>, expected: Array<string>) => {
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -28,6 +28,9 @@ inputs:
context:
description: "Build's context is the set of files located in the specified PATH or URL"
required: false
context-subdir:
description: "Subdirectory of the git repo to use as the docker build context (when using a URL-based context)"
required: false
file:
description: "Path to the Dockerfile"
required: false
Expand Down
12 changes: 11 additions & 1 deletion dist/index.js

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

12 changes: 11 additions & 1 deletion src/context.ts
Expand Up @@ -20,6 +20,7 @@ export interface Inputs {
cacheTo: string[];
cgroupParent: string;
context: string;
contextSubdir: string;
file: string;
labels: string[];
load: boolean;
Expand Down Expand Up @@ -73,6 +74,7 @@ export async function getInputs(defaultContext: string): Promise<Inputs> {
cacheTo: await getInputList('cache-to', true),
cgroupParent: core.getInput('cgroup-parent'),
context: core.getInput('context') || defaultContext,
contextSubdir: core.getInput('context-subdir'),
file: core.getInput('file'),
labels: await getInputList('labels', true),
load: core.getBooleanInput('load'),
Expand All @@ -97,7 +99,15 @@ export async function getArgs(inputs: Inputs, defaultContext: string, buildxVers
let args: Array<string> = ['buildx'];
args.push.apply(args, await getBuildArgs(inputs, defaultContext, buildxVersion));
args.push.apply(args, await getCommonArgs(inputs, buildxVersion));
args.push(inputs.context);
let context: string = inputs.context;
if (inputs.contextSubdir) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the ability to add a subdirectory is only available in BuildX starting with v0.7.0, shouldn't you check that buildxVersion satisfies that? 🤔

if (context == defaultContext) {
context = `${context}:${inputs.contextSubdir}`;
} else {
core.warning('"context-subdir" input is ignored when a "context" input is present');
}
}
args.push(context);
return args;
}

Expand Down