build: production docker image (#112)

* build: heroku support

* build: production docker image
This commit is contained in:
tea artist 2023-07-31 19:34:16 +08:00 committed by GitHub
parent 650085731b
commit 3c399e4a9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 58 additions and 44 deletions

View File

@ -14,8 +14,8 @@
# ignore: all **/node_modules folders and .yarn/cache #
###################################################################
ARG NODE_VERSION=16
ARG ALPINE_VERSION=3.15
ARG NODE_VERSION=18
ARG ALPINE_VERSION=3.18
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS deps
RUN apk add --no-cache rsync
@ -24,6 +24,7 @@ WORKDIR /workspace-install
COPY yarn.lock .yarnrc.yml ./
COPY .yarn/ ./.yarn/
COPY sh/ ./sh/
# Specific to monerepo's as docker COPY command is pretty limited
# we use buidkit to prepare all files that are necessary for install
@ -34,17 +35,18 @@ COPY .yarn/ ./.yarn/
# - All package.json present in the host (root, apps/*, packages/*)
# - All schema.prisma (cause prisma will generate a schema on postinstall)
#
RUN --mount=type=bind,target=/docker-context \
rsync -amv --delete \
COPY . /workspace-install
RUN rsync -amv --delete \
--exclude='node_modules' \
--exclude='*/node_modules' \
--include='package.json' \
--include='schema.prisma' \
--include='.env' \
--include='*/' --exclude='*' \
/docker-context/ /workspace-install/;
/workspace-install/ /workspace-install/
# @see https://www.prisma.io/docs/reference/api-reference/environment-variables-reference#cli-binary-targets
ENV PRISMA_CLI_BINARY_TARGETS=linux-musl
# ENV PRISMA_CLI_BINARY_TARGETS=linux-musl
#
# To speed up installations, we override the default yarn cache folder
@ -60,9 +62,7 @@ ENV PRISMA_CLI_BINARY_TARGETS=linux-musl
# Does not play well with buildkit on CI
# https://github.com/moby/buildkit/issues/1673
RUN --mount=type=cache,target=/root/.yarn3-cache,id=yarn3-cache \
YARN_CACHE_FOLDER=/root/.yarn3-cache \
yarn install --immutable --inline-builds
RUN yarn install --immutable --inline-builds
###################################################################
@ -80,14 +80,12 @@ COPY . .
COPY --from=deps /workspace-install ./
# Optional: if the app depends on global /static shared assets like images, locales...
RUN yarn workspace nextjs-app share-static-hardlink && yarn workspace nextjs-app build
RUN yarn workspace @teable-group/app share-static-hardlink && yarn g:build
RUN yarn workspace @teable-group/db-main-prisma prisma-db-push
# Does not play well with buildkit on CI
# https://github.com/moby/buildkit/issues/1673
RUN --mount=type=cache,target=/root/.yarn3-cache,id=yarn3-cache \
SKIP_POSTINSTALL=1 \
YARN_CACHE_FOLDER=/root/.yarn3-cache \
yarn workspaces focus nextjs-app --production
RUN SKIP_POSTINSTALL=1 \
yarn workspaces focus --production -A
###################################################################
# Stage 3: Extract a minimal image from the build #
@ -99,40 +97,50 @@ WORKDIR /app
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
# RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
COPY --from=builder /app/apps/nextjs-app/next.config.mjs \
COPY --from=builder /app/apps/nextjs-app/next.config.js \
/app/apps/nextjs-app/next-i18next.config.js \
/app/apps/nextjs-app/package.json \
/app/apps/nextjs-app/.env \
./apps/nextjs-app/
COPY --from=builder /app/apps/nextjs-app/public ./apps/nextjs-app/public
COPY --from=builder --chown=nextjs:nodejs /app/apps/nextjs-app/.next ./apps/nextjs-app/.next
COPY --from=builder /app/apps/nestjs-backend/package.json ./apps/nestjs-backend/
COPY --from=builder /app/apps/nextjs-app/.next ./apps/nextjs-app/.next
COPY --from=builder /app/apps/nestjs-backend/package.json ./apps/nestjs-backend/
COPY --from=builder /app/apps/nestjs-backend/dist ./apps/nestjs-backend/dist
COPY --from=builder /app/packages/core/ ./packages/core/
COPY --from=builder /app/packages/db-main-prisma/ ./packages/db-main-prisma/
COPY --from=builder /app/packages/common-i18n/ ./packages/common-i18n/
COPY --from=builder /app/packages/openapi/ ./packages/openapi/
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
USER nextjs
# USER nextjs
EXPOSE ${NEXTJS_APP_PORT:-3000}
ENV PORT=3000
EXPOSE ${PORT:-3000}
ENV NEXT_TELEMETRY_DISABLED 1
CMD ["./node_modules/.bin/next", "start", "apps/nextjs-app/", "-p", "${NEXTJS_APP_PORT:-3000}"]
WORKDIR /app/apps/nestjs-backend
CMD ["node", "./dist"]
###################################################################
# Optional: develop locally #
###################################################################
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS develop
ENV NODE_ENV=development
# FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS develop
# ENV NODE_ENV=development
WORKDIR /app
# WORKDIR /app
COPY --from=deps /workspace-install ./
# COPY --from=deps /workspace-install ./
EXPOSE ${NEXTJS_APP_PORT:-3000}
# EXPOSE ${PORT:-3000}
WORKDIR /app/apps/nextjs-app
CMD ["yarn", "dev", "-p", "${NEXTJS_APP_PORT:-3000}"]
# WORKDIR /app/apps/nextjs-app
# CMD ["yarn", "dev", "-p", "${PORT:-3000}"]

1
Procfile Normal file
View File

@ -0,0 +1 @@
web: yarn app:start

View File

@ -51,6 +51,7 @@
},
"devDependencies": {
"@faker-js/faker": "8.0.2",
"@nestjs/cli": "10.1.10",
"@nestjs/testing": "9.3.9",
"@teable-group/eslint-config-bases": "workspace:^",
"@types/cors": "2.8.12",

View File

@ -57,7 +57,7 @@ export class WorkflowTriggerService {
const result = await (prisma || this.prisma).$transaction(async (tx) => {
return tx.automationWorkflowTrigger.deleteMany({
where: { triggerId, OR: { workflowId } },
where: { triggerId, OR: [{ workflowId }] },
});
});

View File

@ -124,7 +124,6 @@
"@tanstack/react-query": "4.13.0",
"@teable-group/common-i18n": "workspace:^",
"@teable-group/core": "workspace:^",
"@teable-group/db-main-prisma": "workspace:^",
"@teable-group/openapi": "workspace:^",
"@teable-group/sdk": "workspace:^",
"@teable/sharedb": "3.3.11",

View File

@ -7,14 +7,15 @@ import {
DropdownMenuRadioItem,
DropdownMenuTrigger,
} from '@teable-group/ui-lib/shadcn/ui/dropdown-menu';
import classNames from 'classnames';
export const ThemePicker: React.FC<{ className?: string }> = ({ className }) => {
const { theme, isAutoTheme, setTheme } = useTheme();
const value = isAutoTheme ? '' : theme;
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button className={className} size={'xs'} variant="ghost">
{value || 'auto'}
<Button className={classNames('capitalize', className)} size={'xs'} variant="ghost">
{value || 'system'}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56">
@ -27,6 +28,7 @@ export const ThemePicker: React.FC<{ className?: string }> = ({ className }) =>
{[ThemeKey.Light, ThemeKey.Dark].map((item) => {
return (
<DropdownMenuRadioItem
className="capitalize"
key={item}
disabled={!isAutoTheme && theme === item}
value={item}
@ -36,7 +38,7 @@ export const ThemePicker: React.FC<{ className?: string }> = ({ className }) =>
);
})}
<DropdownMenuRadioItem disabled={isAutoTheme} value="">
auto
system
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</DropdownMenuContent>

View File

@ -66,7 +66,7 @@ export const AutoPane: React.FC<{
{left}
</Allotment.Pane>
<Allotment.Pane minSize={400}>{center}</Allotment.Pane>
<Allotment.Pane minSize={minSize} preferredSize={200} snap visible={rightVisible}>
<Allotment.Pane minSize={minSize} preferredSize={100} snap visible={rightVisible}>
{right}
</Allotment.Pane>
</Allotment>

View File

@ -7,7 +7,7 @@ import type { NextPageWithLayout } from '../_app';
const Space: NextPageWithLayout = () => {
return (
<div className="grow flex flex-col h-full p-4">
<div className="grow flex flex-col h-full p-4 basis-[600px]">
<h1>Welcome to Teable</h1>
</div>
);

View File

@ -39,7 +39,6 @@
"g:share-static-symlink": "yarn workspaces foreach -pv --include '*-app' run share-static-symlink",
"g:share-static-hardlink": "yarn workspaces foreach -pv --include '*-app' run share-static-hardlink",
"clean:global-cache": "rimraf --no-glob ./.cache",
"app:start": "yarn workspace @teable-group/backend run start",
"apps:build": "yarn workspaces foreach -ptv --include '*-app' run build",
"apps:clean": "yarn workspaces foreach -ptv --include '*-app' run clean",
"packages:build": "yarn workspaces foreach -ptv --include '@teable-group/*' run build",
@ -67,7 +66,7 @@
"check:install": "yarn dlx @yarnpkg/doctor@3.1.4 .",
"check:renovate:config": "docker run -v renovate.json5:/usr/src/app/renovate.json5 -it renovate/renovate renovate-config-validator",
"install:playwright": "playwright install",
"postinstall": "is-ci || yarn husky install",
"postinstall": "node ./sh/postinstall.js",
"generate-openapi-types": "node ./sh/generate-openapi-types.mjs"
},
"helpResolutions": {
@ -103,8 +102,7 @@
},
"engines": {
"node": "^14.13.1 || >=16.0.0",
"yarn": ">=1.22.0",
"npm": "please-use-yarn"
"yarn": ">=1.22.0"
},
"packageManager": "yarn@4.0.0-rc.26"
}

View File

@ -17,8 +17,6 @@ Start the database with `docker-compose up database` then run
```bash
cd packages/db-main-prisma
yarn prisma-db-push
yarn prisma-migrate dev
yarn prisma-migrate-reset
```
> See the .env(.local|.production|.development) file to edit the connection.

View File

@ -34,9 +34,9 @@
"postinstall": "yarn prisma generate"
},
"dependencies": {
"@prisma/client": "4.7.1",
"@prisma/client": "5.0.0",
"dotenv-flow-cli": "1.0.0",
"prisma": "4.7.1"
"prisma": "5.0.0"
},
"devDependencies": {
"@faker-js/faker": "8.0.2",

7
sh/postinstall.js Normal file
View File

@ -0,0 +1,7 @@
if (!process.env.SKIP_POSTINSTALL) {
const isCI = require('is-ci');
const { execSync } = require('child_process');
if (!isCI) {
execSync('yarn husky install', { stdio: 'inherit' });
}
}

BIN
yarn.lock

Binary file not shown.