falcondev-oss / github-actions-cache-server

Self-hosted GitHub Actions cache server implementation. Compatible with official 'actions/cache' action
https://gha-cache-server.falcondev.io
MIT License
92 stars 4 forks source link

Failed to restore: getCacheEntry failed: getaddrinfo ENOTFOUND cache-server #38

Closed Edvinas01 closed 2 months ago

Edvinas01 commented 2 months ago

Issue

I'm trying to Dockerize my GitHub actions runner and github-actions-cache-server so I could scale it easier. When running the cache action, I'm encountering getaddrinfo ENOTFOUND cache-server warning which results in cache restoration/creation not working:

Run actions/cache@v3
  with:
    path: Library
    key: Library-Android-ecc5f7bcf2e73f875061940849f0b77aa1e0d2198803057608362414fee6cf58
    restore-keys: Library-Android-

    enableCrossOsArchive: false
    fail-on-cache-miss: false
    lookup-only: false
  env:
    ACTIONS_CACHE_URL: http://cache-server:3000/SOME_TOKEN/

Warning: Failed to restore: getCacheEntry failed: getaddrinfo ENOTFOUND cache-server
Cache not found for input keys: Library-Android-ecc5f7bcf2e73f875061940849f0b77aa1e0d2198803057608362414fee6cf58, Library-Android-

If I try to execute curl "${ACTIONS_CACHE_URL}" in my actions, I get a valid response.

Details

Here is my runner Dockerfile:

FROM ubuntu:22.04

ARG RUNNER_VERSION="2.316.1"

# Core dependencies.
RUN apt-get update -y && apt-get upgrade -y

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
  curl \
  wget \
  jq \
  git \
  git-lfs \
  build-essential \
  libssl-dev \
  libffi-dev \
  python3 \
  python3-venv \
  python3-dev \
  python3-pip

RUN useradd -m docker

# Setup runner.
RUN cd /home/docker \
  && mkdir actions-runner \
  && cd actions-runner \
  && curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \
  && tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz

RUN chown -R docker ~docker && ./home/docker/actions-runner/bin/installdependencies.sh

# Setup caching, for more info see: https://gha-cache-server.falcondev.io/getting-started#docker
RUN sed -i \
  's/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x55\x00\x52\x00\x4C\x00/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x4F\x00\x52\x00\x4C\x00/g' \
  /home/docker/actions-runner/bin/Runner.Worker.dll

# Prepare entry point.
COPY start.sh start.sh

RUN chmod +x start.sh

USER docker

ENTRYPOINT ["./start.sh"]

The Docker compose file:

services:
  cache-server:
    image: ghcr.io/falcondev-oss/github-actions-cache-server:2.1.2
    ports:
      - '3000:3000'
    environment:
      CLEANUP_OLDER_THAN_DAYS: 30
      URL_ACCESS_TOKEN: SOME_TOKEN
      API_BASE_URL: http://localhost:3000
    volumes:
      - cache-data:/app/.data

  actions-runner:
    build:
      context: actions-runner
      args:
        RUNNER_VERSION: 2.316.1
    environment:
      - GITHUB_ORG=SOME_ORG
      - ACTIONS_CACHE_URL=http://cache-server:3000/SOME_TOKEN/
      - RUNNER_LABELS=self-hosted,docker,linux,x64
      - RUNNER_GROUP=Custom
      - RUNNER_NAME=docker-actions-runner
    env_file:
      - '.actions-runner.secrets.env'

volumes:
  cache-data:

Other

I've tried the solution mentioned in https://github.com/falcondev-oss/github-actions-cache-server/issues/18 (setting API_BASE_URL: http://localhost:3000 to API_BASE_URL: http://cache-server:3000 if I understood it correctly), however it did not yield any results.

I've also tried removing the scheme from ACTIONS_CACHE_URL (ACTIONS_CACHE_URL: cache-server:3000/SOME_TOKEN/), this resulted in the following error:

Warning: Failed to restore: getCacheEntry failed: connect ECONNREFUSED 127.0.0.1:80
Cache not found for input keys: Library-Android-ecc5f7bcf2e73f875061940849f0b77aa1e0d2198803057608362414fee6cf58, Library-Android-
LouisHaftmann commented 2 months ago

I think the runner and cache server need to be in the same docker network. Maybe try this:

services:
  cache-server:
    image: ghcr.io/falcondev-oss/github-actions-cache-server:2.1.2
    ports:
      - '3000:3000'
    environment:
      CLEANUP_OLDER_THAN_DAYS: 30
      URL_ACCESS_TOKEN: SOME_TOKEN
      # this should also be updated
      API_BASE_URL: http://cache-server:3000
    volumes:
      - cache-data:/app/.data
    # add network
    networks:
      - default

  actions-runner:
    build:
      context: actions-runner
      args:
        RUNNER_VERSION: 2.316.1
    environment:
      - GITHUB_ORG=SOME_ORG
      - ACTIONS_CACHE_URL=http://cache-server:3000/SOME_TOKEN/
      - RUNNER_LABELS=self-hosted,docker,linux,x64
      - RUNNER_GROUP=Custom
      - RUNNER_NAME=docker-actions-runner
    env_file:
      - '.actions-runner.secrets.env'
    # add network
    networks:
      - default

volumes:
  cache-data:

# add network
networks:
  default:
Edvinas01 commented 2 months ago

Ugh, I feel dumb 😅 The job in my workflow was using another self-hosted runner, due to which it was unable to reach the one running locally on my machine - essentially some jobs ran on the cloud (self-hosted) while some on my local machine as I completely forgot that runs-on is used three times in my workflow. I'm surprised only caching was broken >.> Now it is working as intended!

I didn't have to add networks entries you mentioned or adjust the URL in API_BASE_URL though 🤔

Anyway, thanks for the quick reply and sorry for wasting time, will close the issue.