tilt-dev / tilt

Define your dev environment as code. For microservice apps on Kubernetes.
https://tilt.dev/
Apache License 2.0
7.7k stars 303 forks source link

Ignored folder added trigger rebuild #3447

Open gaetansnl opened 4 years ago

gaetansnl commented 4 years ago

Hello Everyone

I have some folder ignored in .dockerignore for example /dist. And I noticed that when dist is created, tilt detect the change, even if the folder is ignored.

wu-victor commented 4 years ago

Thanks for logging this.

samelie commented 4 years ago

I'm working with docker-compose and also seeing this compose.yml

 abroll-base:
    stdin_open: true
    tty: true
    build:
      context: ../
      dockerfile: dev/dockerfiles/abroll-base.Dockerfile
    image: abroll-base

Tiltfile

docker_build(
  # Image name - must match the image in the docker-compose file
  'abroll-base',
  # Docker context
  '.',
  dockerfile='dev/dockerfiles/abroll-base.Dockerfile',
  only=[
    './package.json',
    './yarn.lock',
    './lerna.json',
    './tsconfig.json',
    './tsconfig.build.json',
    './babel.config.js',
    ],
)

saving a file in the repo will cause that file to show in the 'EDITED HISTORY' within Tilt cli

landism commented 4 years ago

saving a file in the repo will cause that file to show in the 'EDITED HISTORY' within Tilt cli

Could you grab the output of tilt dump engine after this happens and share it? (publicly or privately)

samelie commented 4 years ago

Here is a gist of that command ran right after I changed a file. .env

abroll-pkgs picked up the change

docker_build(
  'abroll-pkgs',
  '.',
  dockerfile='dev/dockerfiles/abroll-pkgs.Dockerfile',
  only=[
    './packages',
    ],
  ignore=[
    './apps',
    './configs',
    ],
)

But only abroll-config should have

docker_build(
  'abroll-config',
  '.',
  dockerfile='dev/dockerfiles/abroll-config.Dockerfile',
  only=[
    './configs',
    ],
  ignore=[
    './apps',
    './packages',
    ],
)

Now in the docker-compose abroll-pkgs does depend_on abroll-config

version: '3.7'

services:
  abroll-base:
    stdin_open: true
    tty: true
    build:
      context: ../
      dockerfile: dev/dockerfiles/abroll-base.Dockerfile
    image: abroll-base
  abroll-config:
    stdin_open: true
    tty: true
    depends_on:
      - abroll-base
    build:
      context: ../
      dockerfile: dev/dockerfiles/abroll-config.Dockerfile
    image: abroll-config
  abroll-pkgs:
    stdin_open: true
    tty: true
    depends_on:
      - abroll-base
      - abroll-config
    build:
      context: ../
      dockerfile: dev/dockerfiles/abroll-pkgs.Dockerfile
    image: abroll-pkgs

Sorry if it's so messy and maybe full of noise?. If there is a way to clean it up for you, let me know https://gist.github.com/doogledor/8a8437486f7d3cf6c5b73db32db182c8

landism commented 4 years ago

Now in the docker-compose abroll-pkgs does depend_on abroll-config

Ah! This explains things. Tilt will rebuild an image when a file in its context changes, or when one of its base images changes.

Tilt's execution model is currently (and unfortunately for this issue) a bit simpler than what you're describing - Tilt sees .env change, so it rebuilds abroll-config. It doesn't know what files in abroll-config have changed as a result of that build, just that there was a rebuild, so it then rebuilds any other images that depend on abroll-config, i.e., abroll-pkgs.

The first two options I'd look into (though it's hard to say if either is better or even feasible without knowing about a specific setup):

  1. change the abroll-pkgs build so that it doesn't depend on abroll-config (may or may not be possible)
  2. set up a live_update for abroll-pkgs so that the rebuild is much quicker to reduce how annoying it is
samelie commented 4 years ago

Thank you landism for this advice. Coming multistage docker world, I was forcing something that wasn't needed.

Having 1 Dockerfile that does all the copying, shared between the various apps within the monorepo & using specific docker_builds( with live_update for each of the applications seems to be the way to go.