Skip to content

Commit

Permalink
image (#23)
Browse files Browse the repository at this point in the history
* image

* env

* standalone

* test
  • Loading branch information
c121914yu authored Jan 30, 2024
1 parent 725ef35 commit 54c1857
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 37 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/fastgpt-home-image.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Build xiaoyi page images in Personal warehouse
name: Build fastgpt page images in Personal warehouse
on:
workflow_dispatch:
push:
paths:
- 'projects/xiaoyi/**'
- 'projects/fastgpt/**'
branches:
- 'main'
jobs:
Expand Down Expand Up @@ -33,12 +33,12 @@ jobs:
password: ${{ secrets.GH_PAT }}
- name: Set DOCKER_REPO_TAGGED based on branch or tag
run: |
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-home:xiaoyi" >> $GITHUB_ENV
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-home:latest" >> $GITHUB_ENV
- name: Build and publish image for main branch or tag push event
env:
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
run: |
cd projects/xiaoyi && docker buildx build \
cd projects/fastgpt && docker buildx build \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \
--label "org.opencontainers.image.description=fastgpt-home image" \
--push \
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/xiaoyi-home-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build xiaoyi page images in Personal warehouse
on:
workflow_dispatch:
push:
paths:
- 'projects/xiaoyi/**'
branches:
- 'main'
jobs:
build-fastgpt-images:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}
- name: Set DOCKER_REPO_TAGGED based on branch or tag
run: |
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-home:xiaoyi" >> $GITHUB_ENV
- name: Build and publish image for main branch or tag push event
env:
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
run: |
cd projects/xiaoyi && docker buildx build \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \
--label "org.opencontainers.image.description=fastgpt-home image" \
--push \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache \
-t ${DOCKER_REPO_TAGGED} \
-f Dockerfile \
.
56 changes: 56 additions & 0 deletions projects/fastgpt/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Install dependencies only when needed
FROM node:18.15-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add libc6-compat && npm install -g pnpm
WORKDIR /app

# copy packages and one project
COPY package.json pnpm-lock.yaml ./

RUN [ -f pnpm-lock.yaml ] || (echo "Lockfile not found." && exit 1)

RUN pnpm install

# Rebuild the source code only when needed
FROM node:18.15-alpine AS builder
WORKDIR /app

# copy common node_modules and one project node_modules
COPY . .
COPY --from=deps /app/node_modules ./node_modules

# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1
ENV OUTPUT_MODE standalone
RUN npm install -g pnpm
RUN pnpm run build

FROM node:18.15-alpine AS runner
WORKDIR /app

# create user and use it
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

RUN sed -i 's/https/http/' /etc/apk/repositories
RUN apk add curl \
&& apk add ca-certificates \
&& update-ca-certificates

# copy running files
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js ./next.config.js
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
ENV PORT=3000

EXPOSE 3000

USER nextjs

ENV serverPath=./server.js

ENTRYPOINT ["sh","-c","node ${serverPath}"]
13 changes: 12 additions & 1 deletion projects/fastgpt/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@ const { i18n } = require('./next-i18next.config');

