bcr_postsubmit: use gcloud storage rsync with fixed mtimes (#3009)
Migrate `bcr_postsubmit.py` from `gsutil` to `gcloud storage rsync`
again (see #2588), with a fix for the problem that caused the revert in
#2589.
## Problem
A fresh git checkout gives every file a new mtime. `gcloud storage
rsync` keeps the mtime in the object metadata. When the mtime changes,
it patches the metadata of every object, also when the content is the
same.
## Changes
- Set a fixed mtime on all files in `modules/` before rsync. Then rsync
only touches objects with changed content. `--checksums-only` finds the
changed files.
- Upload `last_green.txt` with `Cache-Control: no-cache`.
`get_last_green()` reads this file over HTTP.
Each run is still a full rsync. Thus the latest run alone makes the
bucket the same as the latest commit.
## Testing
I tested on `gs://bazel-testing` with fresh copies of the files for each
run:
| Run | Copies | Metadata patches |
|---|---|---|
| Fixed mtime, no changes | 0 | 0 |
| No fixed mtime, no changes | 0 | all objects |
| Fixed mtime, 1 edit with the same file size + 1 new version + 1
`metadata.json` change | 3 | 0 |
| Fixed mtime, object with a different stored mtime | 0 | 1 |
Note: the first run on the production bucket patches the mtime of all
objects one time, because the objects have different stored mtimes now.
Later runs do not patch.
1 file changed