From 372fc1137af5964c1209b298cffbe6ea9a673282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Tue, 24 Sep 2024 22:12:19 +0800 Subject: [PATCH 1/6] feat: deploy to s3 --- .github/workflows/aws-static.yml | 68 ++++++++++++++++++++++++++++++++ client/next.config.js | 4 +- 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/aws-static.yml diff --git a/.github/workflows/aws-static.yml b/.github/workflows/aws-static.yml new file mode 100644 index 00000000..87341dcb --- /dev/null +++ b/.github/workflows/aws-static.yml @@ -0,0 +1,68 @@ +name: Deploy Next.js to AWS S3 + +on: + pull_request: + branches: [ "main" ] + paths: + - .github/workflows/aws-static.yml + - client/** + - assistant/** + +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 # 仅在 ./client 目录下安装 Next.js 项目的依赖项 + + - name: Build Amplify App + run: npm run build + working-directory: ./client # 仅在 ./client 目录下构建 Next.js 应用程序 + + - name: Zip Build Folder + run: zip -r build.zip out + working-directory: ./client + + - name: Upload Build to S3 + run: | + aws s3 cp ./client/build.zip s3://${{ env.S3_BUCKET }}/builds/${{ github.sha }}.zip + diff --git a/client/next.config.js b/client/next.config.js index 21fb5224..f2af2e89 100644 --- a/client/next.config.js +++ b/client/next.config.js @@ -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 } :{}, webpack: (config, { dev}) => { config.resolve.fallback = { http: false, https: false, net: false, tls: false }; @@ -32,7 +32,7 @@ module.exports = withSentryConfig(nextConfig, { silent: false, // Can be used to suppress logs hideSourceMaps: true, - + sourcemaps: { disable: true, }, From 2a0efbbaa9fc93f45e6c5c1a77f360c41feaf022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Tue, 24 Sep 2024 22:22:03 +0800 Subject: [PATCH 2/6] feat: using s3 sync --- .github/workflows/aws-static.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/aws-static.yml b/.github/workflows/aws-static.yml index 87341dcb..e9635c40 100644 --- a/.github/workflows/aws-static.yml +++ b/.github/workflows/aws-static.yml @@ -52,17 +52,15 @@ jobs: - name: Install Dependencies run: npm install - working-directory: ./client # 仅在 ./client 目录下安装 Next.js 项目的依赖项 + working-directory: ./client - name: Build Amplify App run: npm run build - working-directory: ./client # 仅在 ./client 目录下构建 Next.js 应用程序 - - - name: Zip Build Folder - run: zip -r build.zip out working-directory: ./client - name: Upload Build to S3 + working-directory: ./client run: | - aws s3 cp ./client/build.zip s3://${{ env.S3_BUCKET }}/builds/${{ github.sha }}.zip + aws s3 sync ./out s3://${{ env.S3_BUCKET }} + From ada08b306adde90c89e8519bcd3d8cd01e63578f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Tue, 24 Sep 2024 23:08:59 +0800 Subject: [PATCH 3/6] feat: using s3 sync --- .github/workflows/aws-static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws-static.yml b/.github/workflows/aws-static.yml index e9635c40..950bc02d 100644 --- a/.github/workflows/aws-static.yml +++ b/.github/workflows/aws-static.yml @@ -61,6 +61,6 @@ jobs: - name: Upload Build to S3 working-directory: ./client run: | - aws s3 sync ./out s3://${{ env.S3_BUCKET }} + aws s3 sync ./out s3://${{ env.S3_BUCKET }} --content-type 'text/html' From 566874fa8882ddb99a933b2f84cfe35149be1c41 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Wed, 25 Sep 2024 11:33:41 +0800 Subject: [PATCH 4/6] fix: clone without .html --- .github/workflows/aws-static.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/aws-static.yml b/.github/workflows/aws-static.yml index 950bc02d..c7883c0c 100644 --- a/.github/workflows/aws-static.yml +++ b/.github/workflows/aws-static.yml @@ -61,6 +61,9 @@ jobs: - 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' From 451a9feaa574fee5d4b419d02582824f5651b739 Mon Sep 17 00:00:00 2001 From: yingying Date: Wed, 25 Sep 2024 16:16:09 +0800 Subject: [PATCH 5/6] chore: test --- client/app/factory/edit/page.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/app/factory/edit/page.tsx b/client/app/factory/edit/page.tsx index acdaf292..26da9085 100644 --- a/client/app/factory/edit/page.tsx +++ b/client/app/factory/edit/page.tsx @@ -53,11 +53,11 @@ export default function Edit() { const [gitUrl, setGitUrl] = React.useState(''); 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, From 3a01c034c2117d73b12c97667c4bcb3c3f45b9c5 Mon Sep 17 00:00:00 2001 From: yingying Date: Wed, 25 Sep 2024 21:28:53 +0800 Subject: [PATCH 6/6] chore: fix path --- client/app/factory/list/components/BotCard.tsx | 4 ++-- client/components/BotCard.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/app/factory/list/components/BotCard.tsx b/client/app/factory/list/components/BotCard.tsx index 36c5fb71..347f4171 100644 --- a/client/app/factory/list/components/BotCard.tsx +++ b/client/app/factory/list/components/BotCard.tsx @@ -113,7 +113,7 @@ const BotCard = (props: { bot: Bot }) => { }} > {I18N.components.BotCard.tiaoShi} router.push(`/factory/edit?id=${bot.id}`)} className="z-10 cursor-pointer" @@ -135,7 +135,7 @@ const BotCard = (props: { bot: Bot }) => { }} > {I18N.components.BotCard.gengXinZhiShi} diff --git a/client/components/BotCard.tsx b/client/components/BotCard.tsx index 2e72dc60..b5e58365 100644 --- a/client/components/BotCard.tsx +++ b/client/components/BotCard.tsx @@ -41,7 +41,7 @@ const BotCard = (props: {
- +