GoogleCloudPlatform / cloud-builders-community

Community-contributed images for Google Cloud Build
https://cloud.google.com/cloud-build/
Apache License 2.0
1.26k stars 858 forks source link

Strip a trailing slash from bucket name if present #554

Closed amirtu closed 10 months ago

amirtu commented 2 years ago

As Google Cloud Storage interprets consecutive slashes differently from Unix/Linux Path Resolution Algorithm, restore_cache cannot find the cache object created by save_cache in case of presence of a trailing slash in the --bucket argument supplied identically to both of the commands, as in the following example:

cloudbuild.yaml

steps:
  - name: 'gcr.io/$PROJECT_ID/restore_cache'
    id: restore_gradle_cache
    args:
      - '--bucket=gs://${_GRADLE_CACHE_BUCKET}/' # here the slash makes cache file existence check to fail
      - '--key=${_GRADLE_CACHE_KEY}'
  ...
  - name: 'gcr.io/$PROJECT_ID/save_cache'
    id: save_gradle_cache
    args:
      - '--bucket=gs://${_GRADLE_CACHE_BUCKET}/'
      - '--key=${_GRADLE_CACHE_KEY}'
      - '--path=${_GRADLE_USER_HOME}/caches'
      - '--path=${_GRADLE_USER_HOME}/wrapper'
options:
  dynamic_substitutions: true
substitutions:
  _GRADLE_CACHE_BUCKET: ${PROJECT_ID}_cloudbuild/gradle_cache
  ...
amirtu commented 2 years ago

@googlebot I signed it!