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

✨ Allow for specifying the S3 Storage Class #205

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ postgres:app-links <app> # list all postgres service l
postgres:backup <service> <bucket-name> [--use-iam] # creates a backup of the postgres service to an existing s3 bucket
postgres:backup-auth <service> <aws-access-key-id> <aws-secret-access-key> <aws-default-region> <aws-signature-version> <endpoint-url> # sets up authentication for backups on the postgres service
postgres:backup-deauth <service> # removes backup authentication for the postgres service
postgres:backup-s3class <service> <storage-class> # sets the S3 storage class to be used for backups on the postgres service
postgres:backup-schedule <service> <schedule> <bucket-name> [--use-iam] # schedules a backup of the postgres service
postgres:backup-schedule-cat <service> # cat the contents of the configured backup cronfile for the service
postgres:backup-set-encryption <service> <passphrase> # sets encryption for all future backups of postgres service
Expand Down
20 changes: 18 additions & 2 deletions common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_AVAILABLE_PATH/config/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"

docker_ports_options() {
declare desc="Exports a list of exposed ports"
Expand Down Expand Up @@ -188,6 +189,10 @@ service_backup() {
dokku_log_fail "Provide AWS credentials or use the --use-iam flag"
fi

if fn-plugin-property-exists "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "S3_STORAGE_CLASS"; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e S3_STORAGE_CLASS=$(fn-plugin-property-get "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "S3_STORAGE_CLASS")"
fi

TMPDIR=$(mktemp -d --tmpdir)
trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT

Expand Down Expand Up @@ -226,7 +231,7 @@ service_backup_auth() {
declare SERVICE="$1" AWS_ACCESS_KEY_ID="$2" AWS_SECRET_ACCESS_KEY="$3" AWS_DEFAULT_REGION="$4" AWS_SIGNATURE_VERSION="$5" ENDPOINT_URL="$6"
local SERVICE_BACKUP_ROOT="$PLUGIN_DATA_ROOT/$SERVICE/backup"

mkdir "$SERVICE_BACKUP_ROOT"
mkdir -p "$SERVICE_BACKUP_ROOT"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise it will fail upon trying to create the dir if it already existed

echo "$AWS_ACCESS_KEY_ID" >"$SERVICE_BACKUP_ROOT/AWS_ACCESS_KEY_ID"
echo "$AWS_SECRET_ACCESS_KEY" >"$SERVICE_BACKUP_ROOT/AWS_SECRET_ACCESS_KEY"

Expand All @@ -249,7 +254,18 @@ service_backup_deauth() {
local SERVICE_ROOT="${PLUGIN_DATA_ROOT}/${SERVICE}"
local SERVICE_BACKUP_ROOT="${SERVICE_ROOT}/backup/"

rm -rf "$SERVICE_BACKUP_ROOT"
rm -f "$SERVICE_BACKUP_ROOT/AWS_ACCESS_KEY_ID"
rm -f "$SERVICE_BACKUP_ROOT/AWS_SECRET_ACCESS_KEY"
rm -f "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION"
rm -f "$SERVICE_BACKUP_ROOT/AWS_SIGNATURE_VERSION"
rm -f "$SERVICE_BACKUP_ROOT/ENDPOINT_URL"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the auth command is no longer the only one using that directory, leaving it the way it was would also delete the S3_STORAGE_CLASS.


}

service_backup_s3class() {
declare desc="Sets the S3 storage class to be used for the backup"
declare SERVICE="$1" S3_STORAGE_CLASS="$2"
fn-plugin-property-write "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "S3_STORAGE_CLASS" "$S3_STORAGE_CLASS"
}

service_backup_schedule() {
Expand Down
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ fi

export PLUGIN_BUSYBOX_IMAGE="busybox:1.31.1-uclibc"
export PLUGIN_AMBASSADOR_IMAGE="dokku/ambassador:0.3.3"
export PLUGIN_S3BACKUP_IMAGE="dokku/s3backup:0.10.3"
export PLUGIN_S3BACKUP_IMAGE="dokku/s3backup:0.11.1"
export PLUGIN_WAIT_IMAGE="dokku/wait:0.4.3"
3 changes: 3 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"

set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x

Expand All @@ -25,6 +27,7 @@ plugin-install() {
mkdir -p "$PLUGIN_DATA_ROOT" || echo "Failed to create $PLUGIN_SERVICE data directory"
chown dokku:dokku "$PLUGIN_DATA_ROOT"

fn-plugin-property-setup "$PLUGIN_COMMAND_PREFIX"
mkdir -p "$PLUGIN_CONFIG_ROOT" || echo "Failed to create $PLUGIN_SERVICE config directory"
chown dokku:dokku "$PLUGIN_CONFIG_ROOT"

Expand Down
26 changes: 26 additions & 0 deletions subcommands/backup-s3class
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"

service-backup-s3class-cmd() {
#E set the s3 storage class to Standard Infrequent Access
#E dokku $PLUGIN_COMMAND_PREFIX:backup-s3class lolipop STANDARD_IA
#A service, service to run command against
#A storage-class, an aws S3 storage class
declare desc="sets the S3 storage class to be used for backups on the $PLUGIN_SERVICE service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-s3class" argv=("$@")
[[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" STORAGE_CLASS="$2"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"

[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
[[ -z "$STORAGE_CLASS" ]] && dokku_log_fail "Please specify an aws S3 storage class"
[[ ! "$STORAGE_CLASS" =~ ^(STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE)$ ]] && dokku_log_fail "$STORAGE_CLASS is not a valid S3 storage class. Read https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html for more information."
service_backup_s3class "$SERVICE" "$STORAGE_CLASS"
echo "Set the storage class to $STORAGE_CLASS"
}

service-backup-s3class-cmd "$@"