setup-java download jdk binary again every time due to not cache tool folder #70

Closed
opened 2023-03-23 13:42:54 +00:00 by seepine · 9 comments
Contributor

And github runner can cache container toolcache folder
https://github.com/actions/setup-java/issues/470#issuecomment-1480814653

And github runner can cache container `toolcache` folder https://github.com/actions/setup-java/issues/470#issuecomment-1480814653
wolfogre added the
kind
bug
label 2023-03-24 01:39:40 +00:00
Member

The runner mounts the act-toolcache volume to /toolcache directory (See

"act-toolcache": "/toolcache",
)

In my test, the files created by a task will remain in the volume even after the task has finished. If I rerun the task, the file will still be there. The workflow is like:

jobs:
  write-test:
    runs-on: ubuntu-latest
    steps:
      - name: Write
        run: 'echo $GITHUB_SHA >> /toolcache/sha.txt'

      - name: Read
        run: 'cat /toolcache/sha.txt'

I also test thesetup-java action. But it is strange that the setup-java action doesn't seem to write data to the /toolcache directory. I'll test other actions to check if they cache files there.

The runner mounts the `act-toolcache` volume to `/toolcache` directory (See https://gitea.com/gitea/act/src/commit/342ad6a51a1a25b6f3c6e75df3f36efc3806e7e7/pkg/runner/run_context.go#L108) In my test, the files created by a task will remain in the volume even after the task has finished. If I rerun the task, the file will still be there. The workflow is like: ``` yml jobs: write-test: runs-on: ubuntu-latest steps: - name: Write run: 'echo $GITHUB_SHA >> /toolcache/sha.txt' - name: Read run: 'cat /toolcache/sha.txt' ``` I also test the`setup-java` action. But it is strange that the `setup-java` action doesn't seem to write data to the `/toolcache` directory. I'll test other actions to check if they cache files there.
Member

At present, the act-toolcache volume is mounted to /toolcache and the data in /toolcache will be stored persistently. But the problem is that actions don't write data to /toolcache but to /opt/hostedtoolcache (specified by the RUNNER_TOOL_CACHE env, see

envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/opt/hostedtoolcache"))
)

Maybe we need to support users to configure the volumes that will be mounted to RUNNER_TOOL_CACHE. Now there is a workaround: set the RUNNER_TOOL_CACHE env manually in the workflow, like this:

jobs:
  build:
    env:
      RUNNER_TOOL_CACHE: /toolcache
...
At present, the `act-toolcache` volume is mounted to `/toolcache` and the data in `/toolcache` will be stored persistently. But the problem is that actions don't write data to `/toolcache` but to `/opt/hostedtoolcache` (specified by the `RUNNER_TOOL_CACHE` env, see https://gitea.com/gitea/act/src/commit/cfedc518ca02fd1aa395ad028a1b369f1ce2e5ed/pkg/runner/run_context.go#L236) Maybe we need to support users to configure the volumes that will be mounted to `RUNNER_TOOL_CACHE`. Now there is a workaround: set the `RUNNER_TOOL_CACHE` env manually in the workflow, like this: ``` yml jobs: build: env: RUNNER_TOOL_CACHE: /toolcache ... ```
Member

My test:

First run (no cache):
7ebc385d5e97c2d5578bfd771be458d

Second run (get from cache):
2c358151b2402ec11879f7782f404f1

act-toolcache volume:
image

My test: First run (no cache): ![7ebc385d5e97c2d5578bfd771be458d](/attachments/c8304749-6288-4120-acd9-fd5b77bf70a6) Second run (get from cache): ![2c358151b2402ec11879f7782f404f1](/attachments/92ffed6f-9374-450b-b607-648d71ce8358) `act-toolcache` volume: ![image](/attachments/727bd5ce-47ad-45d1-9c0b-64b8ca05c349)
Author
Contributor

@Zettat123 hi, i found some issues when setup with cache

it can be run fast about 0s without cache: pnpm, but it take time when with cache: pnpm

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      RUNNER_TOOL_CACHE: /toolcache
    setps:
      - name: Setup Pnpm
        uses: pnpm/action-setup@v2
        with:
          version: 8

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: 'pnpm'

      - run: pnpm -v
      - run: pnpm install

image
image

My runner in docker of persistence

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - act_data:/data
      - act_cache:/root/.cache

Do you know what the problem is?

