Skip to content
/ sealos Public
forked from labring/sealos

Commit

Permalink
chore(frontend): add prisma cli into prod image (labring#4586)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudaotutou authored and zzjin committed Mar 13, 2024
1 parent d62762b commit ff7bce6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
21 changes: 11 additions & 10 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./
Expand All @@ -40,28 +41,26 @@ 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
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.
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions frontend/desktop/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ README.md
.git
.env.local
config.yaml

.yalc/
yalc.lock
yalc.lock

prisma/global/generated/
prisma/region/generated/
7 changes: 4 additions & 3 deletions frontend/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff7bce6

Please sign in to comment.