diff --git a/Dockerfile b/Dockerfile index 4a36200..3ea191f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,19 @@ -FROM node:lts AS builder +FROM node:lts-slim AS base -# make workdir /app -WORKDIR /app - -# install pnpm -RUN corepack enable && corepack prepare pnpm@v9.10.0 --activate - -# Install requested packages -COPY pnpm-lock.yaml ./ -RUN pnpm fetch - -# Copy app source and install dependencies -COPY . . -RUN pnpm install -r --offline --ignore-scripts +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable -# transpile to js -RUN pnpm build +FROM base AS prod -FROM node:lts-alpine AS final - -# make workdir /app +COPY pnpm-lock.yaml /app WORKDIR /app - -# install pnpm -RUN corepack enable && corepack prepare pnpm@v9.10.0 --activate - -# Fetch production packages -COPY pnpm-lock.yaml ./ RUN pnpm fetch --prod -# copy transpiled code, install prod dependencies -COPY --from=builder ./app/dist ./dist -COPY package.json . -RUN pnpm install -r --offline --prod --ignore-scripts +COPY . /app +RUN pnpm run build -# start server -CMD cd dist && node deploy-commands.js && node . \ No newline at end of file +FROM base +COPY --from=prod /app/node_modules /app/node_modules +COPY --from=prod /app/dist /app/dist +CMD [ "pnpm", "start" ] \ No newline at end of file diff --git a/package.json b/package.json index 6a73e4a..bf37248 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,7 @@ "type": "module", "scripts": { "build": "tsc", - "deploy-cmd": "tsc && cd dist && node deploy-commands.js", - "start": "tsc && cd dist && node .", + "start": "cd dist && node deploy-commands.js && node .", "prettify": "prettier --write . --plugin-search-dir=. --ignore-unknown", "pm2": "pm2 start \"pnpm start\"", "lint": "eslint --cache . --fix",