@Zettat123 hi, i found some issues when setup with `cache` it can be run fast about `0s` without `cache: pnpm`, but it take time when with `cache: pnpm` ```yml jobs: build: runs-on: ubuntu-latest env: RUNNER_TOOL_CACHE: /toolcache setps: - name: Setup Pnpm uses: pnpm/action-setup@v2 with: version: 8 - name: Setup Node uses: actions/setup-node@v3 with: node-version: 16 cache: 'pnpm' - run: pnpm -v - run: pnpm install ``` ![image](/attachments/ab2c93f8-9a61-4ff9-9113-2d463796e22d) ![image](/attachments/32625ef7-e91a-4237-a624-3d16c652c70d) My runner in docker of persistence ``` volumes: - /var/run/docker.sock:/var/run/docker.sock - act_data:/data - act_cache:/root/.cache ``` Do you know what the problem is?
Member

@Zettat123 hi, i found some issues when setup with cache

it can be run fast about 0s without cache: pnpm, but it take time when with cache: pnpm

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      RUNNER_TOOL_CACHE: /toolcache
    setps:
      - name: Setup Pnpm
        uses: pnpm/action-setup@v2
        with:
          version: 8

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: 'pnpm'

      - run: pnpm -v
      - run: pnpm install

image
image

My runner in docker of persistence

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - act_data:/data
      - act_cache:/root/.cache

Do you know what the problem is?

It looks like the job container cannot access the cache server. What's your act_runner version? Are you using docker-compose to run your act_runner?

> @Zettat123 hi, i found some issues when setup with `cache` > > it can be run fast about `0s` without `cache: pnpm`, but it take time when with `cache: pnpm` > ```yml > jobs: > build: > runs-on: ubuntu-latest > env: > RUNNER_TOOL_CACHE: /toolcache > setps: > - name: Setup Pnpm > uses: pnpm/action-setup@v2 > with: > version: 8 > > - name: Setup Node > uses: actions/setup-node@v3 > with: > node-version: 16 > cache: 'pnpm' > > - run: pnpm -v > - run: pnpm install > ``` > > ![image](/attachments/ab2c93f8-9a61-4ff9-9113-2d463796e22d) > ![image](/attachments/32625ef7-e91a-4237-a624-3d16c652c70d) > > My runner in docker of persistence > ``` > volumes: > - /var/run/docker.sock:/var/run/docker.sock > - act_data:/data > - act_cache:/root/.cache > ``` > > Do you know what the problem is? It looks like the job container cannot access the cache server. What's your act_runner version? Are you using docker-compose to run your act_runner?
Author
Contributor

@Zettat123
Act_runner run with docker compose, and latest version

version: "3"
services:
  act_runner:
    image: gitea/act_runner
    environment:
      - GITEA_RUNNER_NAME=docker_act_runner
      - GITEA_INSTANCE_URL=http://192.168.100.100:3000/
      - GITEA_RUNNER_REGISTRATION_TOKEN=xxx
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /act_data/data:/data
      - /act_data/cache:/root/.cache

It maybe cache probrem

image

This is mini demo
https://gitea.com/seepine/action-demo

@Zettat123 Act_runner run with docker compose, and latest version ```yml version: "3" services: act_runner: image: gitea/act_runner environment: - GITEA_RUNNER_NAME=docker_act_runner - GITEA_INSTANCE_URL=http://192.168.100.100:3000/ - GITEA_RUNNER_REGISTRATION_TOKEN=xxx volumes: - /var/run/docker.sock:/var/run/docker.sock - /act_data/data:/data - /act_data/cache:/root/.cache ``` It maybe cache probrem ![image](/attachments/f99f71c0-fdb6-4243-8f5d-94d73e6acf41) This is mini demo https://gitea.com/seepine/action-demo
144 KiB
Author
Contributor

And Compele job also

image

And Compele job also ![image](/attachments/37a1605c-1ad9-4eb6-82be-8221d6c1b294)
196 KiB
Member

It maybe cache probrem

Yes, this issue is related to the cache handler. There is a workaround in the documentation, and we will improve the cache handler to avoid similar issues.

> It maybe cache probrem Yes, this issue is related to the cache handler. There is a workaround in the [documentation](https://docs.gitea.com/1.20/usage/actions/act-runner#configuring-cache-when-starting-a-runner-using-docker-image), and we will improve the cache handler to avoid similar issues.
Author
Contributor

Thanks, it can be work

cache:
  # 使用步骤 1. 获取的 LAN IP
  host: "192.168.8.17"
  # 使用步骤 2. 获取的端口号
  port: 8088
Thanks, it can be work ```yml cache: # 使用步骤 1. 获取的 LAN IP host: "192.168.8.17" # 使用步骤 2. 获取的端口号 port: 8088 ```
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: gitea/act_runner#70
No description provided.