diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..082452c5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +# Frontend +frontend/Dockerfile +frontend/**/node_modules +frontend/app/.next +frontend/app/.swc +frontend/packages/*/dist diff --git a/docker-compose.yml b/docker-compose.yml index 8ce472cb..9b5decd1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,8 @@ services: frontend: image: tidb.ai/frontend:local build: - context: ./frontend + context: . + dockerfile: frontend/Dockerfile restart: always ports: - 3000:3000 diff --git a/frontend/.dockerignore b/frontend/.dockerignore deleted file mode 100644 index 759ea3c2..00000000 --- a/frontend/.dockerignore +++ /dev/null @@ -1,8 +0,0 @@ -node_modules -.next -.git -.idea -Dockerfile - -app/.env -app/certificates diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 5a26a047..528d6d54 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -7,14 +7,17 @@ RUN apk add --no-cache libc6-compat WORKDIR /tidb.ai -RUN mkdir app -RUN mkdir -p packages/widget-react +RUN mkdir -p frontend/app +RUN mkdir -p frontend/packages/widget-react # Install dependencies based on the preferred package manager -COPY package.json . -COPY pnpm-*.yaml . -COPY app/package.json ./app -COPY packages/widget-react/package.json ./packages/widget-react +COPY README.md . +COPY frontend/package.json ./frontend +COPY frontend/pnpm-*.yaml ./frontend +COPY frontend/app/package.json ./frontend/app +COPY frontend/packages/widget-react/package.json ./frontend/packages/widget-react + +WORKDIR /tidb.ai/frontend RUN corepack enable pnpm RUN pnpm i --frozen-lockfile @@ -23,13 +26,17 @@ RUN pnpm i --frozen-lockfile # 2. Rebuild the source code only when needed FROM base AS builder WORKDIR /tidb.ai -COPY --from=deps /tidb.ai/node_modules ./node_modules -COPY --from=deps /tidb.ai/app/node_modules ./app/node_modules -COPY --from=deps /tidb.ai/packages/widget-react/node_modules ./packages/widget-react/node_modules +COPY --from=deps /tidb.ai/frontend/node_modules ./frontend/node_modules +COPY --from=deps /tidb.ai/frontend/app/node_modules ./frontend/app/node_modules +COPY --from=deps /tidb.ai/frontend/packages/widget-react/node_modules ./frontend/packages/widget-react/node_modules +# For symbol link of root README.md COPY . . + # This will do the trick, use the corresponding env file for each environment. #COPY .env.production.sample .env.production +WORKDIR /tidb.ai/frontend + ENV BASE_URL "" ENV NEXT_PUBLIC_BASE_URL "" ENV SITE_URL "" @@ -55,14 +62,12 @@ RUN adduser -S nextjs -u 1001 # Automatically leverage output traces to reduce image size # https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=builder --chown=nextjs:nodejs /tidb.ai/app/.next/standalone . -COPY --from=builder --chown=nextjs:nodejs /tidb.ai/app/.next/static app/.next/static - -COPY --from=builder /tidb.ai/app/public app/public +COPY --from=builder --chown=nextjs:nodejs /tidb.ai/frontend/app/.next/standalone . +COPY --from=builder --chown=nextjs:nodejs /tidb.ai/frontend/app/.next/static app/.next/static +COPY --from=builder /tidb.ai/frontend/app/public frontend/app/public USER nextjs EXPOSE 3000 - CMD node app/server.js diff --git a/frontend/app/package.json b/frontend/app/package.json index f63282fe..4236b2f6 100644 --- a/frontend/app/package.json +++ b/frontend/app/package.json @@ -5,7 +5,6 @@ "scripts": { "dev": "next dev --experimental-https", "dev:local": "next dev", - "postinstall": "cp ../../README.md src/pages/docs/README.md", "build": "next build && next-sitemap", "build:standalone": "STANDALONE=1 next build --no-lint && next-sitemap", "start": "next start", diff --git a/frontend/app/src/pages/docs/.gitignore b/frontend/app/src/pages/docs/.gitignore deleted file mode 100644 index 8841e9e9..00000000 --- a/frontend/app/src/pages/docs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# This file should be copied by package.json's "postinstall" command -README.md diff --git a/frontend/app/src/pages/docs/README.md b/frontend/app/src/pages/docs/README.md new file mode 120000 index 00000000..1dfab242 --- /dev/null +++ b/frontend/app/src/pages/docs/README.md @@ -0,0 +1 @@ +../../../../../README.md \ No newline at end of file diff --git a/frontend/app/theme.config.tsx b/frontend/app/theme.config.tsx index 7b865519..33a01c79 100644 --- a/frontend/app/theme.config.tsx +++ b/frontend/app/theme.config.tsx @@ -2,7 +2,7 @@ import { useRouter } from 'next/router'; import { useConfig, DocsThemeConfig, Link } from 'nextra-theme-docs'; let themeConfig: DocsThemeConfig = { - docsRepositoryBase: 'https://github.com/pingcap/tidb.ai/tree/main/www', + docsRepositoryBase: 'https://github.com/pingcap/tidb.ai/tree/main/frontend/app', useNextSeoProps () { return { titleTemplate: '%s - RAG app by TiDB ',