rbb-data/svelte-starter

Deployment fails when the target directory contains no files

Closed this issue · 0 comments

This line of code should remove the given destination folder if it already exists:

gsutil -q stat ${cloud_dst}/* && gsutil rm -r $dst

gsutil -q stat ${cloud_dst}/* is meant to check if the folder exists but it really checks if there is a folder with at least one file. That means: If the destination folder only contains directories (and no files), then gsutil -q stat ${cloud_dst}/* returns an exit code of 1 and the subsequent command is not executed (i.e. the destination folder is not removed).

The next line copies local files to the destination folder:

gsutil cp -r -z html,css,js "$BUILD_DIR" "$cloud_dst"

Not removing the destination folder becomes a problem because gsutil cp behaves differently if the destination folder already exists.

  • If $cloud_dst doesn't exit, then gsutil cp creates a directory with name $cloud_dst and copies files within $BUILD_DIR into that directory (resulting paths: $cloud_dst/*).
  • If $cloud_dst exists, then gsutil cp creates an extra directory $BUILD_DIR within $cloud_dst. The resulting path would then be $cloud_dst/$BUILD_DIR/*.

The second case leads to the following issues: (i) The app appears to be unavailbale because the public path has changed. (ii) Subsequent deployments (by this method) will fail in the same way as $cloud_dst will continue to only contains directories.