From d3a9aaeb86202772abaea495c788e078ed116fd3 Mon Sep 17 00:00:00 2001 From: Adam Zimmermann Date: Wed, 25 May 2022 16:01:52 -0500 Subject: [PATCH] Allow copying to a S3 bucket directory. --- .gitignore | 2 ++ README.md | 1 + action.yml | 3 +++ entrypoint.sh | 9 ++++++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e69de29..2e98753 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +# Ignore IDE files. +.idea diff --git a/README.md b/README.md index aec0c61..0e3e4d5 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ GitHub Action to take a database dump from a platform.sh site and copy the dump platformsh_relationship: 'database' # optional. specify if the project has multiple databases. platformsh_app: 'api' # optional. specify if the project has multiple apps. aws_s3_bucket: 'bucket-name' # required. + aws_s3_directory: 'my-directory' db_dump_filename_base: 'sitename-db-dump' env: PLATFORMSH_CLI_TOKEN: ${{ secrets.PLATFORMSH_CLI_TOKEN }} # required. diff --git a/action.yml b/action.yml index 0ea5fcf..dba41e9 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,9 @@ inputs: description: 'Filename for the database dump. A timestamp will be appended after it.' required: false default: 'db-dump' + aws_s3_directory: + description: 'A directory within the S3 bucket with no proceeding / to copy the file to.' + required: false runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 4d8b12f..a21a7b5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -30,4 +30,11 @@ else fi fi -aws s3 cp "$FILENAME".sql.gz s3://"$INPUT_AWS_S3_BUCKET" +if [ -z "${INPUT_AWS_S3_DIRECTORY}" ] ] +then + # No directory was supplied, copy the file to the root of the bucket. + aws s3 cp "$FILENAME".sql.gz s3://"$INPUT_AWS_S3_BUCKET" +else + # A directory was supplied, so copy the file to it. + aws s3 cp "$FILENAME".sql.gz s3://"$INPUT_AWS_S3_BUCKET"/"$INPUT_AWS_S3_FOLDER" +fi