Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy to s3 #411

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/aws-static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Deploy Next.js to AWS S3

on:
pull_request:
branches: [ "main" ]
paths:
- .github/workflows/aws-static.yml
- client/**
- assistant/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the AWS credentials used here are securely stored and not hard-coded. Consider using GitHub Secrets for sensitive information.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

展开说说

env:
AWS_REGION: ${{ vars.AWS_REGION }}
NEXT_PUBLIC_API_DOMAIN: ${{ vars.NEXT_PUBLIC_API_DOMAIN }}
AMPLIFY_APP_ID: ${{ vars.AMPLIFY_APP_ID }}
S3_BUCKET: ${{ vars.S3_BUCKET }}
NEXT_STANDALONE: "true"

permissions:
id-token: write
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache node modules
uses: actions/cache@v2
with:
path: client/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('client/**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::654654285942:role/Github-OIDC
audience: sts.amazonaws.com
aws-region: ${{ env.AWS_REGION }}

- name: Install Dependencies
run: npm install
working-directory: ./client

- name: Build Amplify App
run: npm run build
working-directory: ./client

- name: Upload Build to S3
working-directory: ./client
run: |
find out -type f -name '*.html' | while read file; do
cp "$file" "${file%.html}"
done
aws s3 sync ./out s3://${{ env.S3_BUCKET }} --content-type 'text/html'


10 changes: 5 additions & 5 deletions client/app/factory/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export default function Edit() {
const [gitUrl, setGitUrl] = React.useState<string>('');
const apiDomain = process.env.NEXT_PUBLIC_API_DOMAIN;

useEffect(() => {
if (!user || status !== 'success' || user.id.startsWith('client|')) {
router.push(`${apiDomain}/api/auth/login`);
}
}, [user, status]);
// useEffect(() => {
// if (!user || status !== 'success' || user.id.startsWith('client|')) {
// router.push(`${apiDomain}/api/auth/login`);
// }
// }, [user, status]);

const {
updateBot: onUpdateBot,
Expand Down
4 changes: 2 additions & 2 deletions client/app/factory/list/components/BotCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const BotCard = (props: { bot: Bot }) => {
}}
>
<Image
src="../images/debug.svg"
src="/images/debug.svg"
alt={I18N.components.BotCard.tiaoShi}
onClick={() => router.push(`/factory/edit?id=${bot.id}`)}
className="z-10 cursor-pointer"
Expand All @@ -135,7 +135,7 @@ const BotCard = (props: { bot: Bot }) => {
}}
>
<Image
src="../images/refresh.svg"
src="/images/refresh.svg"
alt={I18N.components.BotCard.gengXinZhiShi}
className="z-10 cursor-pointer"
/>
Expand Down
2 changes: 1 addition & 1 deletion client/components/BotCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const BotCard = (props: {
</div>
</div>
<div className="z-10 opacity-0 rounded-[8px] hover:opacity-100 w-full h-full backdrop-blur-xl transition-all bg-gradient-to-b from-[rgba(255,255,255,0.65)] to-white absolute flex items-center justify-center">
<Image src="./images/chat.svg" />
<Image src="/images/chat.svg" />
</div>
</CardBody>
<CardFooter className="text-small justify-between flex-col my-4 p-0 px-3 min-h-[84px]">
Expand Down
4 changes: 2 additions & 2 deletions client/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { withSentryConfig } = require("@sentry/nextjs");


const nextConfig = {
...process.env.NEXT_STANDALONE ? { output: "standalone" } :{},
...process.env.NEXT_STANDALONE ? { output: "export", ssr: false } :{},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting ssr: false might have unintended side effects if your application relies on server-side rendering. Ensure this change is thoroughly tested.

webpack: (config, { dev}) => {
config.resolve.fallback = { http: false, https: false, net: false, tls: false };

Expand All @@ -32,7 +32,7 @@ module.exports = withSentryConfig(nextConfig, {
silent: false, // Can be used to suppress logs

hideSourceMaps: true,

sourcemaps: {
disable: true,
},
Expand Down
Loading