GoogleContainerTools/skaffold

[sync] dockerfile infer sync mode not working as expected.

Open

#4,898 opened on Oct 10, 2020

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Go (12,822 stars) (1,416 forks)batch import
area/syncbuild/dockergood first issuekind/frictionpriority/p2

Description

I have a dockerfile for a ruby app project here

FROM library/ruby:2.3.0
  
# Install essential Linux packages
RUN apt-get update -qq && apt-get install -y \
    build-essential \
    nodejs

RUN mkdir /dashboard
WORKDIR /dashboard

# Copy Gemfile and Gemfile.lock
COPY Gemfile /dashboard/

# Speed up nokogiri install
ENV NOKOGIRI_USE_SYSTEM_LIBRARIES 1
ENV BUNDLER_VERSION=2.1.4

RUN gem install bundler -v 2.0.2
RUN gem update bundler
RUN bundle install

EXPOSE 3030

COPY .  /dashboard

CMD dashing start -p 3030 --address 0.0.0.0

I want to configure sync for one the css file. As per the docs, i do the following

apiVersion: skaffold/v2beta7
kind: Config
metadata:
  name: github-dashing
build:
  artifacts:
  - image: github-dash
    sync:
      infer:
        - 'assets/**/*'
deploy:
  kubectl:
    manifests:
    - k8s/deployment.yaml
portForward:
  - resourceType: deployment
    resourceName: github-dash
    port: 3030
    localPort: 8080

However, when i make change to one of the files in assets assets/javascripts/application.coffee , a re-build is triggered.

  1. first case, since i had opened the project in intellij, a change to /Users/tejaldesai/workspace/github-dashing/.idea/workspace.xml is detected. This file is not added in .docerignore and hence triggers a re-build.
DEBU[0039] Change detected notify.Write: "/Users/tejaldesai/workspace/github-dashing/assets/javascripts/application.coffee" 
DEBU[0039] Change detected notify.Write: "/Users/tejaldesai/workspace/github-dashing/.idea/workspace.xml" 
TRAC[0039] Checking base image library/ruby:2.3.0 for ONBUILD triggers. 
Port forwarding deployment/github-dash in namespace default, remote port 3030 -> address 127.0.0.1 port 8080
DEBU[0039] Found dependencies for dockerfile: [{Gemfile /dashboard true} {. /dashboard false}] 
DEBU[0039] Running command: [kubectl --context minikube port-forward --pod-running-timeout 1s --namespace default deployment/github-dash 8080:3030] 
INFO[0039] files modified: [.idea/workspace.xml assets/javascripts/application.coffee] 
TRAC[0039] Checking base image library/ruby:2.3.0 for ONBUILD triggers. 
DEBU[0039] Found dependencies for dockerfile: [{Gemfile /dashboard true} {. /dashboard false}] 
INFO[0039] Changed file .idea/workspace.xml does not match any sync pattern. Skipping sync 
Generating tags...
 - github-dash -> DEBU[0039] Running command: [git describe --tags --always] 
DEBU[0039] Command output: [2662512
]                   
  1. After adding a idea/* to .dockerignore, sync was triggered.
DEBU[0021] Change detected notify.Write: "/Users/tejaldesai/workspace/github-dashing/assets/javascripts/application.coffee" 
DEBU[0021] Command output: [], stderr: tar: Removing leading `/' from member names 
Watching for changes...
DEBU[0021] Change detected notify.Write: "/Users/tejaldesai/workspace/github-dashing/.idea/workspace.xml" 
TRAC[0022] Checking base image library/ruby:2.3.0 for ONBUILD triggers. 
DEBU[0022] Found dependencies for dockerfile: [{Gemfile /dashboard true} {. /dashboard false}] 
DEBU[0022] Skipping excluded path: .idea/vcs.xml        
DEBU[0022] Skipping excluded path: .idea/.gitignore     
DEBU[0022] Skipping excluded path: .idea/workspace.xml  
DEBU[0022] Skipping excluded path: .idea/modules.xml    
DEBU[0022] Skipping excluded path: .idea/github-dashing.iml 
DEBU[0022] Skipping excluded path: .idea/misc.xml       
INFO[0022] files modified: [assets/javascripts/application.coffee] 
TRAC[0022] Checking base image library/ruby:2.3.0 for ONBUILD triggers. 
DEBU[0022] Found dependencies for dockerfile: [{Gemfile /dashboard true} {. /dashboard false}] 
DEBU[0022] Skipping excluded path: .idea/vcs.xml        
DEBU[0022] Skipping excluded path: .idea/.gitignore     
DEBU[0022] Skipping excluded path: .idea/workspace.xml  
DEBU[0022] Skipping excluded path: .idea/modules.xml    
DEBU[0022] Skipping excluded path: .idea/github-dashing.iml 
DEBU[0022] Skipping excluded path: .idea/misc.xml       
Syncing 1 files for github-dash:0b1e6dbd6fc5ff49b703a553f8770cc1a72fef212d97a5b18f19cbe06762cb71
  1. Because i have COPY . /dashboard in my dockerfile, a rebuild happens when git object change
EBU[0335] Change detected notify.Write: "/Users/tejaldesai/workspace/github-dashing/.git/FETCH_HEAD" 
DEBU[0335] Change detected notify.Remove: "/Users/tejaldesai/workspace/github-dashing/.git/objects/maintenance.lock" 
DEBU[0335] Change detected notify.Create: "/Users/tejaldesai/workspace/github-dashing/.git/objects/maintenance.lock" 
TRAC[0336] Checking base image library/ruby:2.3.0 for ONBUILD triggers. 
DEBU[0336] Found dependencies for dockerfile: [{Gemfile /dashboard true} {. /dashboard false}] 
DEBU[0336] Skipping excluded path: .idea/vcs.xml        
DEBU[0336] Skipping excluded path: .idea/.gitignore     
DEBU[0336] Skipping excluded path: .idea/workspace.xml  
DEBU[0336] Skipping excluded path: .idea/modules.xml    
DEBU[0336] Skipping excluded path: .idea/github-dashing.iml 
DEBU[0336] Skipping excluded path: .idea/misc.xml       
INFO[0336] files modified: [.git/FETCH_HEAD]            
TRAC[0336] Checking base image library/ruby:2.3.0 for ONBUILD triggers. 
DEBU[0336] Found dependencies for dockerfile: [{Gemfile /dashboard true} {. /dashboard false}] 
DEBU[0336] Skipping excluded path: .idea/vcs.xml        
DEBU[0336] Skipping excluded path: .idea/.gitignore     
DEBU[0336] Skipping excluded path: .idea/workspace.xml  
DEBU[0336] Skipping excluded path: .idea/modules.xml    
DEBU[0336] Skipping excluded path: .idea/github-dashing.iml 
DEBU[0336] Skipping excluded path: .idea/misc.xml       
INFO[0336] Changed file .git/FETCH_HEAD does not match any sync pattern. Skipping sync 
Generating tags...

Expected: Infer rule 'assets/**/*' should not trigger rebuild.

  • .git/ folder objects
  • .idea/*
  • vscode config files.

Document or Warn users when Copy . is present in dockerfile and add following rules to dockerignore.

.idea/*
.git/*

Contributor guide