Skip to content

Commit

Permalink
Merge pull request #1 from the-events-calendar/add-cp-command
Browse files Browse the repository at this point in the history
Add the 'cp' command
  • Loading branch information
borkweb authored Dec 17, 2024
2 parents 0165a1b + b70b1c8 commit 281d5e1
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 56 deletions.
135 changes: 82 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ of the commands provided by this GitHub Action. Sensitive information, especiall
they'll be public to anyone browsing your repository's source code and
CI logs.

| Key | Value | Suggested Type | Required | Default |
| ------------- | ------------- | ------------- | ------------- | ------------- |
| `COMMAND` | The action command (see below) you wish to execute | `env` | **Yes** | N/A |
| `S3_ACCESS_KEY_ID` | Your AWS Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) | `secret env` | **Yes** | N/A |
| `S3_SECRET_ACCESS_KEY` | Your AWS Secret Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) | `secret env` | **Yes** | N/A |
| `S3_BUCKET` | The name of the bucket you're syncing to. For example, `jarv.is` or `my-app-releases`. | `secret env` | **Yes** | N/A |
| `S3_REGION` | The region where you created your bucket. Set to `us-east-1` by default. [Full list of regions here.](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) | `env` | No | `us-east-1` |
| `S3_ENDPOINT` | The endpoint URL of the bucket you're syncing to. Can be used for [VPC scenarios](https://aws.amazon.com/blogs/aws/new-vpc-endpoint-for-amazon-s3/) or for non-AWS services using the S3 API, like [DigitalOcean Spaces](https://www.digitalocean.com/community/tools/adapting-an-existing-aws-s3-application-to-digitalocean-spaces). | `env` | No | Automatic (`s3.amazonaws.com` or AWS's region-specific equivalent) |

| Key | Value | Suggested Type | Required | Default |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------- | ------------------------------------------------------------------ |
| `COMMAND` | The action command (see below) you wish to execute | `env` | **Yes** | N/A |
| `S3_ACCESS_KEY_ID` | Your AWS Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) | `secret env` | **Yes** | N/A |
| `S3_SECRET_ACCESS_KEY` | Your AWS Secret Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) | `secret env` | **Yes** | N/A |
| `S3_BUCKET` | The name of the bucket you're syncing to. For example, `jarv.is` or `my-app-releases`. | `secret env` | **Yes** | N/A |
| `S3_REGION` | The region where you created your bucket. Set to `us-east-1` by default. [Full list of regions here.](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) | `env` | No | `us-east-1` |
| `S3_ENDPOINT` | The endpoint URL of the bucket you're syncing to. Can be used for [VPC scenarios](https://aws.amazon.com/blogs/aws/new-vpc-endpoint-for-amazon-s3/) or for non-AWS services using the S3 API, like [DigitalOcean Spaces](https://www.digitalocean.com/community/tools/adapting-an-existing-aws-s3-application-to-digitalocean-spaces). | `env` | No | Automatic (`s3.amazonaws.com` or AWS's region-specific equivalent) |

## Commands

Expand All @@ -33,23 +32,23 @@ You can add the following as a step in one of your workflows:
```
- name: S3 exists
uses: the-events-calendar/action-s3-utility@main
env:
COMMAND: exists
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
FILE: 'some-file-name.txt'
env:
COMMAND: exists
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
FILE: 'some-file-name.txt'
```

#### Configuration

Additional configuration for this command:

| Key | Value | Suggested Type | Required | Default |
| ------------- | ------------- | ------------- | ------------- | ------------- |
| `FILE` | The file you want to check for the existence of | `env` | No | `/` (root of bucket) |
| Key | Value | Suggested Type | Required | Default |
| ------ | ----------------------------------------------- | -------------- | -------- | ------- |
| `FILE` | The file you want to check for the existence of | `env` | Yes | N/A |

### `ls`

Expand All @@ -62,23 +61,23 @@ You can add the following as a step in one of your workflows:
```
- name: S3 ls
uses: the-events-calendar/action-s3-utility@main
env:
COMMAND: ls
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
FILE: 'some-file-name.txt'
env:
COMMAND: ls
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
FILE: 'some-file-name.txt'
```

#### Configuration

Additional configuration for this command:

| Key | Value | Suggested Type | Required | Default |
| ------------- | ------------- | ------------- | ------------- | ------------- |
| `FILE` | The file you want to check for the existence of | `env` | No | `/` (root of bucket) |
| Key | Value | Suggested Type | Required | Default |
| ------ | ----------------------------------------------- | -------------- | -------- | ------- |
| `FILE` | The file you want to check for the existence of | `env` | Yes | N/A |

### `rm`

Expand All @@ -91,23 +90,23 @@ You can add the following as a step in one of your workflows:
```
- name: S3 rm
uses: the-events-calendar/action-s3-utility@main
env:
COMMAND: rm
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
FILE: 'some-file-name.txt'
env:
COMMAND: rm
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
FILE: 'some-file-name.txt'
```

#### Configuration

Additional configuration for this command:

| Key | Value | Suggested Type | Required | Default |
| ------------- | ------------- | ------------- | ------------- | ------------- |
| `FILE` | The file you want to check for the existence of | `env` | No | `/` (root of bucket) |
| Key | Value | Suggested Type | Required | Default |
| ------ | ----------------------------------------------- | -------------- | -------- | ------- |
| `FILE` | The file you want to check for the existence of | `env` | Yes | N/A |

### `sync`

Expand All @@ -120,20 +119,50 @@ You can add the following as a step in one of your workflows:
```
- name: S3 sync
uses: the-events-calendar/action-s3-utility@main
env:
COMMAND: sync
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
SOURCE_DIR: 'some-dir/'
env:
COMMAND: sync
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
SOURCE_DIR: 'some-dir/'
```

#### Configuration

Additional configuration for this command:

| Key | Value | Suggested Type | Required | Default |
| ------------ | -------------------------------------- | -------------- | -------- | -------------------- |
| `SOURCE_DIR` | The file or directory you wish to sync | `env` | No | `/` (root of bucket) |

### `cp`

This command performs `aws s3 cp`.

#### `workflow.yml` Step Example

You can add the following as a step in one of your workflows:

```
- name: S3 cp
uses: the-events-calendar/action-s3-utility@main
env:
COMMAND: cp
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
FILE: 'some-file-name.txt'
DESTINATION: 'some-dir/some-file-name.txt'
```

#### Configuration

Additional configuration for this command:

| Key | Value | Suggested Type | Required | Default |
| ------------- | ------------- | ------------- | ------------- | ------------- |
| `SOURCE_DIR` | The file or directory you wish to sync | `env` | No | `/` (root of bucket) |
| Key | Value | Suggested Type | Required | Default |
| ------------- | ---------------------------- | -------------- | -------- | ------- |
| `DESTINATION` | The destination file or dir. | `env` | Yes | N/A |
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'S3 Utility'
description: 'Execute various s3 (ls, sync, rm) and s3 helper commands (exists)'
description: 'Execute various s3 (ls, sync, rm, cp) and s3 helper commands (exists)'
author: 'The Events Calendar (support@theeventscalendar.com)'
branding:
icon: file
Expand Down
22 changes: 22 additions & 0 deletions commands/cp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -e

if [ -z "$FILE" ]; then
echo "FILE is not set. Quitting."
exit 1
fi

if [ -z "$DESTINATION" ]; then
echo "Destination is not set. Quitting."
exit 1
fi

the_command="aws ${S3_PROFILE} ${ENDPOINT_APPEND} s3 cp s3://${S3_BUCKET}/${FILE} ${DESTINATION}"

echo $the_command

# Run the command.
output=$(sh -c "$the_command")

echo $output
6 changes: 4 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fi
S3_PROFILE="--profile action-s3-utility"

# Create a dedicated profile for this action
aws configure --profile action-s3-utility <<-EOF > /dev/null 2>&1
aws configure --profile action-s3-utility <<-EOF >/dev/null 2>&1
${S3_ACCESS_KEY_ID}
${S3_SECRET_ACCESS_KEY}
${S3_REGION}
Expand All @@ -50,10 +50,12 @@ elif [[ "$COMMAND" == "exists" ]]; then
. /commands/exists.sh
elif [[ "$COMMAND" == "rm" ]]; then
. /commands/rm.sh
elif [[ "$COMMAND" == "cp" ]]; then
. /commands/cp.sh
fi

# Clear out credentials after we're done.
aws configure --profile action-s3-utility <<-EOF > /dev/null 2>&1
aws configure --profile action-s3-utility <<-EOF >/dev/null 2>&1
null
null
null
Expand Down

0 comments on commit 281d5e1

Please sign in to comment.