Skip to content

Commit c3b0973

Browse files
authored
Merge pull request #5048 from camilamacedo86/improve-dockerignore
🐛 (go/v4): Fix Docker builds failing when projects don’t include apis/, controllers/, or webhooks by updating .dockerignore to allow only Go source files and module metadata
2 parents b77b135 + c2e1e09 commit c3b0973

File tree

14 files changed

+84
-42
lines changed

14 files changed

+84
-42
lines changed
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
3-
bin/
2+
# Ignore everything by default and re-include only needed files
3+
**
4+
5+
# Re-include Go source files (but not *_test.go)
6+
!**/*.go
7+
**/*_test.go
8+
9+
# Re-include Go module files
10+
!go.mod
11+
!go.sum

docs/book/src/cronjob-tutorial/testdata/project/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ COPY go.sum go.sum
1111
# and so that source changes don't invalidate our downloaded layer
1212
RUN go mod download
1313

14-
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
16-
COPY api/ api/
17-
COPY internal/ internal/
14+
# Copy the Go source (relies on .dockerignore to filter)
15+
COPY . .
1816

1917
# Build
2018
# the GOARCH has no default value to allow the binary to be built according to the host where the command
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
3-
bin/
2+
# Ignore everything by default and re-include only needed files
3+
**
4+
5+
# Re-include Go source files (but not *_test.go)
6+
!**/*.go
7+
**/*_test.go
8+
9+
# Re-include Go module files
10+
!go.mod
11+
!go.sum

docs/book/src/getting-started/testdata/project/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ COPY go.sum go.sum
1111
# and so that source changes don't invalidate our downloaded layer
1212
RUN go mod download
1313

14-
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
16-
COPY api/ api/
17-
COPY internal/ internal/
14+
# Copy the Go source (relies on .dockerignore to filter)
15+
COPY . .
1816

1917
# Build
2018
# the GOARCH has no default value to allow the binary to be built according to the host where the command
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
3-
bin/
2+
# Ignore everything by default and re-include only needed files
3+
**
4+
5+
# Re-include Go source files (but not *_test.go)
6+
!**/*.go
7+
**/*_test.go
8+
9+
# Re-include Go module files
10+
!go.mod
11+
!go.sum

docs/book/src/multiversion-tutorial/testdata/project/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ COPY go.sum go.sum
1111
# and so that source changes don't invalidate our downloaded layer
1212
RUN go mod download
1313

14-
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
16-
COPY api/ api/
17-
COPY internal/ internal/
14+
# Copy the Go source (relies on .dockerignore to filter)
15+
COPY . .
1816

1917
# Build
2018
# the GOARCH has no default value to allow the binary to be built according to the host where the command

pkg/plugins/golang/v4/scaffolds/internal/templates/dockerfile.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ COPY go.sum go.sum
5151
# and so that source changes don't invalidate our downloaded layer
5252
RUN go mod download
5353
54-
# Copy the go source
55-
COPY cmd/main.go cmd/main.go
56-
COPY api/ api/
57-
COPY internal/ internal/
54+
# Copy the Go source (relies on .dockerignore to filter)
55+
COPY . .
5856
5957
# Build
6058
# the GOARCH has no default value to allow the binary to be built according to the host where the command

pkg/plugins/golang/v4/scaffolds/internal/templates/dockerignore.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func (f *DockerIgnore) SetTemplateDefaults() error {
3939
}
4040

4141
const dockerignorefileTemplate = `# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
42-
# Ignore build and test binaries.
43-
bin/
42+
# Ignore everything by default and re-include only needed files
43+
**
44+
45+
# Re-include Go source files (but not *_test.go)
46+
!**/*.go
47+
**/*_test.go
48+
49+
# Re-include Go module files
50+
!go.mod
51+
!go.sum
4452
`
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
3-
bin/
2+
# Ignore everything by default and re-include only needed files
3+
**
4+
5+
# Re-include Go source files (but not *_test.go)
6+
!**/*.go
7+
**/*_test.go
8+
9+
# Re-include Go module files
10+
!go.mod
11+
!go.sum

testdata/project-v4-multigroup/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ COPY go.sum go.sum
1111
# and so that source changes don't invalidate our downloaded layer
1212
RUN go mod download
1313

14-
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
16-
COPY api/ api/
17-
COPY internal/ internal/
14+
# Copy the Go source (relies on .dockerignore to filter)
15+
COPY . .
1816

1917
# Build
2018
# the GOARCH has no default value to allow the binary to be built according to the host where the command

0 commit comments

Comments
 (0)