Created
August 31, 2023 01:59
-
-
Save rumaniel/66fca20c1be6ce5df7d907b19406d791 to your computer and use it in GitHub Desktop.
Upload to s3 with recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# usage ./upload_to_s3.sh githash path/to/local/folder | |
# Check if the githash argument is provided | |
if [ $# -ne 3 ]; then | |
echo "Usage: $0 <githash> <folder-path> <bucket name>" | |
exit 1 | |
fi | |
# Set your bucket name and folder path | |
GITHASH="$1" | |
FOLDER_PATH="$2" | |
BUCKET_NAME="$3" | |
# Get the absolute path of the script's directory | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# Iterate through files in the folder and upload them to S3 | |
echo "Get ${SCRIPT_DIR}/${FOLDER_PATH} items and push to ${BUCKET_NAME}" | |
find "${SCRIPT_DIR}/${FOLDER_PATH}" -type f | while read -r FILE; do | |
RELATIVE_PATH=${FILE#${SCRIPT_DIR}/${FOLDER_PATH}/} | |
S3_KEY="assetbundle/${GITHASH}/${RELATIVE_PATH}" | |
echo "Upload ${RELATIVE_PATH} to ${S3_KEY} on ${BUCKET_NAME}" | |
aws s3api put-object --bucket "${BUCKET_NAME}" --key "${S3_KEY}" --body "${FILE}" --acl bucket-owner-full-control | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment