From 3444d9ea5f624bed3c43fb6b583542296379de79 Mon Sep 17 00:00:00 2001 From: Andrei Kondratov Date: Fri, 6 Dec 2024 01:43:39 +0500 Subject: [PATCH 1/6] feat: docker file target for prod --- .docker/server/Dockerfile | 27 +++++++++++++++------------ packages/server/db.ts | 11 +++++++---- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/.docker/server/Dockerfile b/.docker/server/Dockerfile index cae3612..6c88105 100755 --- a/.docker/server/Dockerfile +++ b/.docker/server/Dockerfile @@ -1,18 +1,21 @@ FROM --platform=linux/amd64 node:20 AS base - -COPY . /usr/src/app WORKDIR /usr/src/app +COPY . . +RUN yes | yarn install -RUN yes | yarn bootstrap - -EXPOSE $SERVER_PORT +FROM base AS build +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 - -CMD [ "npm", "run", "preview" ] +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 .env ./.env +# 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..b60300a 100644 --- a/packages/server/db.ts +++ b/packages/server/db.ts @@ -1,9 +1,12 @@ -import dotenv from 'dotenv' -import path from 'path' -import { Client } from 'pg' +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 { From 4650dadc1d37550a3d1d50d1a8a3cba6770df547 Mon Sep 17 00:00:00 2001 From: Andrei Kondratov Date: Fri, 6 Dec 2024 20:56:24 +0500 Subject: [PATCH 2/6] fix linter --- packages/server/db.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/server/db.ts b/packages/server/db.ts index b60300a..ef67f19 100644 --- a/packages/server/db.ts +++ b/packages/server/db.ts @@ -1,9 +1,9 @@ -import dotenv from 'dotenv'; -import path from 'path'; -import { Client } from 'pg'; +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'); +const PATH_TO_ENV_DEV = path.resolve(__dirname, '../../../.env') +const PATH_TO_ENV_PROD = path.resolve(__dirname, '../../.env') dotenv.config({ path: process.env.NODE_ENV === 'production' ? PATH_TO_ENV_PROD : PATH_TO_ENV_DEV, // Путь к корневому .env файлу From fd160d240123f9ae0308bdadac830349f873845a Mon Sep 17 00:00:00 2001 From: Andrei Kondratov Date: Fri, 6 Dec 2024 21:04:42 +0500 Subject: [PATCH 3/6] wip --- .docker/server/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.docker/server/Dockerfile b/.docker/server/Dockerfile index 6c88105..54ad1e9 100755 --- a/.docker/server/Dockerfile +++ b/.docker/server/Dockerfile @@ -15,7 +15,7 @@ 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 .env ./.env +COPY --from=build .env ./.env # EXPOSE $SERVER_PORT CMD [ "node", "server/ts-dist" ] # CMD /bin/bash -c "tail -f /dev/null" From 190725d379db73331a609bae53d40968230d34a5 Mon Sep 17 00:00:00 2001 From: Daniil <77277774+shamemask@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:44:27 +0300 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B5=20=D0=B2=20?= =?UTF-8?q?Dockerfile,=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B1=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD=D1=82=D0=B5=20=D1=81=20.env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .docker/server/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.docker/server/Dockerfile b/.docker/server/Dockerfile index 54ad1e9..50a044c 100755 --- a/.docker/server/Dockerfile +++ b/.docker/server/Dockerfile @@ -15,7 +15,10 @@ 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 .env ./.env + +# Ensure .env exists, if it does, copy it, otherwise copy .env.example to .env +RUN if [ -f .env ]; then cp .env .env; else cp .env.example .env; fi + # EXPOSE $SERVER_PORT CMD [ "node", "server/ts-dist" ] # CMD /bin/bash -c "tail -f /dev/null" From 188a17ef8966a318ebc5d459961de9b2c1abd21b Mon Sep 17 00:00:00 2001 From: Daniil <77277774+shamemask@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:58:14 +0300 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B5,=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BF=D1=80=D0=B5=D0=B4=D1=8B=D0=B4=D1=83=D1=89?= =?UTF-8?q?=D0=B5=D0=B5,=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B1=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD=D1=82=D0=B5=20=D1=81=20.env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .docker/server/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.docker/server/Dockerfile b/.docker/server/Dockerfile index 50a044c..6030e8c 100755 --- a/.docker/server/Dockerfile +++ b/.docker/server/Dockerfile @@ -15,9 +15,7 @@ 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 - -# Ensure .env exists, if it does, copy it, otherwise copy .env.example to .env -RUN if [ -f .env ]; then cp .env .env; else cp .env.example .env; fi +COPY --from=build /usr/src/app/.env ./.env # EXPOSE $SERVER_PORT CMD [ "node", "server/ts-dist" ] From 58182876709a8ee16f4dc801a11e5b13d9b9376d Mon Sep 17 00:00:00 2001 From: Daniil <77277774+shamemask@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:24:16 +0300 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=D0=B5=D1=89=D1=91=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BF=D1=8B=D1=82=D0=BA=D0=B0=20=D0=BE=D0=B1=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=B2=20=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=20=D1=81=20.env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .docker/server/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.docker/server/Dockerfile b/.docker/server/Dockerfile index 6030e8c..691f389 100755 --- a/.docker/server/Dockerfile +++ b/.docker/server/Dockerfile @@ -1,9 +1,11 @@ FROM --platform=linux/amd64 node:20 AS base WORKDIR /usr/src/app COPY . . +COPY ./.env ./.env RUN yes | yarn install FROM base AS build + RUN yarn build FROM base AS dev