devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.34k stars 361 forks source link

dockerignore is ignored #2723

Closed xgalaxy closed 1 year ago

xgalaxy commented 1 year ago

What happened?

.dockerignore file is being.. well.. ignored when doing devspace deploy :)

If a dockerfile contains the contents:

COPY . .

Files listed in the .dockerignore get copied into the image anyway. This also results in a needless cache invalidation of that image layer. Which was reported in 2021 here.

What did you expect to happen instead?

The .dockerignore file should be respected when doing a deploy.

How can we reproduce the bug? (as minimally and precisely as possible)

My devspace.yaml:

version: v2beta1
name: playground

images:
  test:
    image: test
    buildKit: {}
    dockerfile: k8s/Dockerfile

deployments:
  test:
    helm:
      chart:
        name: component-chart
        repo: https://charts.devspace.sh

My dockerfile:

# syntax=docker/dockerfile:1.4
FROM mcr.microsoft.com/devcontainers/go:1.20-bookworm AS develop
ENV GOMODCACHE=/cache/gomod
ENV GOCACHE=/cache/gobuild
WORKDIR /app
COPY . .
RUN --mount=type=cache,target=/cache/gomod \
    go mod download
RUN --mount=type=cache,target=/cache/gomod \
    --mount=type=cache,target=/cache/gobuild \
    CGO_ENABLED=0 GOOS=linux go build -o main ./cmd/${SERVICE_NAME}

FROM gcr.io/distroless/base-debian11 AS production
COPY --from=build /app/main /
CMD ["/main"]

My .dockerignore

.git
.idea
k8s
devspace.yaml

Local Environment:

Anything else we should know: Same setup transported to Tilt does not exhibit this behavior. So I don't think this is a docker/buildkit bug.

xgalaxy commented 1 year ago

I figured out what the problem is.

If you create an image with the above criteria mentioned in the ticket. And do nothing else but add a .dockerignore something, somewhere will never adhere to the dockerignore file.

Only until I purged the image and rebuilt it from scratch did it start adhering to the dockerignore thereafter.

Weird issue.