Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/scripts/save-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ echo "Cache Path is $CACHE_PATH"
# Check if the cache path exists
if [ -d "$CACHE_PATH" ]; then

# Check if cache already exists in S3 before compressing
echo "Checking if cache already exists in S3..."
S3_OBJECT_PATH="s3://$BUCKET_NAME/$CACHE_KEY/$CACHE_KEY.tar.gz"

if aws s3api head-object --bucket "$BUCKET_NAME" --key "$CACHE_KEY/$CACHE_KEY.tar.gz" > /dev/null 2>&1; then
echo "Cache key '$CACHE_KEY' already exists in S3. Skipping compression and upload."
exit 0
fi

echo "Cache not found in S3. Proceeding with compression..."
echo "Cache path exists. Archiving..."
# Create the archive
tar -czf "$CACHE_KEY.tar.gz" "$CACHE_PATH"
Expand All @@ -21,7 +31,7 @@ if [ -d "$CACHE_PATH" ]; then
aws configure set default.s3.multipart_threshold "$S3_MULTIPART_THRESHOLD"

# Upload the archive to the S3 bucket
aws s3 cp "$CACHE_KEY.tar.gz" "s3://$BUCKET_NAME/$CACHE_KEY/$CACHE_KEY.tar.gz"
aws s3 cp "$CACHE_KEY.tar.gz" "$S3_OBJECT_PATH"
echo "Cache archive uploaded to S3."
else
echo "Cache path does not exist. Skipping upload."
Expand Down