everpcpc / actions-cache

Actions cache to cloud storage with OpenDAL
MIT License
17 stars 2 forks source link

Save s3 cache failed: Error: getaddrinfo ENOTFOUND s3..amazonaws.com #5

Closed strophy closed 1 year ago

strophy commented 1 year ago

This action recently stopped working for me in some cases with the following errors on restore/save. @everpcpc Is this related to OpenDAL, or am I configuring something incorrectly? s3..amazonaws.com makes me think it is parsing the region incorrectly?

My action looks like this:

- name: Configure AWS credentials and bucket region
  uses: aws-actions/configure-aws-credentials@v4
  if: contains(runner.name, 'ubuntu-platform')
  with:
    aws-region: eu-west-1

- name: Cache NPM build artifacts (S3 bucket cache)
  uses: everpcpc/actions-cache@v1
  if: contains(runner.name, 'ubuntu-platform')
  with:
    bucket: multi-runner-linux-x64-platform-cache-ui535z23
    endpoint: s3.amazonaws.com
    root: actions-cache
    path: |
      .yarn/unplugged
    key: ${{ runner.os }}-yarn-unplugged-${{ hashFiles('yarn.lock') }}
    restore-keys: |
      ${{ runner.os }}-yarn-unplugged-

Restore (multiple hits should exist in this bucket):

##[debug]Loading env
Run everpcpc/actions-cache@v1
  with:
    bucket: multi-runner-linux-x64-platform-cache-ui535z23
    endpoint: s3.amazonaws.com
    root: actions-cache
    path: .yarn/unplugged

    key: Linux-yarn-unplugged-608e20aab582ae1f974e74345514012f98154f94e1e0185077d562a5ab7b926b
    restore-keys: Linux-yarn-unplugged-

    provider: s3
    use-fallback: false
  env:
    AWS_DEFAULT_REGION: eu-west-1
    AWS_REGION: eu-west-1
##[debug]Checking zstd --quiet --version
##[debug]1.4.8
##[debug]zstd version: 1.4.8
##[debug]Key: "Linux-yarn-unplugged-608e20aab582ae1f974e74345514012f98154f94e1e0185077d562a5ab7b926b"
##[debug]Restore keys: ["Linux-yarn-unplugged-"]
##[debug]Finding exact macth for: Linux-yarn-unplugged-608e20aab582ae1f974e74345514012f98154f94e1e0185077d562a5ab7b926b
##[debug]Found []
##[debug]Finding object with prefix: Linux-yarn-unplugged-
##[debug]Found []
Restore s3 cache failed: Error: Cache item not found
##[debug]Node Action run completed with exit code 0
##[debug]Save intra-action state primary-key = Linux-yarn-unplugged-608e20aab582ae1f974e74345514012f98154f94e1e0185077d562a5ab7b926b
##[debug]Set output cache-hit = false
##[debug]Finished: run

Save:

Uploading tar to s3. Bucket: multi-runner-linux-x64-platform-cache-ui535z23, root: actions-cache, Object: Linux-yarn-unplugged-608e20aab582ae1f974e74345514012f98154f94e1e0185077d562a5ab7b926b/cache.tzst
##[debug]Presigned request Method: PUT, Url: https://s3..amazonaws.com/multi-runner-linux-x64-platform-cache-ui535z23/actions-cache/Linux-yarn-unplugged-608e20aab582ae1f974e74345514012f98154f94e1e0185077d562a5ab7b926b/cache.tzst?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=%2F20231101%2F%2Fs3%2Faws4_request&X-Amz-Date=20231101T082609Z&X-Amz-Expires=600&X-Amz-Security-Token&X-Amz-SignedHeaders=host&X-Amz-Signature=123
Save s3 cache failed: Error: getaddrinfo ENOTFOUND s3..amazonaws.com
##[debug]skipped fallback cache
##[debug]Node Action run completed with exit code 0
##[debug]Finished: run

Removing endpoint: s3.amazonaws.com has no effect. I am using a Gateway Endpoint to access S3 from inside the VPC.

strophy commented 1 year ago

I actually use the action again at a different point in the workflow and it works. After forcing use of the correct endpoint with endpoint: s3.eu-west-1.amazonaws.com I noticed the difference between the working and non-working run is in the presigned request, the one that fails only has a partial X-Amz-Credential and the X-Amz-Security-Token is missing entirely, as well as the URL being invalid.

I noticed I use aws-actions/configure-aws-credentials@v4 before each cache step. Moving this out of the called composite action and into the calling action resulted in the cache action working correctly again, it was something to do with running the configure-aws-credentials action twice.