diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 000000000..9d937ea61 --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -0,0 +1,25 @@ +name: Build and Push to Alibaba Cloud Registry + +on: + push: + branches: + - develop + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Alibaba Cloud Docker Registry + run: docker login --username=${{ secrets.ALI_DOCKER_USERNAME }} registry.cn-beijing.aliyuncs.com --password=${{ secrets.ALI_DOCKER_PASSWORD }} + + - name: Build and push Docker image + run: | + docker build -t registry.cn-beijing.aliyuncs.com/bieber/teable:${GITHUB_SHA} -f dockers/teable/Dockerfile . + docker push registry.cn-beijing.aliyuncs.com/bieber/teable:${GITHUB_SHA} diff --git a/apps/nextjs-app/src/backend/api/rest/table.ssr.ts b/apps/nextjs-app/src/backend/api/rest/table.ssr.ts index 3e2755163..152836f3a 100644 --- a/apps/nextjs-app/src/backend/api/rest/table.ssr.ts +++ b/apps/nextjs-app/src/backend/api/rest/table.ssr.ts @@ -1,6 +1,7 @@ import type { ITableFullVo, ITableListVo, IRecord } from '@teable-group/core'; import { FieldKeyType, HttpError } from '@teable-group/core'; import type { IGetBaseVo } from '@teable-group/openapi'; +import type { IUser } from '@teable-group/sdk'; import axios from 'axios'; export class SsrApi { @@ -54,6 +55,14 @@ export class SsrApi { async getBaseById(baseId: string) { return await this.axios.get(`/base/${baseId}`).then(({ data }) => data); } + + async getUserMe(cookie?: string) { + return await this.axios + .get(`/auth/user/me`, { + headers: { cookie }, + }) + .then(({ data }) => data); + } } export const ssrApi = new SsrApi(); diff --git a/apps/nextjs-app/src/pages/_app.tsx b/apps/nextjs-app/src/pages/_app.tsx index cb056c4e6..206bcbd22 100644 --- a/apps/nextjs-app/src/pages/_app.tsx +++ b/apps/nextjs-app/src/pages/_app.tsx @@ -1,6 +1,5 @@ import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'; import { HttpError, parseDsn } from '@teable-group/core'; -import { axios } from '@teable-group/openapi'; import type { IUser } from '@teable-group/sdk'; import dayjs from 'dayjs'; import timezone from 'dayjs/plugin/timezone'; @@ -12,6 +11,7 @@ import Head from 'next/head'; import { appWithTranslation } from 'next-i18next'; import type { ReactElement, ReactNode } from 'react'; import { z } from 'zod'; +import { ssrApi } from '@/backend/api/rest/table.ssr'; import { colors } from '@/themes/colors'; import { INITIAL_THEME } from '@/themes/initial'; import { getColorsCssVariablesText } from '@/themes/utils'; @@ -97,24 +97,20 @@ MyApp.getInitialProps = async (appContext: AppContext) => { // calls page's `getInitialProps` and fills `appProps.pageProps` const appProps = await App.getInitialProps(appContext); const res = appContext.ctx.res; - const host = appContext.ctx.req?.headers.host || ''; const isLoginPage = appContext.ctx.pathname.startsWith('/auth/login'); if (!res || !res?.writeHead) { return appProps; } - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const { driver } = parseDsn(process.env.PRISMA_DATABASE_URL!); + const { driver } = parseDsn(process.env.PRISMA_DATABASE_URL as string); const initialProps = { ...appProps, driver, }; try { - const user = await axios.get(`http://${host}/api/auth/user/me`, { - headers: { cookie: appContext.ctx.req?.headers.cookie }, - }); + const user = await ssrApi.getUserMe(appContext.ctx.req?.headers.cookie); // Already logged in if (user && isLoginPage) { res.writeHead(302, { @@ -122,7 +118,7 @@ MyApp.getInitialProps = async (appContext: AppContext) => { }); return res.end(); } - return { ...initialProps, user: user.data }; + return { ...initialProps, user }; } catch (error) { if (error instanceof HttpError && !isLoginPage) { const redirect = encodeURIComponent(appContext.ctx.req?.url || ''); @@ -132,6 +128,7 @@ MyApp.getInitialProps = async (appContext: AppContext) => { }); return res.end(); } + console.error(error); } return initialProps; diff --git a/dockers/integration-test.yml b/dockers/integration-test.yml index 55e7bccd1..0d137a204 100644 --- a/dockers/integration-test.yml +++ b/dockers/integration-test.yml @@ -5,6 +5,7 @@ services: container_name: integration-test build: context: ../ + dockerfile: ./dockers/teable/Dockerfile target: builder args: INTEGRATION_TEST: 1 diff --git a/Dockerfile b/dockers/teable/Dockerfile similarity index 100% rename from Dockerfile rename to dockers/teable/Dockerfile