const nextConfig = {
i18n,
// output: 'export',
output: process.env.OUTPUT_MODE,
reactStrictMode: process.env.NODE_ENV === 'development' ? false : true,
compress: true,

async rewrites() {
return process.env.OUTPUT_MODE === 'standalone'
? [
{
source: '/standalone',
destination: '/'
}
]
: [];
},

webpack(config, { isServer }) {
config.module = {
...config.module,
Expand Down
1 change: 1 addition & 0 deletions projects/fastgpt/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@
},
"slogan": "Improving AI's Ability\nTo Grasp Your Knowledge"
},
"meta desc": "FastGPT is a knowledge-based platform built on the LLM, offers out-of-the-box data processing and model invocation capabilities, allows for workflow orchestration through Flow visualization!",
"module": {
"Confirm Delete Module": "Confirm to delete the custom module?",
"Confirm Sync Plugin": "Confirm the latest sync plugin information? The plug-in connection and input content will be cleared, please confirm!",
Expand Down
1 change: 1 addition & 0 deletions projects/fastgpt/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@
},
"slogan": "让 AI 更懂你的知识"
},
"meta desc": "FastGPT 是一个大模型应用编排系统,提供开箱即用的数据处理、模型调用等能力,可以快速的构建知识库并通过 Flow 可视化进行工作流编排,实现复杂的知识库场景!",
"module": {
"Confirm Delete Module": "确认删除该自定义模块?",
"Confirm Sync Plugin": "确认同步插件最新信息?插件的连线和输入的内容将会被清空,请确认!",
Expand Down
7 changes: 2 additions & 5 deletions projects/fastgpt/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import '@/web/styles/reset.scss';

function App({ Component, pageProps }: AppProps) {
const router = useRouter();
const { i18n } = useTranslation();
const { t, i18n } = useTranslation();

useEffect(() => {
// get default language
Expand All @@ -28,10 +28,7 @@ function App({ Component, pageProps }: AppProps) {
<>
<Head>
<title>FastGPT</title>
<meta
name="description"
content={`FastGPT 是一个大模型应用编排系统,提供开箱即用的数据处理、模型调用等能力,可以快速的构建知识库并通过 Flow 可视化进行工作流编排,实现复杂的知识库场景!`}
/>
<meta name="description" content={t('meta desc')} />
<meta
name="viewport"
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no, viewport-fit=cover"
Expand Down
17 changes: 0 additions & 17 deletions projects/fastgpt/src/pages/index.module.scss

This file was deleted.

19 changes: 9 additions & 10 deletions projects/fastgpt/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import React, { useRef } from 'react';
import { Box } from '@chakra-ui/react';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';

import Navbar from './components/Navbar';
import Hero from './components/Hero';
import Ability from './components/Ability';
import Choice from './components/Choice';
import Footer from './components/Footer';
import Navbar from '@/components/home/Navbar';
import Hero from '@/components/home/Hero';
import Ability from '@/components/home/Ability';
import Choice from '@/components/home/Choice';
import Footer from '@/components/home/Footer';
import { UserConfig } from 'next-i18next';

const Home = (e: {
Expand Down Expand Up @@ -45,8 +45,9 @@ const Home = (e: {
</>
);
};
export default Home;

export async function getStaticProps({ locale }: any) {
export const getStaticProps = async ({ locale }: any) => {
return {
props: {
beian: process.env.BEIAN || '',
Expand All @@ -56,6 +57,4 @@ export async function getStaticProps({ locale }: any) {
...(await serverSideTranslations(locale))
}
};
}

export default Home;
};
60 changes: 60 additions & 0 deletions projects/fastgpt/src/pages/standalone.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { useRef } from 'react';
import { Box } from '@chakra-ui/react';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';

import Navbar from '@/components/home/Navbar';
import Hero from '@/components/home/Hero';
import Ability from '@/components/home/Ability';
import Choice from '@/components/home/Choice';
import Footer from '@/components/home/Footer';
import { UserConfig } from 'next-i18next';

const Home = (e: {
_nextI18Next?:
| {
initialI18nStore: any;
initialLocale: string;
ns: string[];
userConfig: UserConfig | null;
}
| undefined;
beian: string;
docUrl: string;
statusUrl: string;
cloudDomain: string;
}) => {
const { beian, docUrl, statusUrl, cloudDomain } = e;

return (
<>
<Box id="home" bg={'myWhite.600'} h={'100vh'} overflowY={'auto'} overflowX={'hidden'}>
<Box position={'fixed'} zIndex={10} top={0} left={0} right={0}>
<Navbar docUrl={docUrl} cloudDomain={cloudDomain} />
</Box>
<Box maxW={'1200px'} pt={'70px'} m={'auto'}>
<Hero cloudDomain={cloudDomain} />
<Ability />
<Box my={[4, 6]}>
<Choice />
</Box>
</Box>
<Box bg={'white'}>
<Footer beian={beian} docUrl={docUrl} statusUrl={statusUrl} cloudDomain={cloudDomain} />
</Box>
</Box>
</>
);
};
export default Home;

export const getServerSideProps = async ({ locale }: any) => {
return {
props: {
beian: process.env.BEIAN || '',
docUrl: process.env.DOC_URL || '',
statusUrl: process.env.STATUS_URL || '',
cloudDomain: process.env.CLOUD_DOMAIN || 'https://cloud.fastgpt.in',
...(await serverSideTranslations(locale))
}
};
};

0 comments on commit 54c1857

Please sign in to comment.