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 --no-hostname option to buildah containers #5094

Merged
merged 2 commits into from Oct 25, 2023

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Oct 20, 2023

Fixes: #5093

What type of PR is this?

/kind api-change
/kind bug
/kind cleanup
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
/kind other

What this PR does / why we need it:

How to verify it

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

`buildah build --no-hostname` hostname added to allow for users to not setup /etc/hostname within builds.

@rhatdan
Copy link
Member Author

rhatdan commented Oct 20, 2023

Copy link
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

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

Mostly nits.

docs/buildah-build.1.md Outdated Show resolved Hide resolved
run.go Outdated Show resolved Hide resolved
run_linux.go Outdated
@@ -269,8 +269,7 @@ func (b *Builder) Run(command []string, options RunOptions) error {
bindFiles[config.DefaultHostsFile] = hostFile
}

// generate /etc/hostname if the user intentionally did not override
if !(contains(volumes, "/etc/hostname")) {
if !options.NoHostname && !(contains(volumes, "/etc/hostname")) {
if _, ok := bindFiles["/etc/hostname"]; !ok {
Copy link
Member

Choose a reason for hiding this comment

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

I don't see how ok can ever be true here. Did I miss something?

Copy link
Member 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 for the use case where a user does -v /tmp/hostname:/etc/hostname

Copy link
Member

Choose a reason for hiding this comment

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

I still don't follow. If I'm reading it right, the bindFiles map has, at most, one item in it: a value for the config.DefaultHostsFile key. A -v flag from the command line would show up in options.Volumes or b.CommonBuildOpts.Volumes, or maybe both if we're in build.

contains() probably shouldn't exist when we got rid of for github.com/containers/buildah/util.StringInSlice() in favor of github.com/containers/common/pkg/util.StringInSlice().

Copy link
Member Author

Choose a reason for hiding this comment

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

That was existing code, so I will remove the check.

@@ -137,10 +139,15 @@ func runCmd(c *cobra.Command, args []string, iopts runInputOptions) error {
}
}

if len(iopts.hostname) > 0 && iopts.noHostname {
return errors.New("--no-hostname and --hostname conflict, can not be used together")
Copy link
Member

Choose a reason for hiding this comment

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

One's a setting in the UTS namespace, the other's a file. Do they conflict?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe --hostname attempts to set the hostname field in /etc/hostname, if you don't think this would confuse the user, then I am fine with removing it.

Copy link
Member

Choose a reason for hiding this comment

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

I'd remove the test

tests/bud.bats Outdated Show resolved Hide resolved
tests/bud.bats Outdated Show resolved Hide resolved
tests/bud.bats Outdated
cat > $mytmpdir/Containerfile << _EOF
from alpine
RUN mv /etc /usr/
RUN ls -l /etc
Copy link
Member

Choose a reason for hiding this comment

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

The content of this file will always be the same. Why are we generating it every time this test runs?

Copy link
Member Author

Choose a reason for hiding this comment

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

This file has different content then the previous?

Copy link
Member

Choose a reason for hiding this comment

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

Use two static files?

tests/bud.bats Outdated Show resolved Hide resolved
tests/bud.bats Outdated Show resolved Hide resolved

By default, Buildah manages _/etc/hostname_, adding the container's own hostname.
**--no-hostname** disables this, and the image's _/etc/hostname_ will be preserved unmodified if it exists.
Conflicts with the --hostname option.
Copy link
Member

Choose a reason for hiding this comment

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

If you remove the test above, you should remove this line too.

@@ -645,9 +645,17 @@ Valid _mode_ values are:

Do not use existing cached images for the container build. Build from the start with a new set of cached layers.

**--no-hostname**

Do not create _/etc/hostname_ for RUN instructions.
Copy link
Member

Choose a reason for hiding this comment

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

Soft suggestion

Suggested change
Do not create _/etc/hostname_ for RUN instructions.
Do not create the _/etc/hostname_ file in the container for RUN instructions.


Do not create _/etc/hostname_ for RUN instructions.

By default, Buildah manages _/etc/hostname_, adding the container's own hostname.
Copy link
Member

Choose a reason for hiding this comment

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

I'm on the fence about adding the word file after /etc/hostname here and below.

@rhatdan rhatdan force-pushed the hostname branch 5 times, most recently from 9d95258 to c6ffdc7 Compare October 23, 2023 18:31
@rhatdan
Copy link
Member Author

rhatdan commented Oct 24, 2023

@umohnani8
Copy link
Member

LGTM

@rhatdan I think it needs a rebase though

@TomSweeneyRedHat
Copy link
Member

LGTM

Fixes: containers#5093

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

Restarted flaking test
LGTM
/lgtm
/hold

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 25, 2023

[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

@rhatdan
Copy link
Member Author

rhatdan commented Oct 25, 2023

/unhold

@openshift-ci openshift-ci bot merged commit c9523b3 into containers:main Oct 25, 2023
36 checks passed
@vrothberg
Copy link
Member

Reminder to also open Podman PRs when adding new build flags. Currently, Podman CI breaks when vendoring Buildah.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 25, 2024
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.

[OSTree] Cannot build rootfs with Containerfile due to dangling files /etc/{hostname,hosts,resolv.conf}
6 participants