Skip to content

docker_build is not respecting .dockerignore #5745

@garyng

Description

@garyng

Expected Behavior

docker_build should respect .dockerignore.

Current Behavior

docker_build seems to ignore .dockerignore causing very long build if there are a lot of ignored files (eg: node_modules). I did some search on GitHub and found this: #5416, which might be relevant?

Steps to Reproduce

  1. Clone https://github.com/tilt-dev/tilt-avatars
  2. Run tilt up
  3. Observe the time for [background] read source files, in this case it was [background] read source files 61.67kB [done: 2.789s]
STEP 1/3 — Building Dockerfile: [tilt-avatar-web]
Building Dockerfile for platform linux/amd64:
  FROM node:16-bullseye-slim
  
  ENV YARN_CACHE_FOLDER=/cache/yarn
  
  WORKDIR /app
  
  # install dependencies
  COPY web/package.json web/yarn.lock ./
  RUN --mount=type=cache,target=/cache/yarn \
    yarn install
  
  # copy app source
  COPY web/ ./
  
  CMD ["yarn", "dev"]

     Building image
     [stage-0 1/5] FROM docker.io/library/node:16-bullseye-slim@sha256:9ae59bd83f46c6e6b83c0552fdfb0da00b3df50542b80ec818c658438cc61af1 68.68MB / 68.68MB [done: 58.791s]
     [background] read source files 61.67kB [done: 2.789s]
     [stage-0 2/5] WORKDIR /app [done: 10.288s]
     [stage-0 3/5] COPY web/package.json web/yarn.lock ./ [done: 5.699s]
     [stage-0 4/5] RUN --mount=type=cache,target=/cache/yarn   yarn install
       → yarn install v1.22.18
       → [1/4] Resolving packages...
       → [2/4] Fetching packages...
       → [3/4] Linking dependencies...
       → [4/4] Building fresh packages...
       → Done in 27.73s.
     [stage-0 4/5] RUN --mount=type=cache,target=/cache/yarn   yarn install [done: 38.546s]
     [stage-0 5/5] COPY web/ ./ [done: 4.13s]
     exporting to image [done: 13.678s]
  1. Run npm install inside web
    (I installed a few more packages to get a bigger node_modules: npm i bootstrap lodash chalk request commander react express debug async fs-extra moment bluebird underscore vue axios tslib glob rxjs babel-core yeoman-generator)
  2. Run tilt up
  3. Observe the time for [background] read source files, this time it was [background] read source files 384.47kB [done: 3m37.945s]
STEP 1/3 — Building Dockerfile: [tilt-avatar-web]
Building Dockerfile for platform linux/amd64:
  FROM node:16-bullseye-slim
  
  ENV YARN_CACHE_FOLDER=/cache/yarn
  
  WORKDIR /app
  
  # install dependencies
  COPY web/package.json web/yarn.lock ./
  RUN --mount=type=cache,target=/cache/yarn \
    yarn install
  
  # copy app source
  COPY web/ ./
  
  CMD ["yarn", "dev"]

     Building image
     [stage-0 1/5] FROM docker.io/library/node:16-bullseye-slim@sha256:9ae59bd83f46c6e6b83c0552fdfb0da00b3df50542b80ec818c658438cc61af1
     [background] read source files 384.47kB [done: 3m37.945s]
     [stage-0 2/5] WORKDIR /app [cached]
     [stage-0 3/5] COPY web/package.json web/yarn.lock ./ [done: 1.644s]
     [stage-0 4/5] RUN --mount=type=cache,target=/cache/yarn   yarn install
       → yarn install v1.22.18
       → [1/4] Resolving packages...
       → [2/4] Fetching packages...
       → [3/4] Linking dependencies...
       → warning " > bootstrap@5.1.3" has unmet peer dependency "@popperjs/core@^2.10.2".
       → [4/4] Building fresh packages...
       → success Saved lockfile.
       → Done in 36.24s.
     [stage-0 4/5] RUN --mount=type=cache,target=/cache/yarn   yarn install [done: 40.442s]
     [stage-0 5/5] COPY web/ ./ [done: 2.056s]
     exporting to image [done: 4.975s]

Context

tilt doctor Output

$ tilt doctor
...

Tilt: v0.27.3, built 2022-04-22
System: linux-amd64
---
Docker
- Host: [default]
- Server Version: 20.10.14
- API Version: 1.41
- Builder: 2
- Compose Version: v1.29.2 (build 5becea4c)
---
Kubernetes
- Env: docker-desktop
- Context: docker-desktop
- Cluster Name: docker-desktop
- Namespace: default
- Container Runtime: docker
- Version: v1.22.5
- Cluster Local Registry: none
---
Thanks for seeing the Tilt Doctor!
Please send the info above when filing bug reports. 💗

The info below helps us understand how you're using Tilt so we can improve,
but is not required to ask for help.
---
Analytics Settings
--> (These results reflect your personal opt in/out status and may be overridden by an `analytics_settings` call in your Tiltfile)
- User Mode: opt-out
- Machine: 2e40bfee00900c30e704f0a120347b62
- Repo: 3oHS3Sdl6tpcRYbbMgRgBg=

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions