Spin up a local Github artifact cache server to be used with act Github actions that uses actions/cache
# export env
export ACT_CACHE_AUTH_KEY=foo
# build image and start a container(listen 8080 port)
docker compose up --build
We need to let act to know the Cache Server URL and use which token. There are two ways to do so (choose one).
- Ensure you add the following configuration to your
~/.actrc
file:
--env ACTIONS_CACHE_URL=http://localhost:8080/
--env ACTIONS_RUNTIME_URL=http://localhost:8080/
--env ACTIONS_RUNTIME_TOKEN=foo
# just run act
act {event}
- Run act with env file (for example, put the file in project root)
# ./act/cache.env
ACTIONS_CACHE_URL=http://localhost:8080/
ACTIONS_RUNTIME_URL=http://localhost:8080/
ACTIONS_RUNTIME_TOKEN=foo
# run act with .env file
act {event} --env-file act/cache.env
- You can set
ACT_CACHE_AUTH_KEY
andACTIONS_RUNTIME_TOKEN
to the value you want, but they must be the same - The cache is persisted in Docker's named volumes(when using
docker-compose
) so it will survive between containers - To purge the cache use the endpoint
/_apis/artifactcache/clean
. ie
curl -X POST -H 'Authorization: Bearer foo' 'http://localhost:8080/_apis/artifactcache/clean'
- The caching is global, meaning that it's shared across git projects and branches. As the container lacks the information of the Github context the action is running on it does not have access to
GITHUB_REPOSITORY
,GITHUB_REF
orGITHUB_BASE_REF
so it can do a better job restoring fallback caches or switching branches
- This project started off the awesome https://github.com/anthonykawa/artifact-server and https://github.com/JEFuller/artifact-server (with docker support).