mirror of
https://github.com/containers/podman.git
synced 2025-05-21 00:56:36 +08:00
Merge pull request #10913 from rhatdan/build
podman-remote build use .containerignore over .dockerignore
This commit is contained in:
@ -302,7 +302,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
|
|||||||
tarContent := []string{options.ContextDirectory}
|
tarContent := []string{options.ContextDirectory}
|
||||||
newContainerFiles := []string{}
|
newContainerFiles := []string{}
|
||||||
|
|
||||||
dontexcludes := []string{"!Dockerfile", "!Containerfile"}
|
dontexcludes := []string{"!Dockerfile", "!Containerfile", "!.dockerignore", "!.containerignore"}
|
||||||
for _, c := range containerFiles {
|
for _, c := range containerFiles {
|
||||||
if c == "/dev/stdin" {
|
if c == "/dev/stdin" {
|
||||||
content, err := ioutil.ReadAll(os.Stdin)
|
content, err := ioutil.ReadAll(os.Stdin)
|
||||||
@ -550,9 +550,13 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseDockerignore(root string) ([]string, error) {
|
func parseDockerignore(root string) ([]string, error) {
|
||||||
ignore, err := ioutil.ReadFile(filepath.Join(root, ".dockerignore"))
|
ignore, err := ioutil.ReadFile(filepath.Join(root, ".containerignore"))
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error reading .dockerignore: '%s'", root)
|
var dockerIgnoreErr error
|
||||||
|
ignore, dockerIgnoreErr = ioutil.ReadFile(filepath.Join(root, ".dockerignore"))
|
||||||
|
if dockerIgnoreErr != nil && !os.IsNotExist(dockerIgnoreErr) {
|
||||||
|
return nil, errors.Wrapf(err, "error reading .containerignore: '%s'", root)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rawexcludes := strings.Split(string(ignore), "\n")
|
rawexcludes := strings.Split(string(ignore), "\n")
|
||||||
excludes := make([]string, 0, len(rawexcludes))
|
excludes := make([]string, 0, len(rawexcludes))
|
||||||
|
@ -851,7 +851,7 @@ EOF
|
|||||||
run_podman rmi -f build_test
|
run_podman rmi -f build_test
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "podman build -f test " {
|
@test "podman build -f test" {
|
||||||
tmpdir=$PODMAN_TMPDIR/build-test
|
tmpdir=$PODMAN_TMPDIR/build-test
|
||||||
subdir=$tmpdir/subdir
|
subdir=$tmpdir/subdir
|
||||||
mkdir -p $subdir
|
mkdir -p $subdir
|
||||||
@ -877,6 +877,44 @@ EOF
|
|||||||
run_podman rmi -f build_test
|
run_podman rmi -f build_test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "podman build .dockerignore failure test" {
|
||||||
|
tmpdir=$PODMAN_TMPDIR/build-test
|
||||||
|
subdir=$tmpdir/subdir
|
||||||
|
mkdir -p $subdir
|
||||||
|
|
||||||
|
cat >$tmpdir/.dockerignore <<EOF
|
||||||
|
*
|
||||||
|
subdir
|
||||||
|
!*/sub1*
|
||||||
|
EOF
|
||||||
|
cat >$tmpdir/Containerfile <<EOF
|
||||||
|
FROM $IMAGE
|
||||||
|
COPY ./ ./
|
||||||
|
COPY subdir ./
|
||||||
|
EOF
|
||||||
|
run_podman 125 build -t build_test $tmpdir
|
||||||
|
is "$output" ".*Error: error building at STEP \"COPY subdir ./\"" ".dockerignore was ignored"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "podman build .containerignore and .dockerignore test" {
|
||||||
|
tmpdir=$PODMAN_TMPDIR/build-test
|
||||||
|
mkdir -p $tmpdir
|
||||||
|
touch $tmpdir/test1 $tmpdir/test2
|
||||||
|
cat >$tmpdir/.containerignore <<EOF
|
||||||
|
test2*
|
||||||
|
EOF
|
||||||
|
cat >$tmpdir/.dockerignore <<EOF
|
||||||
|
test1*
|
||||||
|
EOF
|
||||||
|
cat >$tmpdir/Containerfile <<EOF
|
||||||
|
FROM $IMAGE
|
||||||
|
COPY ./ /tmp/test/
|
||||||
|
RUN ls /tmp/test/
|
||||||
|
EOF
|
||||||
|
run_podman build -t build_test $tmpdir
|
||||||
|
is "$output" ".*test1" "test1 should exists in the final image"
|
||||||
|
}
|
||||||
|
|
||||||
function teardown() {
|
function teardown() {
|
||||||
# A timeout or other error in 'build' can leave behind stale images
|
# A timeout or other error in 'build' can leave behind stale images
|
||||||
# that podman can't even see and which will cascade into subsequent
|
# that podman can't even see and which will cascade into subsequent
|
||||||
|
Reference in New Issue
Block a user