From a794408ccb8b562c9d181fa1fa3f4abe663629e4 Mon Sep 17 00:00:00 2001 From: Gianni Carafa Date: Thu, 19 Dec 2024 10:54:01 +0100 Subject: [PATCH 1/4] 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 From 3670415ea76204acaf0efedda213bfaa3e2b9f68 Mon Sep 17 00:00:00 2001 From: Israel Abebe Date: Thu, 19 Dec 2024 22:10:58 +0300 Subject: [PATCH 2/4] chore(infra): add volume to mongo container --- docker-compose.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index a1de6dd..702d765 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -27,5 +27,10 @@ services: mongo: image: mongo container_name: mongo + volumes: + - mongo_data:/data/db ports: - - "27017:27017" \ No newline at end of file + - "27017:27017" + +volumes: + mongo_data: From dd8fcd26f1fe1a4a633a38e1ecfacd1d682a496b Mon Sep 17 00:00:00 2001 From: Israel Abebe Date: Fri, 20 Dec 2024 06:03:39 +0300 Subject: [PATCH 3/4] chore(infra): update db container name --- docker-compose.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 702d765..e082a70 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -23,14 +23,14 @@ services: - path: ./api/.env required: true depends_on: - - mongo - mongo: + - textbee-db + textbee-db: image: mongo - container_name: mongo + container_name: textbee-db volumes: - - mongo_data:/data/db + - textbee-db-data:/data/db ports: - "27017:27017" volumes: - mongo_data: + textbee-db-data: From 48b3ddc24f863ed5ef3acfa3581ead2dc489d9b2 Mon Sep 17 00:00:00 2001 From: Israel Abebe Date: Sat, 21 Dec 2024 02:25:54 +0300 Subject: [PATCH 4/4] Update .env.example --- api/.env.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/.env.example b/api/.env.example index 3a76e39..a2c868d 100644 --- a/api/.env.example +++ b/api/.env.example @@ -1,5 +1,5 @@ PORT= -MONGO_URI=mongodb://mongo:27017/textbee +MONGO_URI=mongodb://textbee-db:27017/textbee JWT_SECRET=secret JWT_EXPIRATION=60d @@ -17,4 +17,4 @@ MAIL_PORT= MAIL_USER= MAIL_PASS= MAIL_FROM= -MAIL_REPLY_TO=textbee.dev@gmail.com \ No newline at end of file +MAIL_REPLY_TO=textbee.dev@gmail.com