From c88b6d7577ad343a238a424331e01c54232c61ab Mon Sep 17 00:00:00 2001 From: hknsh Date: Fri, 25 Oct 2024 19:06:25 +0100 Subject: [PATCH] feat: changed npm to bun in docker --- Dockerfile | 68 +++++++++++++++++++--------------------------- docker-compose.yml | 10 ++++++- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/Dockerfile b/Dockerfile index 108e696..0183450 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,38 @@ -# LOCAL -FROM node:20-alpine AS dev - +FROM oven/bun:latest AS base WORKDIR /usr/src/app -COPY --chown=node:node package*.json ./ -COPY --chown=node:node prisma ./prisma/ +# Install deps into tmp dir +FROM base AS install +RUN mkdir -p /temp/dev +COPY package.json bun.lockb docker.env /temp/dev/ +RUN cd /temp/dev && bun install --frozen-lockfile -RUN npm ci +# Install without dev deps +RUN mkdir -p /temp/prod +COPY package.json bun.lockb /temp/prod/ +COPY .husky/ /temp/prod/.husky/ +RUN bun install husky -g +RUN cd /temp/prod && bun install --frozen-lockfile --production -COPY --chown=node:node . . - -USER node - -# BUILD -FROM node:20-alpine AS build - -WORKDIR /usr/src/app - -COPY --chown=node:node package*.json ./ -COPY --chown=node:node --from=dev /usr/src/app/node_modules ./node_modules -COPY --chown=node:node --from=dev /usr/src/app/prisma ./prisma/ -COPY --chown=node:node .husky ./.husky -COPY --chown=node:node tsconfig.json tsconfig.build.json ./ -COPY --chown=node:node docker.env ./.env -COPY --chown=node:node . . - -RUN npm install husky -g - -RUN npm run prisma:generate - -RUN npm run build +# Copy node_modules from temp directory +FROM base AS prerelase +COPY --from=install /temp/dev/node_modules node_modules +COPY --from=install /temp/dev/docker.env .env +COPY . . ENV NODE_ENV production -RUN npm ci --only=production && npm cache clean --force +RUN bun migrate:deploy -USER node +RUN bun run build -# PROD -FROM node:20-alpine as production +# Copy production deps +FROM base AS release +COPY --from=install /temp/prod/node_modules node_modules +COPY --from=prerelase /usr/src/app/dist dist +COPY --from=prerelase /usr/src/app/prisma prisma +COPY --from=prerelase /usr/src/app/.husky ./.husky +COPY --from=prerelase /usr/src/app/.env ./.env +COPY --from=prerelase /usr/src/app/package*.json ./ -COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules -COPY --chown=node:node --from=build /usr/src/app/dist ./dist -COPY --chown=node:node --from=build /usr/src/app/prisma ./prisma -COPY --chown=node:node --from=build /usr/src/app/.husky ./.husky -COPY --chown=node:node --from=build /usr/src/app/.env ./ -COPY --chown=node:node --from=build /usr/src/app/package*.json ./ - -CMD ["npm", "run" , "prod"] +CMD [ "bun", "dist/main.js" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 319e123..2982654 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,9 @@ networks: minio_network: name: minio_network driver: bridge - + backend-network: + driver: bridge + services: postgres: image: postgres:alpine @@ -17,6 +19,8 @@ services: - docker.env volumes: - postgres:/var/lib/postgresql/data + networks: + - backend-network minio: image: bitnami/minio @@ -40,6 +44,8 @@ services: command: redis-server --save 20 1 --loglevel warning --requirepass not_a_production_pass volumes: - redis:/data + networks: + - backend-network api: container_name: api @@ -55,6 +61,8 @@ services: - minio env_file: - docker.env + networks: + - backend-network volumes: postgres: