Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commands to upload and remove files from transfer bucket #410

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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)"