Commit 6771a041 authored by Yechang's avatar Yechang
Browse files

feat: move to bun

parent 0f233d59
Loading
Loading
Loading
Loading
Loading

.dockerignore

0 → 100644
+1 −0
Original line number Diff line number Diff line
node_modules
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ build:
    - docker build -t $DOCKER_REPOSITORY:$DOCKER_TAG
        --build-arg COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA
        --build-arg SENTRY_DSN=$SENTRY_DSN
        .
        --target release .

push:
  stage: push
+48 −40
Original line number Diff line number Diff line
FROM node:20-alpine as builder-with-pnpm

ENV NODE_ENV build
RUN npm install -g pnpm

FROM builder-with-pnpm as builder

WORKDIR /home/node

# pnpm fetch does require only lockfile
COPY pnpm-lock.yaml ./
RUN pnpm fetch

COPY --chown=node:node . .
RUN pnpm install -r --offline
RUN pnpm prisma:generate

FROM builder as migration
CMD pnpm prisma:deploy

FROM builder as building_stage
ENV NODE_ENV production

# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 as base
WORKDIR /usr/src/app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
COPY prisma /temp/dev/prisma
RUN cd /temp/dev && ls && \
    bun install --frozen-lockfile && \
    bun run prisma:generate

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
COPY prisma /temp/prod/prisma
RUN cd /temp/prod && \
    bun install --frozen-lockfile --production && \
    bun run prisma:generate


# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# [optional] tests & build
ENV NODE_ENV=production
# RUN bun test
ARG ORIGIN=https://lms.sustech.cloud
ENV ORIGIN $ORIGIN

@@ -29,30 +39,28 @@ ENV PUBLIC_COMMIT_SHORT_SHA $COMMIT_SHORT_SHA

ARG SENTRY_DSN
ENV PUBLIC_SENTRY_DSN $SENTRY_DSN
RUN NODE_OPTIONS=--max_old_space_size=8192 bun run build

RUN NODE_OPTIONS=--max_old_space_size=4096 pnpm run build \
    && pnpm prune --production

FROM node:20-alpine
FROM base as migration
COPY --from=install /temp/dev/node_modules node_modules
COPY --from=prerelease /usr/src/app/prisma ./prisma
COPY package.json ./
CMD bun run prisma:deploy

# copy production dependencies and source code into final image
FROM base AS release
RUN echo "Asia/shanghai" > /etc/timezone

USER node
ENV PORT 3000
ENV NODE_ENV production
COPY --from=install --chown=bun:bun /temp/prod/node_modules node_modules
COPY --from=prerelease --chown=bun:bun /usr/src/app/build/ ./build
RUN ls

ARG ORIGIN=https://lms.sustech.cloud
ENV ORIGIN $ORIGIN

WORKDIR /home/app

COPY --from=building_stage --chown=node:node /home/node/package*.json ./
COPY --from=building_stage --chown=node:node /home/node/node_modules/ ./node_modules/
COPY --from=building_stage --chown=node:node /home/node/.svelte-kit/ ./.svelte-kit/
COPY --from=building_stage --chown=node:node /home/node/build/ ./build/
# run the app
USER bun

HEALTHCHECK --interval=5s --timeout=3s \
    CMD wget --spider -q http://127.0.0.1:3000 || exit 1
EXPOSE 3000

CMD ["node","build/index.js"]
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "build/index.js" ]
 No newline at end of file

bun.lockb

0 → 100755
+435 KiB

File added.

No diff preview for this file type.

+132 −127
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@
    "refractor": "^4.8.1",
    "sass": "^1.71.1",
    "svelte": "^4.2.7",
    "svelte-adapter-bun": "^0.5.2",
    "svelte-check": "^3.6.0",
    "svelte-headless-table": "^0.18.2",
    "sveltekit-superforms": "^2.8.0",
@@ -125,5 +126,9 @@
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
	}
  },
  "trustedDependencies": [
    "@sentry/cli",
    "svelte-preprocess"
  ]
}
Loading