diff --git a/.docker/server/Dockerfile b/.docker/server/Dockerfile index cae3612..691f389 100755 --- a/.docker/server/Dockerfile +++ b/.docker/server/Dockerfile @@ -1,18 +1,24 @@ FROM --platform=linux/amd64 node:20 AS base - -COPY . /usr/src/app WORKDIR /usr/src/app +COPY . . +COPY ./.env ./.env +RUN yes | yarn install -RUN yes | yarn bootstrap +FROM base AS build -EXPOSE $SERVER_PORT +RUN yarn build FROM base AS dev -CMD [ "npm", "run", "dev" ] -# CMD /bin/bash -c "tail -f /dev/null" - -FROM base AS prod +CMD [ "yarn", "run", "dev" ] -RUN yarn build +FROM --platform=linux/amd64 node:20 AS prod +ENV NODE_ENV=production +WORKDIR /usr/src/app +COPY --from=build /usr/src/app/packages/server/ts-dist ./server/ts-dist +COPY --from=build /usr/src/app/packages/client/dist ./client/dist +COPY --from=build /usr/src/app/node_modules ./node_modules +COPY --from=build /usr/src/app/.env ./.env -CMD [ "npm", "run", "preview" ] +# EXPOSE $SERVER_PORT +CMD [ "node", "server/ts-dist" ] +# CMD /bin/bash -c "tail -f /dev/null" diff --git a/packages/server/db.ts b/packages/server/db.ts index 21daf81..ef67f19 100644 --- a/packages/server/db.ts +++ b/packages/server/db.ts @@ -2,8 +2,11 @@ import dotenv from 'dotenv' import path from 'path' import { Client } from 'pg' +const PATH_TO_ENV_DEV = path.resolve(__dirname, '../../../.env') +const PATH_TO_ENV_PROD = path.resolve(__dirname, '../../.env') + dotenv.config({ - path: path.resolve(__dirname, '../../../.env'), // Путь к корневому .env файлу + path: process.env.NODE_ENV === 'production' ? PATH_TO_ENV_PROD : PATH_TO_ENV_DEV, // Путь к корневому .env файлу }) const {