fix(cache): trim whitespace in delta count + use s3api for tagging

Two fixes:
1. Restore: Trim whitespace from DELTA_COUNT to fix integer comparison
2. Save: Use 's3api put-object' instead of 's3 cp' to support --tagging

The aws s3 cp command doesn't support --tagging parameter.
Switched to s3api put-object which supports tagging directly.
Tags are needed for lifecycle policies (30-day eviction).
This commit is contained in:
Nicholas Dudfield
2025-10-30 09:29:02 +07:00
parent 3e5c15c172
commit 7ea99caa19
2 changed files with 20 additions and 10 deletions

View File

@@ -107,6 +107,7 @@ runs:
# Delete all delta layers for this key
echo "Deleting all delta layers matching: ${CACHE_KEY}-delta-*"
DELTA_COUNT=$(aws s3 ls "s3://${S3_BUCKET}/" --region "${S3_REGION}" | grep "${CACHE_KEY}-delta-" | wc -l || echo "0")
DELTA_COUNT=$(echo "${DELTA_COUNT}" | tr -d ' \n') # Trim whitespace
if [ "${DELTA_COUNT}" -gt 0 ]; then
aws s3 rm "s3://${S3_BUCKET}/" --recursive \
--exclude "*" \

View File

@@ -134,10 +134,13 @@ runs:
echo "Uploading base layer to S3..."
echo " Key: ${PRIMARY_KEY}-base.tar.zst"
aws s3 cp "${BASE_TARBALL}" "${S3_BASE_KEY}" \
aws s3api put-object \
--bucket "${S3_BUCKET}" \
--key "${PRIMARY_KEY}-base.tar.zst" \
--body "${BASE_TARBALL}" \
--tagging 'type=base' \
--region "${S3_REGION}" \
--tagging "type=base" \
--quiet
>/dev/null
echo "✓ Uploaded: ${S3_BASE_KEY}"
fi
@@ -178,10 +181,13 @@ runs:
echo "Uploading new base layer to S3..."
echo " Key: ${PRIMARY_KEY}-base.tar.zst"
aws s3 cp "${BASE_TARBALL}" "${S3_BASE_KEY}" \
aws s3api put-object \
--bucket "${S3_BUCKET}" \
--key "${PRIMARY_KEY}-base.tar.zst" \
--body "${BASE_TARBALL}" \
--tagging 'type=base' \
--region "${S3_REGION}" \
--tagging "type=base" \
--quiet
>/dev/null
echo "✓ Uploaded: ${S3_BASE_KEY}"
fi
@@ -295,11 +301,14 @@ runs:
echo "Uploading timestamped delta to S3..."
echo " Key: ${PRIMARY_KEY}-delta-${TIMESTAMP}-${COMMIT_SHA}.tar.zst"
# Upload with tag (deltas cleaned up inline - keep last 10)
aws s3 cp "${DELTA_TARBALL}" "${S3_DELTA_TIMESTAMPED}" \
# Upload with tag (deltas cleaned up inline - keep last 1)
aws s3api put-object \
--bucket "${S3_BUCKET}" \
--key "${PRIMARY_KEY}-delta-${TIMESTAMP}-${COMMIT_SHA}.tar.zst" \
--body "${DELTA_TARBALL}" \
--tagging 'type=delta-archive' \
--region "${S3_REGION}" \
--tagging "type=delta-archive" \
--quiet
>/dev/null
echo "✓ Uploaded: ${S3_DELTA_TIMESTAMPED}"