-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #63 support downloading files from s3 storage
- Loading branch information
1 parent
ecb13d9
commit a0cd1e3
Showing
10 changed files
with
215 additions
and
125 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
echo "Starting s3 download script validation" | ||
|
||
# Function to check if a variable is set and not empty | ||
check_var() { | ||
eval value=\$$1 | ||
if [ -z "$value" ]; then | ||
echo "Error: $1 is not set or is empty" | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_var SRC_FILE_PATH | ||
check_var DEST_FILE_PATH | ||
check_var S3_ACCESS_KEY | ||
check_var S3_SECRET_KEY | ||
check_var S3_ENDPOINT | ||
check_var S3_REGION | ||
check_var S3_BUCKET | ||
check_var PATH_PREFIX | ||
|
||
DEST_FILE_PATH="/$DEST_FILE_PATH" | ||
|
||
echo "Removing $DEST_FILE_PATH/*" | ||
rm -rf "$DEST_FILE_PATH/*" 2> /dev/null || true | ||
|
||
echo "Downloading from s3://$S3_BUCKET/$PATH_PREFIX/$SRC_FILE_PATH" | ||
|
||
case "$SRC_FILE_PATH" in | ||
*".tar.gz") | ||
ARCHIVE_FORMAT="tar.gz" | ||
;; | ||
*".zip") | ||
ARCHIVE_FORMAT="zip" | ||
;; | ||
*) | ||
echo "Unsupported archive format: $SRC_FILE_PATH" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
ARCHIVE_PATH="/tmp/archive.$ARCHIVE_FORMAT" | ||
|
||
s3cmd --access_key "$S3_ACCESS_KEY" \ | ||
--secret_key "$S3_SECRET_KEY" \ | ||
--host "$S3_ENDPOINT" \ | ||
--host-bucket "$S3_ENDPOINT" \ | ||
--region "$S3_REGION" \ | ||
get "s3://$S3_BUCKET/$PATH_PREFIX/$SRC_FILE_PATH" "$ARCHIVE_PATH" | ||
|
||
echo "Extracting $SRC_FILE_PATH to $DEST_FILE_PATH" | ||
|
||
case "$ARCHIVE_FORMAT" in | ||
"tar.gz") | ||
tar -xzvf "$ARCHIVE_PATH" -C "$DEST_FILE_PATH" | ||
;; | ||
"zip") | ||
apk add zip | ||
unzip "$ARCHIVE_PATH" | ||
;; | ||
*) | ||
echo "Unsupported archive format: $ARCHIVE_FORMAT" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
echo "Removing $ARCHIVE_PATH" | ||
rm -f "$ARCHIVE_PATH" | ||
|
||
echo "Done" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
echo 'https://ptah.sh' > /tmp/check-access.txt | ||
|
||
echo "Starting s3 upload script validation" | ||
|
||
# Function to check if a variable is set and not empty | ||
check_var() { | ||
eval value=\$$1 | ||
if [ -z "$value" ]; then | ||
echo "Error: $1 is not set or is empty" | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_var ARCHIVE_FORMAT | ||
check_var SRC_FILE_PATH | ||
check_var DEST_FILE_PATH | ||
check_var S3_ACCESS_KEY | ||
check_var S3_SECRET_KEY | ||
check_var S3_ENDPOINT | ||
check_var S3_REGION | ||
check_var S3_BUCKET | ||
check_var PATH_PREFIX | ||
|
||
SRC_FILE_PATH="/$SRC_FILE_PATH" | ||
|
||
if [ -d "$SRC_FILE_PATH" ]; then | ||
cd "$SRC_FILE_PATH" | ||
else | ||
cd "$(dirname "$SRC_FILE_PATH")" | ||
fi | ||
|
||
echo "Archiving $SRC_FILE_PATH" | ||
|
||
SRC_FILE_PATH="/tmp/archive.$ARCHIVE_FORMAT" | ||
|
||
case "$ARCHIVE_FORMAT" in | ||
"tar.gz") | ||
tar -czvf "$SRC_FILE_PATH" "." | ||
;; | ||
"zip") | ||
apk add zip | ||
zip -r "$SRC_FILE_PATH" "." | ||
;; | ||
*) | ||
echo "Unsupported archive format: $ARCHIVE_FORMAT" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
echo "Uploading $SRC_FILE_PATH to s3://$S3_BUCKET/$PATH_PREFIX/$DEST_FILE_PATH" | ||
|
||
s3cmd --guess-mime-type \ | ||
--access_key "$S3_ACCESS_KEY" \ | ||
--secret_key "$S3_SECRET_KEY" \ | ||
--host "$S3_ENDPOINT" \ | ||
--host-bucket "$S3_ENDPOINT" \ | ||
--region "$S3_REGION" \ | ||
put "$SRC_FILE_PATH" "s3://$S3_BUCKET/$PATH_PREFIX/$DEST_FILE_PATH" | ||
|
||
echo "Removing $SRC_FILE_PATH/*" | ||
rm -rf "$SRC_FILE_PATH/*" 2> /dev/null || true | ||
|
||
echo "Done" |
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
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
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
Oops, something went wrong.