Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile builds only caching up to first COPY #3631

Closed
ghost opened this issue Aug 2, 2019 · 2 comments
Closed

Dockerfile builds only caching up to first COPY #3631

ghost opened this issue Aug 2, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 2, 2019

Description of problem

In a multi-stage Dockerfile build, steps are only cached up until the first COPY command in the first stage.

How reproducible

This happens every time I deploy.

Steps to Reproduce

  1. Use the Dockerfile attached at the bottom of this issue
  2. Make a change that only touches e.g. the README
  3. See Docker rebuild the app instead of using the cache

Actual Results

remote: Step 1/27 : FROM elixir:1.9.0-alpine as build        
remote:  ---> 7a6d28e4b511        
remote: Step 2/27 : RUN apk add --update git build-base        
remote:  ---> Using cache        
remote:  ---> 11da61788331        
remote: Step 3/27 : RUN mkdir /app        
remote:  ---> Using cache        
remote:  ---> 2a0fd2bc9f5c        
remote: Step 4/27 : WORKDIR /app        
remote:  ---> Using cache        
remote:  ---> 876adb368066        
remote: Step 5/27 : RUN mix local.hex --force &&   mix local.rebar --force        
remote:  ---> Using cache        
remote:  ---> eb75832955a0        
remote: Step 6/27 : ENV MIX_ENV=prod        
remote:  ---> Using cache        
remote:  ---> 3bc485b4dc82        
remote: Step 7/27 : COPY mix.exs ./        
remote:  ---> c51daa672e0f        
<snip>     

Expected Results

Docker uses the build cache when the copied file has not changed.

Environment Information

dokku report APP_NAME output

-----> uname: Linux fediverse 4.19.0-5-cloud-amd64 #1 SMP Debian 4.19.37-5 (2019-06-19) x86_64 GNU/Linux
-----> memory: 
                     total        used        free      shared  buff/cache   available
       Mem:           3949        2291         260         182        1397        1252
       Swap:             0           0           0
-----> docker version: 
       Client:
        Version:           18.09.7
        API version:       1.39
        Go version:        go1.10.8
        Git commit:        2d0083d
        Built:             Thu Jun 27 17:56:40 2019
        OS/Arch:           linux/amd64
        Experimental:      false
       
       Server: Docker Engine - Community
        Engine:
         Version:          18.09.7
         API version:      1.39 (minimum version 1.12)
         Go version:       go1.10.8
         Git commit:       2d0083d
         Built:            Thu Jun 27 17:23:02 2019
         OS/Arch:          linux/amd64
         Experimental:     false
-----> docker daemon info: 
WARNING: No swap limit support
       Containers: 8
        Running: 3
        Paused: 0
        Stopped: 5
       Images: 73
       Server Version: 18.09.7
       Storage Driver: overlay2
        Backing Filesystem: extfs
        Supports d_type: true
        Native Overlay Diff: true
       Logging Driver: json-file
       Cgroup Driver: cgroupfs
       Plugins:
        Volume: local
        Network: bridge host macvlan null overlay
        Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
       Swarm: inactive
       Runtimes: runc
       Default Runtime: runc
       Init Binary: docker-init
       containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
       runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
       init version: fec3683
       Security Options:
        apparmor
        seccomp
         Profile: default
       Kernel Version: 4.19.0-5-cloud-amd64
       Operating System: Debian GNU/Linux 10 (buster)
       OSType: linux
       Architecture: x86_64
       CPUs: 2
       Total Memory: 3.857GiB
       Name: fediverse
       ID: XNSD:LWIL:YHCJ:23ZK:RD6B:UXXC:F3PE:BDVR:AR46:QARS:56UH:EVN4
       Docker Root Dir: /var/lib/docker
       Debug Mode (client): true
       Debug Mode (server): false
       Registry: https://index.docker.io/v1/
       Labels:
       Experimental: false
       Insecure Registries:
        127.0.0.0/8
       Live Restore Enabled: false
       Product License: Community Engine
       
-----> sigil version: 0.4.0
-----> herokuish version: 
       herokuish: 0.5.0
       buildpacks:
         heroku-buildpack-multi     v1.0.0
         heroku-buildpack-ruby      v200
         heroku-buildpack-nodejs    v142
         heroku-buildpack-clojure   v83
         heroku-buildpack-python    v149
         heroku-buildpack-java      v63
         heroku-buildpack-gradle    v28
         heroku-buildpack-scala     v84
         heroku-buildpack-play      v26
         heroku-buildpack-php       v151
         heroku-buildpack-go        v104
         buildpack-nginx            v10
-----> dokku version: dokku version 0.17.9
-----> dokku plugins: 
       plugn: 0.3.2
         00_dokku-standard    0.17.9 enabled    dokku core standard plugin
         20_events            0.17.9 enabled    dokku core events logging plugin
         app-json             0.17.9 enabled    dokku core app-json plugin
         apps                 0.17.9 enabled    dokku core apps plugin
         build-env            0.17.9 enabled    dokku core build-env plugin
         buildpacks           0.17.9 enabled    dokku core buildpacks plugin
         certs                0.17.9 enabled    dokku core certificate management plugin
         checks               0.17.9 enabled    dokku core checks plugin
         common               0.17.9 enabled    dokku core common plugin
         config               0.17.9 enabled    dokku core config plugin
         docker-options       0.17.9 enabled    dokku core docker-options plugin
         domains              0.17.9 enabled    dokku core domains plugin
         elasticsearch        1.9.0 enabled    dokku elasticsearch service plugin
         enter                0.17.9 enabled    dokku core enter plugin
         git                  0.17.9 enabled    dokku core git plugin
         letsencrypt          0.8.9 enabled    Automated installation of let's encrypt TLS certificates
         logs                 0.17.9 enabled    dokku core logs plugin
         monorepo             0.1.0 enabled    Deploy all apps from a monorepo.
         network              0.17.9 enabled    dokku core network plugin
         nginx-vhosts         0.17.9 enabled    dokku core nginx-vhosts plugin
         plugin               0.17.9 enabled    dokku core plugin plugin
         postgres             1.8.1 enabled    dokku postgres service plugin
         proxy                0.17.9 enabled    dokku core proxy plugin
         ps                   0.17.9 enabled    dokku core ps plugin
         repo                 0.17.9 enabled    dokku core repo plugin
         resource             0.17.9 enabled    dokku core resource plugin
         scheduler-docker-local 0.17.9 enabled    dokku core scheduler-docker-local plugin
         shell                0.17.9 enabled    dokku core shell plugin
         ssh-keys             0.17.9 enabled    dokku core ssh-keys plugin
         storage              0.17.9 enabled    dokku core storage plugin
         tags                 0.17.9 enabled    dokku core tags plugin
         tar                  0.17.9 enabled    dokku core tar plugin
         trace                0.17.9 enabled    dokku core trace plugin
=====> phoenix app information
       App dir:                       /home/dokku/phoenix      
       Git sha:                       d53d42b                  
       Deploy source:                 git                      
       Locked:                        true                     
=====> phoenix buildpacks information
       Buildpacks list:               
CN = phoenix.api-develop.fediverse.space
error 20 at 0 depth lookup: unable to get local issuer certificate
=====> phoenix ssl information
       Ssl dir:                       /home/dokku/phoenix/tls  
       Ssl enabled:                   true                     
       Ssl hostnames:                 phoenix.api-develop.fediverse.space
       Ssl expires at:                Oct 15 14:53:57 2019 GMT 
       Ssl issuer:                    C = US, O = Lets Encrypt, CN = Lets Encrypt Authority X3
       Ssl starts at:                 Jul 17 14:53:57 2019 GMT 
       Ssl subject:                   subject=CN = phoenix.api-develop.fediverse.space
       Ssl verified:                  self signed              
=====> phoenix checks information
       Checks disabled list:          none                     
       Checks skipped list:           none                     
=====> phoenix docker options information
       Docker options build:          --link dokku.elasticsearch.fediverse:dokku-elasticsearch-fediverse --link dokku.postgres.fediversedb:dokku-postgres-fediversedb 
       Docker options deploy:         --link dokku.elasticsearch.fediverse:dokku-elasticsearch-fediverse --link dokku.postgres.fediversedb:dokku-postgres-fediversedb --restart=on-failure:10 
       Docker options run:            --link dokku.elasticsearch.fediverse:dokku-elasticsearch-fediverse --link dokku.postgres.fediversedb:dokku-postgres-fediversedb 
=====> phoenix domains information
       Domains app enabled:           true                     
       Domains app vhosts:            phoenix.api-develop.fediverse.space
       Domains global enabled:        true                     
       Domains global vhosts:         api-develop.fediverse.space
=====> phoenix git information
       Git rev env var:               GIT_REV                  
       Git deploy branch:             master                   
       Git global deploy branch:      develop                  
=====> phoenix network information
       Network bind all interfaces:   false
       Network listeners:             172.17.0.4:5000
=====> phoenix proxy information
       Proxy enabled:                 true                     
       Proxy type:                    nginx                    
       Proxy port map:                http:80:5000 https:443:5000
=====> phoenix ps information
       Processes:                     1                        
       Deployed:                      true                     
       Running:                       true                     
       Restore:                       true                     
       Restart policy:                on-failure:10            
       Ps can scale:                  true                     
       Status web.1:                  running    (CID: 2bb4a5fb6cba)
=====> phoenix scheduler-docker-local information
       Scheduler docker local disable chown:                          
=====> phoenix storage information
       Storage build mounts:                                   
       Storage deploy mounts:                                  
       Storage run mounts:                                     

How (deb/make/rpm) and where (AWS, VirtualBox, physical, etc.) was Dokku installed?:

Debian 10 VPS, installed through the Dokku apt repo.

Additional information

FROM elixir:1.9.0-alpine as build

# install build dependencies
RUN apk add --update git build-base

# prepare build dir
RUN mkdir /app
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
  mix local.rebar --force

# set build ENV
ENV MIX_ENV=prod

# install mix dependencies
COPY mix.exs ./
COPY mix.lock ./
COPY config config
RUN mix deps.get
RUN mix deps.compile

# build assets
# COPY assets assets
# RUN cd assets && npm install && npm run deploy
# RUN mix phx.digest

# build project
COPY priv priv
COPY lib lib
RUN mix compile

# build release
COPY rel rel
RUN mix release

# prepare release image
FROM alpine:3.9 AS app
RUN apk add --update bash openssl

RUN mkdir /app
WORKDIR /app

ENV APP_NAME=backend

COPY --from=build /app/_build/prod/rel/${APP_NAME} ./
COPY Procfile ./
RUN chown -R nobody: /app
USER nobody

ENV HOME=/app

# The command to start the backend
CMD trap 'exit' INT; ${HOME}/bin/${APP_NAME} start

@josegonzalez
Copy link
Member

Do you mind retrying now with Dokku 0.18.1 and seeing what the outcome of the build process is?

@ghost
Copy link
Author

ghost commented Aug 15, 2019

Yes! I tried on 0.18.2 and now caching works as expected. Thank you for the help!

@ghost ghost closed this as completed Aug 15, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant