From 4c6416ce1e7b78d1a39673b94134ac0dde9755de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Bebr=C4=ABtis?= Date: Tue, 3 Dec 2024 16:38:21 +0200 Subject: [PATCH] use Dockerfile-specific ignore-file when present --- cmd/ciImageBuild.go | 4 ++++ cmd/ciImageUrl.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cmd/ciImageBuild.go b/cmd/ciImageBuild.go index 2623f57..6568a66 100644 --- a/cmd/ciImageBuild.go +++ b/cmd/ciImageBuild.go @@ -56,6 +56,10 @@ var ciImageBuildCmd = &cobra.Command{ if _, err := os.Stat(fmt.Sprintf("%s/.dockerignore", buildPath)); err == nil { excludeDockerignore = fmt.Sprintf("--exclude-from='%s'/.dockerignore", buildPath) } + // use .dockerignore if exists, later takes precedence + if _, err := os.Stat(fmt.Sprintf("%s.dockerignore", dockerfile)); err == nil { + excludeDockerignore = fmt.Sprintf("--exclude-from='%s.dockerignore'", dockerfile) + } // If no path is specified, build from an empty directory if len(buildPath) == 0 { diff --git a/cmd/ciImageUrl.go b/cmd/ciImageUrl.go index 538963c..f9984b1 100644 --- a/cmd/ciImageUrl.go +++ b/cmd/ciImageUrl.go @@ -49,6 +49,10 @@ var ciImageUrlCmd = &cobra.Command{ if _, err := os.Stat(fmt.Sprintf("%s/.dockerignore", buildPath)); err == nil { excludeDockerignore = fmt.Sprintf("--exclude-from='%s'/.dockerignore", buildPath) } + // use .dockerignore if exists, later takes precedence + if _, err := os.Stat(fmt.Sprintf("%s.dockerignore", dockerfile)); err == nil { + excludeDockerignore = fmt.Sprintf("--exclude-from='%s.dockerignore'", dockerfile) + } // If no path is specified, build from an empty directory if len(buildPath) == 0 {