Skip to content

Commit

Permalink
Merge pull request #55 from Timur233/dockerfile-target-for-prod
Browse files Browse the repository at this point in the history
feat: docker file target for prod
  • Loading branch information
shamemask authored Dec 11, 2024
2 parents a490642 + 5818287 commit cd8871c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
26 changes: 16 additions & 10 deletions .docker/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 4 additions & 1 deletion packages/server/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cd8871c

Please sign in to comment.