From a794408ccb8b562c9d181fa1fa3f4abe663629e4 Mon Sep 17 00:00:00 2001 From: Gianni Carafa Date: Thu, 19 Dec 2024 10:54:01 +0100 Subject: [PATCH] Update Docker setup with LTS Node version, define environment variables and services in docker-compose, and configure web application Dockerfile with multi-stage builds. --- api/.env.example | 2 +- api/Dockerfile | 4 ++-- docker-compose.yaml | 31 +++++++++++++++++++++++++++++++ web/Dockerfile | 18 ++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 docker-compose.yaml create mode 100644 web/Dockerfile diff --git a/api/.env.example b/api/.env.example index 9df7716..3a76e39 100644 --- a/api/.env.example +++ b/api/.env.example @@ -1,5 +1,5 @@ PORT= -MONGO_URI= +MONGO_URI=mongodb://mongo:27017/textbee JWT_SECRET=secret JWT_EXPIRATION=60d diff --git a/api/Dockerfile b/api/Dockerfile index 0cb9adb..47044a5 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-alpine AS base +FROM node:lts-alpine AS base RUN npm i -g pnpm WORKDIR /app COPY package.json pnpm-lock.yaml ./ @@ -13,7 +13,7 @@ FROM base AS build ENV NODE_ENV=production RUN pnpm build -FROM node:18-alpine AS prod +FROM node:lts-alpine AS prod ENV NODE_ENV=production WORKDIR /app RUN npm i -g pnpm diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..a1de6dd --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,31 @@ +services: + textbee-web: + image: textbee-web + container_name: textbee-web + build: + context: ./web + dockerfile: Dockerfile + ports: + - "3000:3000" + env_file: + - path: ./web/.env + required: true + command: pnpm start + textbee-api: + image: textbee-api + container_name: textbee-api + build: + context: ./api + dockerfile: Dockerfile + ports: + - "3005:3005" + env_file: + - path: ./api/.env + required: true + depends_on: + - mongo + mongo: + image: mongo + container_name: mongo + ports: + - "27017:27017" \ No newline at end of file diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..19e926e --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,18 @@ +FROM node:lts-alpine AS base + +# Stage 1: Install web dependencies +FROM base AS web-deps +WORKDIR /app +COPY package.json pnpm-lock.yaml ./ +RUN corepack enable pnpm && pnpm install --frozen-lockfile + +# Stage 2: Build the web application +FROM base AS web-builder +ENV NODE_ENV=production +EXPOSE 3000 +WORKDIR /app +COPY . . +COPY --from=web-deps /app/node_modules ./node_modules +RUN corepack enable pnpm && pnpm run vercel-build + +CMD ["pnpm", "start"] \ No newline at end of file