-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add commands to upload and remove files from transfer bucket
This is so we can get files from a localhost to the ECS cluster or elsewhere and then tidy up afterwards
- Loading branch information
Showing
2 changed files
with
137 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/bash | ||
|
||
# exit on failures | ||
set -e | ||
set -o pipefail | ||
|
||
usage() { | ||
echo "Usage: $(basename "$0") [OPTIONS]" 1>&2 | ||
echo " -h - help" | ||
echo " -i <infrastructure> - infrastructure name" | ||
echo " -e <environment> - environment name (e.g. 'staging' or 'prod')" | ||
echo " -s <source> - Source" | ||
echo " -r <recursive> - Recursive" | ||
exit 1 | ||
} | ||
|
||
# if there are no arguments passed exit with usage | ||
if [ $# -eq 0 ]; then | ||
usage | ||
fi | ||
|
||
RECURSIVE=0 | ||
|
||
while getopts "i:e:s:rh" opt; do | ||
case $opt in | ||
i) | ||
INFRASTRUCTURE_NAME=$OPTARG | ||
;; | ||
e) | ||
ENVIRONMENT=$OPTARG | ||
;; | ||
s) | ||
SOURCE=$OPTARG | ||
;; | ||
r) | ||
RECURSIVE=1 | ||
;; | ||
h) | ||
usage | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
if [[ | ||
-z "$INFRASTRUCTURE_NAME" || | ||
-z "$ENVIRONMENT" || | ||
-z "$SOURCE" ]]; then | ||
usage | ||
fi | ||
|
||
BUCKET_NAME="$INFRASTRUCTURE_NAME-ecs-$ENVIRONMENT-dalmatian-transfer" | ||
|
||
|
||
if [ "$RECURSIVE" == 1 ]; then | ||
S3_RECURSIVE="--recursive" | ||
else | ||
S3_RECURSIVE="" | ||
fi | ||
|
||
log_info -l "==> Removing $SOURCE from S3 bucket $BUCKET_NAME..." -q "$QUIET_MODE" | ||
|
||
# shellcheck disable=2086 | ||
aws s3 rm s3://"$BUCKET_NAME"/"$SOURCE" $S3_RECURSIVE | ||
|
||
log_info -l "Success!" -q "$QUIET_MODE" |
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,69 @@ | ||
#!/bin/bash | ||
|
||
# exit on failures | ||
set -e | ||
set -o pipefail | ||
|
||
usage() { | ||
echo "Usage: $(basename "$0") [OPTIONS]" 1>&2 | ||
echo " -h - help" | ||
echo " -i <infrastructure> - infrastructure name" | ||
echo " -e <environment> - environment name (e.g. 'staging' or 'prod')" | ||
echo " -s <source> - Source" | ||
echo " -r <recursive> - Recursive" | ||
exit 1 | ||
} | ||
|
||
# if there are no arguments passed exit with usage | ||
if [ $# -eq 0 ]; then | ||
usage | ||
fi | ||
|
||
RECURSIVE=0 | ||
|
||
while getopts "i:e:s:rh" opt; do | ||
case $opt in | ||
i) | ||
INFRASTRUCTURE_NAME=$OPTARG | ||
;; | ||
e) | ||
ENVIRONMENT=$OPTARG | ||
;; | ||
s) | ||
SOURCE=$OPTARG | ||
;; | ||
r) | ||
RECURSIVE=1 | ||
;; | ||
h) | ||
usage | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
if [[ | ||
-z "$INFRASTRUCTURE_NAME" || | ||
-z "$ENVIRONMENT" || | ||
-z "$SOURCE" ]]; then | ||
usage | ||
fi | ||
|
||
BUCKET_NAME="$INFRASTRUCTURE_NAME-ecs-$ENVIRONMENT-dalmatian-transfer" | ||
PREFIX_DIR="${HOSTNAME}-$(date +%Y-%m-%d)" | ||
|
||
log_info -l "==> Copying $SOURCE to $BUCKET_NAME S3 bucket ..." -q "$QUIET_MODE" | ||
|
||
if [ "$RECURSIVE" == 1 ]; then | ||
S3_RECURSIVE="--recursive" | ||
else | ||
S3_RECURSIVE="" | ||
fi | ||
|
||
# shellcheck disable=2086 | ||
aws s3 cp "$SOURCE" s3://"$BUCKET_NAME"/"$PREFIX_DIR"/"$(basename "$SOURCE")" $S3_RECURSIVE | ||
|
||
log_info -l "Success!" -q "$QUIET_MODE" | ||
echo "aws s3 cp s3://$BUCKET_NAME/$PREFIX_DIR/$(basename "$SOURCE") . $S3_RECURSIVE to download the file(s)" |