Skip to content

add: report error while creating dir for URL source. #6087

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

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

flouthoc
Copy link
Collaborator

@flouthoc flouthoc commented Mar 25, 2025

Correctly report back error when attempting to create Tmpdir for a
given url source.

Also remove superfluous isGitTag from define/types.go since git fetch correctly resolves by provided reference.

Fixfor: containers/podman#25679

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?

add: correctly resolve git tags and branches and report errors if no reference found

add.go Outdated
@@ -517,7 +517,7 @@ func (b *Builder) Add(destination string, extract bool, options AddAndCopyOption
if sourceIsGit(src) {
go func() {
var cloneDir, subdir string
cloneDir, subdir, getErr = define.TempDirForURL(tmpdir.GetTempDir(), "", src)
cloneDir, subdir, dirErr = define.TempDirForURL(tmpdir.GetTempDir(), "", src)
Copy link
Member

Choose a reason for hiding this comment

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

This should just return if getErr is not nil, as there's no point in continuing, and cloneDir and subdir are not expected to be useful values.

@flouthoc flouthoc force-pushed the add-report-err branch 2 times, most recently from 0866948 to 752b5be Compare March 25, 2025 19:20
@@ -260,13 +260,6 @@ func parseGitBuildContext(url string) (string, string, string) {
return gitBranchPart[0], gitSubdir, gitBranch
}

func isGitTag(remote, ref string) bool {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no need to for this because fetch below automatically fails if reference does not exists.

@@ -284,12 +277,6 @@ func cloneToDirectory(url, dir string) ([]byte, string, error) {
return combinedOutput, gitSubdir, fmt.Errorf("failed while performing `git remote add`: %w", err)
}

if gitRef != "" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no need for this fetch automatically resolves correct tag, branch or commit. If not found it fails.

@flouthoc flouthoc requested a review from nalind March 25, 2025 19:22
tests/bud.bats Outdated

cat > $contextdir/Dockerfile << _EOF
FROM alpine
RUN apk add git
Copy link
Member

Choose a reason for hiding this comment

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

The image shouldn't need git installed for ADD to work, so this step is unnecessary. It can be FROM scratch if it doesn't need to run anything after the content has been added.

@flouthoc flouthoc requested a review from nalind March 25, 2025 20:01
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.

Changes look good, but the commit log doesn't exactly reflect what was changed.

@flouthoc flouthoc changed the title add: correctly resolve git tags and branches add: report error while creating dir for URL source. Mar 25, 2025
@flouthoc
Copy link
Collaborator Author

@containers/buildah-maintainers PTAL

Comment on lines +521 to +520
defer wg.Done()
defer pipeWriter.Close()
Copy link
Member

Choose a reason for hiding this comment

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

The defer placement feels wrong, doing this after the function call but before errors checking is odd.
IMO they should be at the top of the function.

tests/bud.bats Outdated

cat > $contextdir/Dockerfile << _EOF
FROM scratch
ADD https://github.com/openshift/microshift.git#foobar /src
Copy link
Member

Choose a reason for hiding this comment

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

We have no direct control over this repo, if they ever add such a branch all our CI would break.
Can we use buildah instead?

Copy link
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

Other than @nalind's comments, LGTM

@flouthoc flouthoc force-pushed the add-report-err branch 2 times, most recently from 6dd6a43 to 8944852 Compare March 26, 2025 15:05
@flouthoc flouthoc requested a review from Luap99 March 26, 2025 15:05
tests/bud.bats Outdated
ADD https://github.com/containers/crun.git#nosuchbranch /src
_EOF
run_buildah 128 build -f $contextdir/Dockerfile -t git-image $contextdir
expect_output --substring "couldn't find remote ref foobar"
Copy link
Member

Choose a reason for hiding this comment

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

you switched to nosuchbranch but the test matches still foobar

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

my bad

Correctly report back error when attempting to create `Tmpdir` for a
given url source.

Also remove superfluous `isGitTag` from define/types.go since `git
fetch` correctly resolves by provided reference.

Closes: containers/podman#25679

Signed-off-by: flouthoc <[email protected]>
@flouthoc flouthoc requested a review from Luap99 March 26, 2025 15:18
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

/lgtm

But I don't have merge powers here I belive

Copy link
Contributor

openshift-ci bot commented Mar 26, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc, Luap99, nalind

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

@openshift-merge-bot openshift-merge-bot bot merged commit e4d3dc0 into containers:main Mar 26, 2025
35 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants