nareshbhatia / proshop-nx

Sample shopping app using the Nx monorepo
proshop-nx-catalog.vercel.app
2 stars 0 forks source link

Better utilise Docker Image building cache #4

Open themegaphoenix opened 2 years ago

themegaphoenix commented 2 years ago

Normally when developing, the requirements tend to be static- the package.json doesn't change, but the files do.

Docker images are made up of layers, and hence we can utilise cache to help speed up the building process.

By first copying the package.json and then do RUN npm install -g nx RUN npm install
COPY . .
RUN nx build proshop-api --configuration=production

It can become 5 different layers. So when the React application code changes, but not the requirements, Docker will use the cache of the first 3 layers and only run the 5th and 6th step, saving time when building the docker image

More info https://levelup.gitconnected.com/easy-optimization-of-your-react-docker-image-down-to-22mb-9d9e3a06870 https://tiangolo.medium.com/react-in-docker-with-nginx-built-with-multi-stage-docker-builds-including-testing-8cc49d6ec305

nareshbhatia commented 2 years ago

Wow! Thank you for a thorough code review and these useful pointers. Will give it a shot.