Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Commit 0facb22

Browse files
committed
Default to us-east-1 region and clear credentials after sync is done.
1 parent 6358f33 commit 0facb22

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ LABEL "com.github.actions.description"="Sync a directory to an AWS S3 repository
55
LABEL "com.github.actions.icon"="refresh-cw"
66
LABEL "com.github.actions.color"="green"
77

8-
LABEL version="0.4.0"
8+
LABEL version="0.5.0"
99
LABEL repository="https://github.com/jakejarvis/s3-sync-action"
1010
LABEL homepage="https://jarv.is/"
1111
LABEL maintainer="Jake Jarvis <[email protected]>"
1212

1313
# https://github.com/aws/aws-cli/blob/master/CHANGELOG.rst
14-
ENV AWSCLI_VERSION='1.16.262'
14+
ENV AWSCLI_VERSION='1.16.265'
1515

1616
RUN pip install --quiet --no-cache-dir awscli==${AWSCLI_VERSION}
1717

README.md

+20-11
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ This simple action uses the [vanilla AWS CLI](https://docs.aws.amazon.com/cli/in
1111

1212
Place in a `.yml` file such as this one in your `.github/workflows` folder. [Refer to the documentation on workflow YAML syntax here.](https://help.github.com/en/articles/workflow-syntax-for-github-actions)
1313

14-
As of v0.3.0, all [`aws s3 sync` flags](https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html) are optional to allow for maximum customizability (that's a word, I promise) and must be provided by you via `args:`. The optimal defaults for a static website are set in this example: `--acl public-read` makes your files publicly readable, `--follow-symlinks` won't hurt and fixes some weird symbolic link problems that may come up, and most importantly, `--delete` **permanently deletes** files in the S3 bucket that are **not** present in the latest version of your repository/build.
14+
As of v0.3.0, all [`aws s3 sync` flags](https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html) are optional to allow for maximum customizability (that's a word, I promise) and must be provided by you via `args:`. The optimal defaults for a static website are set in this example:
15+
16+
- `--acl public-read` makes your files publicly readable (make sure your [bucket settings are also set to public](https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html)).
17+
- `--follow-symlinks` won't hurt and fixes some weird symbolic link problems that may come up.
18+
- Most importantly, `--delete` **permanently deletes** files in the S3 bucket that are **not** present in the latest version of your repository/build.
19+
- If you're syncing the root of your repository, `--exclude '.git/*'` prevents your `.git` folder from syncing, which would expose your source code history if your project is closed-source.
1520

1621
```yaml
17-
name: Sync Bucket
18-
on: push
22+
name: Upload Website
23+
24+
on:
25+
push:
26+
branches:
27+
- master
1928

2029
jobs:
2130
deploy:
@@ -24,13 +33,13 @@ jobs:
2433
- uses: actions/checkout@master
2534
- uses: jakejarvis/s3-sync-action@master
2635
with:
27-
args: --acl public-read --follow-symlinks --delete
36+
args: --acl public-read --follow-symlinks --delete --exclude '.git/*'
2837
env:
29-
SOURCE_DIR: './public'
30-
AWS_REGION: 'us-east-1'
3138
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
3239
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
3340
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41+
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
42+
SOURCE_DIR: 'public' # optional: defaults to entire repository
3443
```
3544
3645
@@ -42,11 +51,11 @@ The following settings must be passed as environment variables as shown in the e
4251
| ------------- | ------------- | ------------- | ------------- | ------------- |
4352
| `AWS_ACCESS_KEY_ID` | Your AWS Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) | `secret` | **Yes** | N/A |
4453
| `AWS_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` | **Yes** | N/A |
45-
| `AWS_S3_BUCKET` | The name of the bucket you're syncing to. For example, `jarv.is`. | `secret` | **Yes** | N/A |
46-
| `AWS_REGION` | The region where you created your bucket in. For example, `us-east-1`. [Full list of regions here.](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) | `env` | **Yes** | N/A |
47-
| `AWS_S3_ENDPOINT` | The endpoint URL of the bucket you're syncing to. Can be used for VPC scenarios or for S3 compliant products like [DigitalOcean Spaces](https://www.digitalocean.com/community/tools/adapting-an-existing-aws-s3-application-to-digitalocean-spaces). | `env` | No | AWS |
48-
| `SOURCE_DIR` | The local directory you wish to sync/upload to S3. For example, `./public` | `env` | No | `.` |
49-
| `DEST_DIR` | The directory inside of the S3 bucket you wish to sync/upload to. Eg: `my_project/assets`. | `env` | No | `/` |
54+
| `AWS_S3_BUCKET` | The name of the bucket you're syncing to. For example, `jarv.is` or `my-app-releases`. | `secret` | **Yes** | N/A |
55+
| `AWS_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` |
56+
| `AWS_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) |
57+
| `SOURCE_DIR` | The local directory you wish to sync/upload to S3. For example, `public`. Defaults to your entire repository. | `env` | No | `./` (root of cloned repository) |
58+
| `DEST_DIR` | The directory inside of the S3 bucket you wish to sync/upload to. For example, `my_project/assets`. Defaults to the root of the bucket. | `env` | No | `/` |
5059

5160

5261
## License

entrypoint.sh

+23-15
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
1717
exit 1
1818
fi
1919

20+
# Default to us-east-1 if AWS_REGION not set.
2021
if [ -z "$AWS_REGION" ]; then
21-
echo "AWS_REGION is not set. Quitting."
22-
exit 1
22+
AWS_REGION="us-east-1"
2323
fi
2424

25-
# Default to CLI defined AWS endpoint
26-
ENDPOINT_APPEND=""
27-
if [ "$AWS_S3_ENDPOINT" ]; then
25+
# Override default AWS endpoint if user sets AWS_S3_ENDPOINT.
26+
if [ -n "$AWS_S3_ENDPOINT" ]; then
2827
ENDPOINT_APPEND="--endpoint-url $AWS_S3_ENDPOINT"
2928
fi
3029

31-
# Default to syncing entire repo if SOURCE_DIR not set.
32-
SOURCE_DIR=${SOURCE_DIR:-.}
33-
34-
# Create a dedicated profile for this action to avoid
35-
# conflicts with other actions.
30+
# Create a dedicated profile for this action to avoid conflicts
31+
# with past/future actions.
3632
# https://github.com/jakejarvis/s3-sync-action/issues/1
3733
aws configure --profile s3-sync-action <<-EOF > /dev/null 2>&1
3834
${AWS_ACCESS_KEY_ID}
@@ -41,8 +37,20 @@ ${AWS_REGION}
4137
text
4238
EOF
4339

44-
# Use our dedicated profile and suppress verbose messages.
45-
# All other flags are optional via `args:` directive.
46-
sh -c "aws s3 sync ${SOURCE_DIR} s3://${AWS_S3_BUCKET}/${DEST_DIR} \
47-
--profile s3-sync-action ${ENDPOINT_APPEND} \
48-
--no-progress $*"
40+
# Sync using our dedicated profile and suppress verbose messages.
41+
# All other flags are optional via the `args:` directive.
42+
sh -c "aws s3 sync ${SOURCE_DIR:-.} s3://${AWS_S3_BUCKET}/${DEST_DIR} \
43+
--profile s3-sync-action \
44+
--no-progress \
45+
${ENDPOINT_APPEND} $*"
46+
47+
# Clear out credentials after we're done.
48+
# We need to re-run `aws configure` with bogus input instead of
49+
# deleting ~/.aws in case there are other credentials living there.
50+
# https://forums.aws.amazon.com/thread.jspa?threadID=148833
51+
aws configure --profile s3-sync-action <<-EOF > /dev/null 2>&1
52+
null
53+
null
54+
null
55+
text
56+
EOF

0 commit comments

Comments
 (0)