mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat: Improve build system to reduce Docker image to 312 MB
This commit is contained in:
parent
44aaa87f79
commit
ecf1139081
4 changed files with 60 additions and 13 deletions
29
Dockerfile
29
Dockerfile
|
|
@ -1,9 +1,9 @@
|
|||
# use the official Bun image
|
||||
# see all versions at https://hub.docker.com/r/oven/bun/tags
|
||||
FROM oven/bun:1.0.14-alpine as base
|
||||
FROM oven/bun:1.0.15-alpine as base
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
RUN apk add vips-dev
|
||||
RUN apk add vips
|
||||
# Required for Prisma to work
|
||||
COPY --from=node:18-alpine /usr/local/bin/node /usr/local/bin/node
|
||||
|
||||
|
|
@ -16,20 +16,28 @@ RUN cd /temp/dev && bun install --frozen-lockfile
|
|||
|
||||
# install with --production (exclude devDependencies)
|
||||
RUN mkdir -p /temp/prod
|
||||
COPY package.json bun.lockb /temp/prod/
|
||||
COPY . /temp/prod/
|
||||
RUN cd /temp/prod && bun install --frozen-lockfile --production.
|
||||
|
||||
# Generate Prisma
|
||||
RUN bunx prisma generate
|
||||
|
||||
# Build Vite in pages
|
||||
WORKDIR /temp/prod
|
||||
RUN bunx --bun vite build pages
|
||||
|
||||
# Build the project
|
||||
RUN bun run build.ts
|
||||
|
||||
# copy production dependencies and source code into final image
|
||||
FROM base AS release
|
||||
|
||||
# Create app directory
|
||||
RUN mkdir -p /app
|
||||
COPY --from=install /temp/prod/node_modules /app/node_modules
|
||||
COPY . /app
|
||||
COPY --from=install /temp/prod/dist /app/dist
|
||||
COPY --from=install /temp/prod/pages /app/pages
|
||||
COPY entrypoint.sh /app
|
||||
|
||||
# Build Vite in pages
|
||||
WORKDIR /app
|
||||
RUN bunx --bun vite build pages
|
||||
|
||||
LABEL org.opencontainers.image.authors "Gaspard Wierzbinski (https://cpluspatch.dev)"
|
||||
LABEL org.opencontainers.image.source "https://github.com/lysand-org/lysand"
|
||||
|
|
@ -38,11 +46,8 @@ LABEL org.opencontainers.image.licenses "AGPL-3.0"
|
|||
LABEL org.opencontainers.image.title "Lysand Server"
|
||||
LABEL org.opencontainers.image.description "Lysand Server docker image"
|
||||
|
||||
# CD to app
|
||||
WORKDIR /app
|
||||
RUN bunx prisma generate
|
||||
# CD to app
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
# Run migrations and start the server
|
||||
ENTRYPOINT [ "bun", "migrate", "&&", "bun start" ]
|
||||
ENTRYPOINT [ "./entrypoint.sh" "start" ]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue