This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 780c45c
Showing
23 changed files
with
5,906 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
on: [push, pull_request] | ||
|
||
env: | ||
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} | ||
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}" | ||
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" | ||
|
||
name: Deploy NextJS | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Use Node.js 16 | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
- name: Install dependencies | ||
run: npm install --prefix nextjs-testapp | ||
- name: Build NextJS | ||
run: npm run export --prefix nextjs-testapp | ||
- name: Deploy to s3 | ||
uses: eisberg-labs/static-website-to-s3@main | ||
with: | ||
target: nextjs-testapp/out | ||
dest: next-to-s3/nextjs-testapp | ||
exclusions: ^nextjs-testapp\/out\/(index).html$ | ||
bucket: ${{ secrets.BUCKET }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2022 Eisberg Labs <ana@eisberg-labs.com> (www.eisberg-labs.com) | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Static website to S3 Github action | ||
> This action will deploy your static website to S3 without the html extension. | ||
I tested only with NextJS exported website, but I don't see any reason why it shouldn't work | ||
with other setups. If it's not working for you, [please report an issue](https://github.com/eisberg-labs/static-website-to-s3/issues). | ||
|
||
## Prerequisite | ||
|
||
You have configured your S3 bucket for [static website hosting](https://www.amarjanica.com/host-a-nextjs-static-website-on-s3#Configure_S3_Bucket_for_static_website_hosting). | ||
|
||
## Usage | ||
|
||
Define AWS_DEFAULT_REGION, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables. | ||
This action should be run after the static website is built: | ||
|
||
```yaml | ||
- name: Deploy to s3 | ||
uses: eisberg-labs/static-website-to-s3@main | ||
with: | ||
target: nextjs-testapp/out | ||
dest: next-to-s3/nextjs-testapp | ||
exclusions: ^nextjs-testapp\/out\/(index|404).html$ | ||
bucket: ${{ secrets.BUCKET }} | ||
``` | ||
## Example | ||
There's an example action at [Actions](https://github.com/eisberg-labs/static-website-to-s3/actions), | ||
and [configuration file](.github/workflows/deploy-nextjs.yml) testing the NextJS build. | ||
## License | ||
MIT © [Eisberg Labs](http://www.eisberg-labs.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: "Deploy static website to S3" | ||
description: "Deploys static website to S3 without html extension. Works for NextJS." | ||
author: "Ana Bujan - Eisberg Labs" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: unfor19/install-aws-cli-action@v1 | ||
- run: ./deploy-doc-to-s3.sh "${{inputs.target}}" "${{inputs.exclusions}}" "${{inputs.bucket}}" "${{inputs.dest}}" | ||
shell: bash | ||
inputs: | ||
target: | ||
description: 'Location of static website' | ||
required: false | ||
default: '' | ||
exclusions: | ||
description: 'Regex pattern for files to be excluded from extension removal' | ||
required: false | ||
default: '' | ||
bucket: | ||
description: 'Bucket name' | ||
required: true | ||
dest: | ||
description: 'Destination directory path' | ||
required: true | ||
branding: | ||
icon: "upload-cloud" | ||
color: "blue" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
# Exit immediately if a command exits with a non zero status | ||
set -e | ||
# Treat unset variables as an error when substituting | ||
set -u | ||
|
||
function remove_html_extension() { | ||
TARGET=$1 | ||
EXCLUDES_REGEX=$2 | ||
|
||
for filename in $TARGET/*.html; do | ||
# File is html and not in $EXCLUDES_REGEX files | ||
if [[ $filename =~ ^.+\.html$ && ! $filename =~ $EXCLUDES_REGEX ]]; then | ||
original="$filename" | ||
# Get the filename without the path/extension | ||
filename=$(basename "$filename") | ||
extension="${filename##*.}" | ||
filename="${filename%.*}" | ||
|
||
# Move it | ||
mv $original $TARGET/$filename | ||
fi | ||
done | ||
} | ||
|
||
function upload_to_s3() { | ||
TARGET=$1 | ||
BUCKET=$2 | ||
DEST=$3 | ||
## Now upload to s3, deleting any items that no longer exist | ||
aws s3 sync --delete $TARGET s3://$BUCKET/$DEST | ||
## Rename all files without the extension to mimetype text/html | ||
|
||
echo "Uploading to s3://$BUCKET/$DEST" | ||
aws s3 cp \ | ||
s3://$BUCKET/$DEST \ | ||
s3://$BUCKET/$DEST \ | ||
--exclude '*.*' \ | ||
--no-guess-mime-type \ | ||
--content-type="text/html" \ | ||
--metadata-directive="REPLACE" \ | ||
--recursive | ||
} | ||
|
||
function deploy() { | ||
TARGET=$1 | ||
EXCLUDES_REGEX=$2 | ||
BUCKET=$3 | ||
DEST=$4 | ||
|
||
remove_html_extension $TARGET $EXCLUDES_REGEX | ||
upload_to_s3 $TARGET $BUCKET $DEST | ||
rm -r $TARGET | ||
} | ||
|
||
deploy "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file. | ||
|
||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`. | ||
|
||
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
} | ||
|
||
module.exports = nextConfig |
Oops, something went wrong.