Avoid build everytime pushing code to local mode

On doing sudo balena push -s, docker-compose creates a build everytime although no changes have taken place in the Dockerfile or docker-compose.yml. Why is it happening?

There could be source code changes in files referenced in a Dockerfile. Is that the case?

@majorz yes but how do I avoid that?

@majorz My Dockerfile

FROM resin/raspberry-pi-node

COPY . /app


RUN npm install


CMD node /app/app.js

Does the contents of the /app/app.js file changes between the push operations you do?

@majorz /app/app.js is the first page to be executed and it includes a lot files from other folders which change often.

Right, the ones you copy over to the work dir. So anytime one of those files changes, the image will be rebuild from this point onward. That should be all normal. Or is there another issue you experience, as I may have misunderstood your question?

That is to say the RUN npm install will be executed each time something in the workdir changes. You can optimize this process for sure. Let me think for a bit.

@g_abhishek_agarwal you may move copying the package.json file before the npm install and then copy the rest of the files after the install. This will produce better results due to the caching mechanisms. Example here:

Yes @majorz. Got it. Doing npm install before copying the files to workdir does the build in less than 10 sec. Thank you so much.