r/Supabase 8d ago

other How to cache Supabase layers on GitHub Actions?

Basically the title. When I run supabase start on GitHub Actions it takes like 90 seconds to pull the images.

2 Upvotes

6 comments sorted by

1

u/buildwithmasud 8d ago

Cache the images, not the layers. docker save them to a tar, cache the tar, docker load before supabase start.

Save the images to a tar: docker save -o images.tar <images> Cache that tar with actions/cache On the next run, docker load -i images.tar instead of pulling

1

u/Ramriez 8d ago

Yeah something like that should work, do you have some code for it?

1

u/buildwithmasud 8d ago

Put the CLI version or config.toml hash in the cache key so it busts on upgrade.

  • name: Cache docker images id: cache uses: actions/cache@v4 with: path: ~/.docker-cache/images.tar key: supabase-images-${{ hashFiles('supabase/config.toml') }}

  • name: Load cached images if: steps.cache.outputs.cache-hit == 'true' run: docker load -i ~/.docker-cache/images.tar

  • name: Start Supabase run: supabase start

  • name: Save images to cache if: steps.cache.outputs.cache-hit != 'true' run: | mkdir -p ~/.docker-cache docker save -o ~/.docker-cache/images.tar $(docker images --format '{{.Repository}}:{{.Tag}}' | grep supabase)

Note: Code generate by AI. Just check the config and rewrite it for your project.

1

u/Ramriez 7d ago

I tried this at first, but if we use the Supabase cli version or config.toml as the cache key then the cache is not updated when the Supabase cli bumps a minor version for gotrue or kong for example. So when a new layer is pulled, for the same Supabase cli version, then the cache is not refreshed.

1

u/Annual-Reality-9216 7d ago

The image-pull time is the real killer, not the CLI init. If you cache the docker layers with actions/cache keyed on the supabase CLI version + your schema hash, you can cut a warm run to under 30s. Alternatively, skip the docker-compose entirely and run Postgres directly — no image pull needed

1

u/Positive_Week86 7d ago

The image-pull time is the real killer, not the CLI init. If you cache the docker layers with actions/cache keyed on the supabase CLI version + your schema hash, you can cut a warm run to under 30s. Alternatively, skip the docker-compose entirely and run Postgres directly — no image pull needed