import-map-deployer icon indicating copy to clipboard operation
import-map-deployer copied to clipboard

Adding note to README about GCP/Azure concurrency

Open danopia opened this issue 3 years ago • 0 comments

In reaction to:

If you do want to address the deployment race condition without using import-map-deployer, we'd love to hear what you come up with. Consider leaving a PR to these docs that explain what you did!

S3 does not allow for this strategy, but it's valid on several other storage providers as mentioned.

example

To verify the process, I've implemented a basic GCP flow in a rough shell script:

#!/bin/bash
set -euxo pipefail

Bucket="${1}"
Specifier="${2}"
Destination="${3}"
JsonFile="${Bucket}/bundles/latest.json"

# Check that the target is really there
gsutil cat "${Bucket}${Destination}" | wc -c

# Operate optimistically on a single generation
# (If we race someone else with the file, only one will succeed)
CurrentVersion=$(gsutil ls -a "${JsonFile}" | cut -d'#' -f2)
gsutil cat "${JsonFile}#${CurrentVersion}" \
| jq \
    --arg specifier "$Specifier" \
    --arg target "$Destination" \
    '.imports[$specifier] = $target' \
| gsutil \
    -h "x-goog-if-generation-match: ${CurrentVersion}" \
    -h "cache-control: max-age=60" \
    cp - "${JsonFile}"

It didn't seem fit to include in the README itself, given the scope of the doc/repo.

danopia avatar May 14 '22 21:05 danopia