From 1d591d02bd1fd1ccdd66d7033b788561c76e7e14 Mon Sep 17 00:00:00 2001 From: Oskar Thornblad Date: Tue, 18 Feb 2020 10:41:11 +0100 Subject: [PATCH] Init --- Dockerfile | 18 ++++++++++++++++++ LICENSE.md | 7 +++++++ README.md | 27 +++++++++++++++++++++++++++ action.yml | 9 +++++++++ entrypoint.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 Dockerfile create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 action.yml create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..36912cb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.8-alpine + +LABEL "com.github.actions.name"="S3 cp" +LABEL "com.github.actions.description"="Copy from/to AWS S3" +LABEL "com.github.actions.icon"="refresh-cw" +LABEL "com.github.actions.color"="green" + +LABEL version="0.1.0" +LABEL repository="https://github.com/prewk/s3-cp-action" +LABEL maintainer="Oskar Thornblad " + +# https://github.com/aws/aws-cli/blob/master/CHANGELOG.rst +ENV AWSCLI_VERSION='1.17.1' + +RUN pip install --quiet --no-cache-dir awscli==${AWSCLI_VERSION} + +ADD entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..dad3b56 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +Copyright 2020 Oskar Thornblad + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a92b215 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# GitHub Action to S3 cp + +Borrowed most of it from [jakejarvis/s3-sync-action](https://github.com/jakejarvis/s3-sync-action). + +## Usage + +``` +name: Download a file from S3 + +on: + push: + branches: + - master + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: prewk/s3-cp-action@master + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: 'us-west-1' # optional: defaults to us-east-1 + SOURCE: 's3://some-bucket/something-remote' + DEST: './something-local' +``` \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..ffc233f --- /dev/null +++ b/action.yml @@ -0,0 +1,9 @@ +name: "S3 cp" +description: "AWS S3 cp" +author: prewk +runs: + using: docker + image: Dockerfile +branding: + icon: refresh-cw + color: green \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..e4d0859 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +set -e + +if [ -z "$AWS_ACCESS_KEY_ID" ]; then + echo "AWS_ACCESS_KEY_ID is not set. Quitting." + exit 1 +fi + +if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then + echo "AWS_SECRET_ACCESS_KEY is not set. Quitting." + exit 1 +fi + +# Default to us-east-1 if AWS_REGION not set. +if [ -z "$AWS_REGION" ]; then + AWS_REGION="us-east-1" +fi + +# Override default AWS endpoint if user sets AWS_S3_ENDPOINT. +if [ -n "$AWS_S3_ENDPOINT" ]; then + ENDPOINT_APPEND="--endpoint-url $AWS_S3_ENDPOINT" +fi + +# Create a dedicated profile for this action to avoid conflicts +# with past/future actions. +# https://github.com/jakejarvis/s3-cp-action/issues/1 +aws configure --profile s3-cp-action <<-EOF > /dev/null 2>&1 +${AWS_ACCESS_KEY_ID} +${AWS_SECRET_ACCESS_KEY} +${AWS_REGION} +text +EOF + +# Sync using our dedicated profile and suppress verbose messages. +# All other flags are optional via the `args:` directive. +sh -c "aws s3 cp ${SOURCE} ${DEST} \ + --profile s3-cp-action \ + --no-progress \ + ${ENDPOINT_APPEND} $*" + +# Clear out credentials after we're done. +# We need to re-run `aws configure` with bogus input instead of +# deleting ~/.aws in case there are other credentials living there. +# https://forums.aws.amazon.com/thread.jspa?threadID=148833 +aws configure --profile s3-cp-action <<-EOF > /dev/null 2>&1 +null +null +null +text +EOF \ No newline at end of file