Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-hosted runners cache not working when using service containers #1021

Open
omri-shilton opened this issue Jan 27, 2025 · 5 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@omri-shilton
Copy link

Description:
Running on self hosted runner using the following: https://github.com/github-aws-runners/terraform-aws-github-runner
I have a workflow that has multiple jobs, some are regular and some have service containers ie:

  Job-A:
    runs-on: [self-hosted, linux, x64, ubuntu-latest]
    steps:
      - name: Check out repository code 🕵🏻‍♀️
        uses: actions/checkout@v4

      - uses: actions/setup-python@v4
        with:
          python-version: '3.10.10'
          cache: 'pip'

      - name: Run Mypy
        run: |
          pip install -r backend/requirements/linter-requirements.txt
          mypy --config backend/mypy.ini backend


  Job-B:
    runs-on: [self-hosted, linux, x64, ubuntu-latest]
    services:
      postgresql:
        image: somerepo/someimage:latest
        ports:
          - 5432:5432
        env:
          SOME_VAR: SOMEVAR
        credentials:
          username: someuser
          password: somepass
    steps:
      - name: Check out repository code 🕵🏻‍♀️
        uses: actions/checkout@v4

      - uses: actions/setup-python@v4
        with:
          python-version: '3.10.10'
          cache: 'pip'

      - name: Install newly added packages
        run: |
          pip install -r backend/requirements/requirements.txt
          pip install -r backend/requirements/dev-requirements.txt
          pip install psycopg2-binary==2.9.9

On the job that don't have service containers i'm getting these logs:
Image
you can see that the cache is found and then using the cached packages.

On the job that has service containers i'm getting these logs:
Image
you can see that the cache is found and then still downloading the packages instead of using the cache.

When I log into the machine that ran the second job i can see that .cache/pip/ folder has many packages.

Action version:
4

Platform:

  • Ubuntu

Runner type:

  • Self-hosted - version 2.322.0

Tools version:

3.10.10

Repro steps:
copy the workflow jobs that I listed and fill in some real data.

Expected behavior:
Cache to be used on both jobs.

Actual behavior:
cache is working only on jobs without service containers.

@omri-shilton omri-shilton added bug Something isn't working needs triage labels Jan 27, 2025
@mahabaleshwars
Copy link

Hi @omri-shilton,
Thank you for creating this issue. We will investigate it and provide feedback as soon as we have some updates.

@priyagupta108
Copy link
Contributor

Hi @omri-shilton,
If you use separate files to define dependencies for different jobs (e.g., Job-A and Job-B), please utilize the cache-dependency-path input to specify paths for different files to generate separate cache for them. This ensures that the caching mechanism correctly identifies and utilizes the appropriate dependency files for each job.

  • For Job-A, you can use the following configuration:

    - uses: actions/setup-python@v5
      with:
        python-version: '3.10.10'
        cache: 'pip'
        cache-dependency-path: backend/requirements/linter-requirements.txt
    
  • For Job-B, you can use this configuration:

    - uses: actions/setup-python@v5
      with:
         python-version: '3.10.10'
         cache: 'pip'
         cache-dependency-path: |
             backend/requirements/requirements.txt
             backend/requirements/dev-requirements.txt
    

Additionally, it is recommended to delete the existing cache before running with cache-dependency-path to avoid any cache conflicts.
Please note that actions/setup-python@v4 also works fine with this configuration. However, it is advisable to use the latest tag (v5), as it ensures that you are utilizing the most recent features, improvements, and security patches.

Thank you!

@omri-shilton
Copy link
Author

@priyagupta108 ill try that now, but this only happend to me after I changed to ec2 self hosted runners rather than my old EKS action controller runners. got any idea why?

@priyagupta108
Copy link
Contributor

Hi @omri-shilton 👋,
It's possible that the EKS action controller runners had existing caches, which might be why you did not encounter this issue earlier. This behavior is expected when using separate files to define different dependencies.
To address this, I would suggest to use cache-dependency-path to specify paths for different files to generate separate cache for them.

@priyagupta108
Copy link
Contributor

@omri-shilton 👋,
Just checking in to see if there are any updates on your end regarding this issue? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants