-
Notifications
You must be signed in to change notification settings - Fork 639
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
fix dockerfile local dir #1192
fix dockerfile local dir #1192
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,38 @@ CMD ["echo", "nerdctl-build-test-stdin"] | |
base.Cmd("build", "-t", imageName, "-f", "-", ".").CmdOption(testutil.WithStdin(strings.NewReader(dockerfile))).AssertCombinedOutContains(imageName) | ||
} | ||
|
||
func TestBuildWithDockerfile(t *testing.T) { | ||
testutil.RequiresBuild(t) | ||
base := testutil.NewBase(t) | ||
defer base.Cmd("builder", "prune").Run() | ||
imageName := testutil.Identifier(t) | ||
defer base.Cmd("rmi", imageName).Run() | ||
|
||
dockerfile := fmt.Sprintf(`FROM %s | ||
CMD ["echo", "nerdctl-build-test-dockerfile"] | ||
`, testutil.CommonImage) | ||
|
||
buildCtx := filepath.Join(t.TempDir(), "test") | ||
err := os.MkdirAll(buildCtx, 0755) | ||
assert.NilError(t, err) | ||
err = os.WriteFile(filepath.Join(buildCtx, "Dockerfile"), []byte(dockerfile), 0644) | ||
assert.NilError(t, err) | ||
|
||
pwd, err := os.Getwd() | ||
assert.NilError(t, err) | ||
err = os.Chdir(buildCtx) | ||
assert.NilError(t, err) | ||
defer os.Chdir(pwd) | ||
|
||
// hack os.Getwd return "(unreachable)" on rootless | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this happen? Can't find "unreachable" error in the code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually don't know what happened, https://github.com/containerd/nerdctl/runs/7196804919?check_suite_focus=true#step:5:1004 |
||
t.Setenv("PWD", buildCtx) | ||
|
||
base.Cmd("build", "-t", imageName, "-f", "Dockerfile", "..").AssertOK() | ||
base.Cmd("build", "-t", imageName, "-f", "Dockerfile", ".").AssertOK() | ||
// fail err: no such file or directory | ||
base.Cmd("build", "-t", imageName, "-f", "../Dockerfile", ".").AssertFail() | ||
} | ||
|
||
func TestBuildLocal(t *testing.T) { | ||
t.Parallel() | ||
testutil.DockerIncompatible(t) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Why do we need builder prune? Won't these slow our tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @ktock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manugupt1 @junnplus This was to ensure all content (possibly leased by BuildKit) in the content store gets pruned after each test. Tests may check the behaviour of pulling blobs and contents remaining in the content store unexpectedly skip these operations.But yes, we may improve this by removing
defer base.Cmd("builder", "prune").Run()
and instead addingrmiAll()
(defined inimage_encrypt_linux_test.go
) to tests (if exist) requiring clean content store. Thanks for pointing this out :)