Skip to content

Commit 797ecad

Browse files
authored
Ignore Dockerfile/Compose files by default (#1013)
* Ignore Dockerfile by default * Ignore compose include files
1 parent de2848c commit 797ecad

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/pkg/cli/compose/context.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,33 @@ const (
3939
ContextSizeSoftLimit = 10 * MiB
4040
DefaultContextSizeHardLimit = 100 * MiB
4141

42-
sourceDateEpoch = 315532800 // 1980-01-01, same as nix-shell
42+
sourceDateEpoch = 315532800 // 1980-01-01, same as nix-shell
43+
// The default .dockerignore for projects that don't have one. Keep in sync with upload.ts in pulumi-defang repo.
4344
defaultDockerIgnore = `# Default .dockerignore file for Defang
44-
**/.DS_Store
45+
**/__pycache__
4546
**/.direnv
47+
**/.DS_Store
4648
**/.envrc
4749
**/.git
4850
**/.github
4951
**/.idea
5052
**/.next
5153
**/.vscode
52-
**/__pycache__
54+
**/compose.*.yaml
55+
**/compose.*.yml
5356
**/compose.yaml
5457
**/compose.yml
55-
**/defang.exe
56-
**/docker-compose.yml
58+
**/docker-compose.*.yaml
59+
**/docker-compose.*.yml
5760
**/docker-compose.yaml
61+
**/docker-compose.yml
5862
**/node_modules
5963
**/Thumbs.db
64+
Dockerfile
65+
*.Dockerfile
6066
# Ignore our own binary, but only in the root to avoid ignoring subfolders
6167
defang
68+
defang.exe
6269
# Ignore our project-level state
6370
.defang`
6471
)

src/pkg/cli/compose/context_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,25 @@ func TestWalkContextFolder(t *testing.T) {
109109
t.Fatal("WalkContextFolder() should have failed")
110110
}
111111
})
112+
113+
t.Run("Default .dockerignore", func(t *testing.T) {
114+
var files []string
115+
err := WalkContextFolder("../../../testdata/alttestproj", "", func(path string, de os.DirEntry, slashPath string) error {
116+
if strings.Contains(slashPath, "alttestproj") {
117+
t.Errorf("Path is not relative: %v", slashPath)
118+
}
119+
files = append(files, slashPath)
120+
return nil
121+
})
122+
if err != nil {
123+
t.Fatalf("WalkContextFolder() failed: %v", err)
124+
}
125+
126+
expected := []string{"Dockerfile", "altcomp.yaml", "compose.yaml.fixup", "compose.yaml.golden", "compose.yaml.warnings"}
127+
if !reflect.DeepEqual(files, expected) {
128+
t.Errorf("Expected files: %v, got %v", expected, files)
129+
}
130+
})
112131
}
113132

114133
func TestCreateTarballReader(t *testing.T) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file should not be included in the build context
2+
FROM scratch

0 commit comments

Comments
 (0)