From 7a15d5589eb2e12aee460ee6b813c3ca6eab71ce Mon Sep 17 00:00:00 2001 From: xudaotutou <13435638964@163.com> Date: Wed, 13 Mar 2024 16:18:06 +0800 Subject: [PATCH] chore(frontend): add prisma cli into prod image (#4586) --- frontend/Dockerfile | 21 +++++++++++---------- frontend/desktop/.dockerignore | 6 ++++-- frontend/desktop/package.json | 7 ++++--- frontend/package.json | 1 + frontend/pnpm-lock.yaml | 12 +++++++++--- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index f1a118a08..98ba347a8 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -14,13 +14,14 @@ FROM node:20.4.0-alpine As base ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" +WORKDIR /app # Install dependencies only when needed FROM base AS deps # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. RUN apk add --no-cache libc6-compat && npm install -g pnpm -WORKDIR /app + # Install dependencies based on the preferred package manager root workspace COPY pnpm-lock.yaml package.json pnpm-workspace.yaml ./ @@ -40,16 +41,12 @@ pnpm -r --offline --filter=./packages/* install \ FROM deps AS builder -WORKDIR /app # COPY --from=deps /app/node_modules ./node_modules # Next.js collects completely anonymous telemetry data about general usage. # Learn more here: https://nextjs.org/telemetry # Uncomment the following line in case you want to disable telemetry during the build. ENV NEXT_TELEMETRY_DISABLED 1 -# RUN npm install -g pnpm - - # COPY --from=deps /app/packages ./packages ARG name @@ -57,11 +54,13 @@ ARG path COPY ${path} ${path} -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm --offline --filter=$name install && pnpm --filter=$name run build - +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm --frozen-lockfile --filter=$name install && pnpm --filter=$name run build +RUN if [ "$name" = "desktop" ]; then \ + cp -r ./desktop/prisma/global/migrations desktop/.next/standalone/desktop/prisma/global/migrations; \ + cp -r ./desktop/prisma/region/migrations desktop/.next/standalone/desktop/prisma/region/migrations; \ +fi # Production image, copy all the files and run next -FROM node:20.4.0-alpine AS runner -WORKDIR /app +FROM base AS runner ENV NODE_ENV production # Uncomment the following line in case you want to disable telemetry during runtime. @@ -81,6 +80,9 @@ ARG path RUN if [ "$name" = "template" ]; then \ apk add --no-cache git openssh-client; \ fi +RUN if [ "$name" = "desktop" ]; then \ + npm install -g prisma; \ +fi USER nextjs # You only need to copy next.config.js if you are NOT using the default configuration @@ -91,7 +93,6 @@ RUN if ["$name" = "objectstorage" ]; then \ COPY --from=builder /app/$path/public ./$path/public COPY --from=builder --chown=nextjs:nodejs /app/$path/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/$path/.next/static ./$path/.next/static - EXPOSE 3000 ENV PORT 3000 diff --git a/frontend/desktop/.dockerignore b/frontend/desktop/.dockerignore index 4094b29f2..acdf44118 100644 --- a/frontend/desktop/.dockerignore +++ b/frontend/desktop/.dockerignore @@ -7,6 +7,8 @@ README.md .git .env.local config.yaml - .yalc/ -yalc.lock \ No newline at end of file +yalc.lock + +prisma/global/generated/ +prisma/region/generated/ \ No newline at end of file diff --git a/frontend/desktop/package.json b/frontend/desktop/package.json index 85c84ebc1..492807757 100644 --- a/frontend/desktop/package.json +++ b/frontend/desktop/package.json @@ -65,7 +65,8 @@ "sharp": "^0.32.6", "uuid": "^9.0.1", "xml2js": "^0.6.2", - "zustand": "^4.4.1" + "zustand": "^4.4.1", + "prisma": "^5.10.2" }, "devDependencies": { "@testing-library/jest-dom": "^6.1.3", @@ -84,8 +85,8 @@ "dotenv-cli": "^7.3.0", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", - "prettier": "^2.8.8", - "prisma": "^5.10.2" + "prettier": "^2.8.8" + }, "pnpm": { "supportedArchitectures": { diff --git a/frontend/package.json b/frontend/package.json index 77c6d6f65..6cfeff59f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -25,6 +25,7 @@ "@chakra-ui/cli": "^2.4.1", "prettier": "^2.8.8" }, + "packageManager": "pnpm@*", "dependencies": { "@chakra-ui/icons": "^2.1.1", "@chakra-ui/system": "^2.6.1", diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index 300e1dff5..320875893 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -153,6 +153,9 @@ importers: nprogress: specifier: ^0.2.0 version: 0.2.0 + prisma: + specifier: ^5.10.2 + version: 5.10.2 qrcode.react: specifier: ^3.1.0 version: 3.1.0(react@18.2.0) @@ -244,9 +247,6 @@ importers: prettier: specifier: ^2.8.8 version: 2.8.8 - prisma: - specifier: ^5.10.2 - version: 5.10.2 packages/client-sdk: dependencies: @@ -8162,9 +8162,11 @@ packages: /@prisma/debug@5.10.2: resolution: {integrity: sha512-bkBOmH9dpEBbMKFJj8V+Zp8IZHIBjy3fSyhLhxj4FmKGb/UBSt9doyfA6k1UeUREsMJft7xgPYBbHSOYBr8XCA==} + dev: false /@prisma/engines-version@5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9: resolution: {integrity: sha512-uCy/++3Jx/O3ufM+qv2H1L4tOemTNqcP/gyEVOlZqTpBvYJUe0tWtW0y3o2Ueq04mll4aM5X3f6ugQftOSLdFQ==} + dev: false /@prisma/engines@5.10.2: resolution: {integrity: sha512-HkSJvix6PW8YqEEt3zHfCYYJY69CXsNdhU+wna+4Y7EZ+AwzeupMnUThmvaDA7uqswiHkgm5/SZ6/4CStjaGmw==} @@ -8174,6 +8176,7 @@ packages: '@prisma/engines-version': 5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9 '@prisma/fetch-engine': 5.10.2 '@prisma/get-platform': 5.10.2 + dev: false /@prisma/fetch-engine@5.10.2: resolution: {integrity: sha512-dSmXcqSt6DpTmMaLQ9K8ZKzVAMH3qwGCmYEZr/uVnzVhxRJ1EbT/w2MMwIdBNq1zT69Rvh0h75WMIi0mrIw7Hg==} @@ -8181,11 +8184,13 @@ packages: '@prisma/debug': 5.10.2 '@prisma/engines-version': 5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9 '@prisma/get-platform': 5.10.2 + dev: false /@prisma/get-platform@5.10.2: resolution: {integrity: sha512-nqXP6vHiY2PIsebBAuDeWiUYg8h8mfjBckHh6Jezuwej0QJNnjDiOq30uesmg+JXxGk99nqyG3B7wpcOODzXvg==} dependencies: '@prisma/debug': 5.10.2 + dev: false /@probe.gl/env@3.6.0: resolution: {integrity: sha512-4tTZYUg/8BICC3Yyb9rOeoKeijKbZHRXBEKObrfPmX4sQmYB15ZOUpoVBhAyJkOYVAM8EkPci6Uw5dLCwx2BEQ==} @@ -18139,6 +18144,7 @@ packages: requiresBuild: true dependencies: '@prisma/engines': 5.10.2 + dev: false /prismjs@1.27.0: resolution: {integrity: sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==}