grammarly / rocker

Rocker breaks the limits of Dockerfile.
Other
1.34k stars 88 forks source link

Help understanding caching logic #164

Closed withinboredom closed 7 years ago

withinboredom commented 7 years ago

Here's an excerpt of the build log:

INFO[0000] FROM node:latest                  
INFO[0001] | Pull image node:latest                     
latest: Pulling from library/node
Digest: sha256:d63c3b05c7fc033b55698dce010922f6714ba44949521ddf5ab6bd69f22180b5
Status: Image is up to date for node:latest
INFO[0002] | Image sha256:d1699                          size=659.8 MB
INFO[0002] RUN npm install -g yarn           
INFO[0003] | Cached! Take image sha256:ad246    size=688.4 MB (+28.62 MB)
INFO[0003] PUSH quay.io/withinboredom/yarn:0 
INFO[0003] | Tag sha256:ad246 -> quay.io/withinboredom/yarn:0 
INFO[0003] | Don't push. Pass --push flag to actually push to the registry 
INFO[0003] PUSH quay.io/withinboredom/yarn:latest 
INFO[0003] | Tag sha256:ad246 -> quay.io/withinboredom/yarn:latest 
INFO[0003] | Don't push. Pass --push flag to actually push to the registry 
INFO[0003] COPY ./src/site /app              
INFO[0003] | Calculating tarsum for 36 files (4.837 MB total) 
INFO[0003] | Cached! Take image sha256:f454f    size=693.2 MB (+4.837 MB)
INFO[0003] RUN cd /app/js && yarn && NODE_ENV=production node_modules/.bin/webpack -p && rm -rf /app/js 
INFO[0003] | Not cached                        
INFO[0003] | Created container 9e1970788a74 (image sha256:f454f) 

Either the last COPY or the last RUN command will return Not cached even if no files change. This makes no sense to me. If everything before a RUN is cached, why wasn't the RUN cached?

ctrlok commented 7 years ago

@withinboredom I can't reproduce it.

☁  tmp3  rocker build
INFO[0000] FROM ubuntu
INFO[0000] | Image sha256:104be                          size=129 MB
INFO[0000] RUN apt-get update
INFO[0000] | Cached! Take image sha256:ba269    size=168.4 MB (+39.49 MB)
INFO[0000] COPY ./dir /dir
INFO[0000] | Calculating tarsum for 1 files (0 B total)
INFO[0000] | Not cached
INFO[0000] | Created container 9e3cb241f2be (image sha256:ba269)
INFO[0000] | Uploading files to container 9e3cb241f2be
INFO[0000] Commit changes
INFO[0000] | Result image is sha256:6b813                size=168.4 MB (+0 B)
INFO[0000] | Removing container 9e3cb241f2be
INFO[0000] RUN apt-get update
INFO[0001] | Created container 1079e3f40cc6 (image sha256:6b813)
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates/main Sources [268 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [144 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [568 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [469 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial-security/main Sources [64.9 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial-security/universe Sources [17.2 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial-security/main amd64 Packages [245 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [80.1 kB]
Fetched 2061 kB in 1s (1898 kB/s)
Reading package lists...
INFO[0004] Commit changes
INFO[0004] | Result image is sha256:8f000                size=171.9 MB (+3.449 MB)
INFO[0004] | Removing container 1079e3f40cc6
INFO[0004] Cleaning up
INFO[0004] Successfully built sha256:8f000 | final size 171.9 MB (+42.94 MB from the base image)

☁  tmp3  rocker build
INFO[0000] FROM ubuntu
INFO[0000] | Image sha256:104be                          size=129 MB
INFO[0000] RUN apt-get update
INFO[0000] | Cached! Take image sha256:ba269    size=168.4 MB (+39.49 MB)
INFO[0000] COPY ./dir /dir
INFO[0000] | Calculating tarsum for 1 files (0 B total)
INFO[0000] | Cached! Take image sha256:6b813    size=168.4 MB (+0 B)
INFO[0000] RUN apt-get update
INFO[0000] | Cached! Take image sha256:8f000    size=171.9 MB (+3.449 MB)
INFO[0000] Cleaning up
INFO[0000] Successfully built sha256:8f000 | final size 171.9 MB (+42.94 MB from the base image)

Are you sure, you didn't change anything in last command before run? (RUN cd /app/js && yarn && NODE_ENV=production node_modules/.bin/webpack -p && rm -rf /app/js)