How to cache Ruby gems with native extensions in container-based job?

I have this workflow which is based on this Docker image (Dockerfile). I’m trying to figure out how to do caching for the Ruby gems.

As you can see from my Actions screenshot above, some Ruby gems didn’t respect the Bundler cache environment variables and always trying to install the gems (see lines with Installing prefix at line 523 & 524). They are gems with native extensions.

Gems without the native extensions were loaded fine from the cache (see lines with Using prefix).

In contrast, I didn’t get this issue when using VM-based job. See this screenshot:

As you can see from VM-based job above, the bcrypt gem (line 51) was loaded from the cache. This is what I want in my container-based job but I’m stucked to move forward.

What I did wrong here? What should I change on my workflow or Dockerfile to make sure all gems are installed and loaded from the cache, regardless they are or are not native extension gems.

I forked your repo to my account, I run the job with container workflow two times, the first oneshows Cache saved successfully  . In the second time I run the workflow, it shows that all gems are from cache. Include those with native extensions.


Please check your logs . Have you saved bcrypt ,nio4r into your cache before using it ?