Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache npm packages in Docker GitHub actions

I actually have GitHub actions that tests a nodeJS project in a Docker image (node:16-alpine). My problem is that at each run, yarn install re-installed completely all the packages. My question is: how can I cache these packages between runs ?

I've trouble doing it since the execution run in the Docker image and I could not find a solution to cache the packages. Thank you for your help!

like image 528
Bastien Faivre Avatar asked Jul 02 '26 08:07

Bastien Faivre


2 Answers

You can use dockerCache , using that you will be use your github action cache in the respective docker build.

like image 65
Junip Dewan Avatar answered Jul 04 '26 23:07

Junip Dewan


You can use github actions cache to cache things inside your job.

If you're using a docker image separately from your job, probably you can't cache that. My suggestion, improve your workflow if you create a job for a test and need the same environment put it all in just one job with different steps.

like image 22
fguisso Avatar answered Jul 04 '26 23:07

fguisso