deploy: skip --delete on R2 sync when partial rebuild
When EXISTING_VERSIONS is set, the build only produces HTML for a subset of versions and the bucket already contains the others. s5cmd sync with --delete would purge those existing keys. Omit --delete in that case and keep it for full rebuilds (EXISTING_VERSIONS empty). Assisted-by: Claude Opus 4 (Claude Code)
This commit is contained in:
Vendored
+11
-1
@@ -141,14 +141,24 @@ docker run --rm \
|
||||
string(credentialsId: 'r2-access-key-id', variable: 'AWS_ACCESS_KEY_ID'),
|
||||
string(credentialsId: 'r2-secret-access-key', variable: 'AWS_SECRET_ACCESS_KEY')
|
||||
]) {
|
||||
// When EXISTING_VERSIONS is set this is a partial rebuild,
|
||||
// so omit --delete to preserve versions already in the bucket.
|
||||
sh '''
|
||||
if [ -n "${EXISTING_VERSIONS}" ]; then
|
||||
DELETE_FLAG=""
|
||||
echo "Partial rebuild (EXISTING_VERSIONS set) -- preserving existing objects."
|
||||
else
|
||||
DELETE_FLAG="--delete"
|
||||
echo "Full rebuild -- bucket will be synced with --delete."
|
||||
fi
|
||||
|
||||
docker run --rm \
|
||||
-v "$(pwd)/html:/workspace/html" \
|
||||
-e AWS_ACCESS_KEY_ID \
|
||||
-e AWS_SECRET_ACCESS_KEY \
|
||||
peakcom/s5cmd:latest \
|
||||
--endpoint-url "https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com" \
|
||||
sync --delete /workspace/html/ "s3://${R2_BUCKET_NAME}/"
|
||||
sync ${DELETE_FLAG} /workspace/html/ "s3://${R2_BUCKET_NAME}/"
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user