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

build: Add additional step nodes when labels are modified #3517

Merged

Conversation

flouthoc
Copy link
Collaborator

Make sure label modification behaviour stays similar to docker i.e
new step is added when labels are modified and leave caching of layers
to executor

Advantages.

  • Layers will be automatically cached if needed.
  • If Labels are modified , new step will be built and cached if
    configured instead of forcing pre-built cached layers.

See detailed discussion here: #3370 (comment)

Closes: #3370

@flouthoc
Copy link
Collaborator Author

Will add tests once we finalize on this discussion.

@flouthoc
Copy link
Collaborator Author

@containers/buildah-maintainers @nalind PTAL

@nalind
Copy link
Member

nalind commented Sep 14, 2021

Looks reasonable. Tests should definitely make sure this doesn't break weirdly on multistage builds and when the build replaces the base image (i.e., when the --from CLI option is used). Please take care around quoting label values.

value = ""
}
labelLine = fmt.Sprintf("LABEL %s=%s\n", key, value)
if len(labelLine) > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

When would this be false?

Copy link
Member

Choose a reason for hiding this comment

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

yeah, might be better to check if key and value don't equal ""

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is needed for basic validation since --label accepts arbitrary string similar check is also present in executor itself.

Copy link
Member

Choose a reason for hiding this comment

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

Right, but isn't labelLine at a minimum going to contain "LABEL = "? That would never be 0 or less right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@TomSweeneyRedHat oh right thanks changing this to key != "", we can support empty value since docker supports empty values (manually verified).

imagebuildah/build.go Outdated Show resolved Hide resolved
@rhatdan
Copy link
Member

rhatdan commented Sep 16, 2021

@flouthoc are you planning on updating this PR?

@flouthoc
Copy link
Collaborator Author

@rhatdan Just writing some test cases which covers all edge-cases.

@flouthoc flouthoc force-pushed the step-modified-labels branch 2 times, most recently from 4082903 to 684bb18 Compare September 16, 2021 08:40
@flouthoc
Copy link
Collaborator Author

@nalind added tests for regular and multi-staged builds

Muti-stage build test covers

  • Perform multi-stage build with label1=value1 and verify labels.
  • Relabel build with label1=value2 and verify
  • To make sure we are using cache rebuild with label1=value1 and makes sure everything is used from cache

Regular build with --from

  • Covers basic modifying of labels and base images

Just waiting for everything to pass.

@flouthoc flouthoc force-pushed the step-modified-labels branch 2 times, most recently from 0cb43af to 1d6ffeb Compare September 16, 2021 14:00
imagebuildah/build.go Outdated Show resolved Hide resolved
if len(label) > 1 {
value = label[1]
}
labelLine = fmt.Sprintf("LABEL \"%s\"=\"%s\"\n", key, value)
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look like it'll catch weirdness like values that include internal quotation marks of one kind or another.

Copy link
Collaborator Author

@flouthoc flouthoc Sep 16, 2021

Choose a reason for hiding this comment

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

@nalind i tried this buildah build --layers --label "label1=value'2" --from=alpine -t image1 works ! but this is failing buildah build --layers --label 'label1=value"2' --from=alpine -t image1 let me get a fix.

Copy link
Collaborator Author

@flouthoc flouthoc Sep 16, 2021

Choose a reason for hiding this comment

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

@nalind I have changed this formatting with simple %q it autoescapes things for us tested both the cases, " will be autoescaped but just thinking if buildah build --layers --label 'label1=value"2' --from=alpine -t image1 is even a valid input since --label accepts a string.

-                       labelLine = fmt.Sprintf("LABEL \"%s\"=\"%s\"\n", key, value)
+                       labelLine = fmt.Sprintf("LABEL %q=%q\n", key, value)

@rhatdan
Copy link
Member

rhatdan commented Sep 16, 2021

/approve
LGTM

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 16, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc, rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@flouthoc
Copy link
Collaborator Author

Just a rebase since main is updated.

Make sure label modification behaviour stays similar to docker i.e
new step is added when labels are modified and leave caching of layers
to executor

Advantages.

* Layers will be automatically cached if needed.
* If Labels are modified , new step will be built and cached if
  configured instead of forcing pre-built cached layers.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
@TomSweeneyRedHat
Copy link
Member

LGTM
I'm not sure if this needs a rebase or not....

@rhatdan
Copy link
Member

rhatdan commented Sep 17, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Sep 17, 2021
@openshift-merge-robot openshift-merge-robot merged commit f3f3c55 into containers:main Sep 17, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rebuild labels with build --label
5 participants