Skip to content

Commit

Permalink
Add commands to upload and remove files from transfer bucket
Browse files Browse the repository at this point in the history
This is so we can get files from a localhost to the ECS cluster or elsewhere
and then tidy up afterwards
  • Loading branch information
rjw1 committed Feb 28, 2025
1 parent 4952b5d commit fccfc28
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
68 changes: 68 additions & 0 deletions bin/ecs/v1/remove-from-transfer-bucket
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"
69 changes: 69 additions & 0 deletions bin/ecs/v1/upload-to-transfer-bucket
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)"

0 comments on commit fccfc28

Please sign in to comment.