From 848552061ff4dd9e5c8ea8243dbcbb2b00a62f85 Mon Sep 17 00:00:00 2001 From: milon27 Date: Tue, 4 Mar 2025 17:07:13 +0600 Subject: [PATCH] update docker local setup --- .env.dev | 5 +++-- Dockerfile | 6 +++--- docker-compose.local.yml | 27 +++++++++++++++------------ readme.md | 7 +++++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/.env.dev b/.env.dev index d8189f1..95c5cd6 100644 --- a/.env.dev +++ b/.env.dev @@ -6,13 +6,13 @@ PORT=4000 TZ=Etc/UTC # database -DATABASE_URL="mysql://root:myPassWord@localhost:3308/test" # test, test +DATABASE_URL="mysql://root:myPassWord@np_mysql:3308/test" # redis # with ssl # REDIS_URL="rediss://default:xxxxx@xxxx.upstash.io:6379" # without ssl -REDIS_URL="redis://default:1234567@localhost:6379" +REDIS_URL="redis://default:1234567@np_redis:6379" # redis cluster (not used) REDIS_CLUSTER_ENABLE='false' REDIS_CLUSTER_URLS="one,two,three" @@ -28,6 +28,7 @@ ENABLE_SOCKET='false' LOKI_HOST="https://xxxxx.grafana.net" LOKI_AUTH="xxxxxxxxxxxxxxxxxxxxxxxxx" +# todo : mailhog setup here for dev # SMTP Mail SMTP_HOST="smtp-relay.xxxx.com" SMTP_PORT=587 diff --git a/Dockerfile b/Dockerfile index a78f21a..0cfbf68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20.18.0-alpine as build +FROM node:20.18.0-alpine AS build RUN npm install -g pnpm WORKDIR /app @@ -14,7 +14,7 @@ RUN npm run build # # ------------------dev ------------------- -FROM node:20.18.0-alpine as dev +FROM node:20.18.0-alpine AS dev RUN npm install -g pnpm WORKDIR /app @@ -36,7 +36,7 @@ CMD ["/bin/sh", "-c", "pnpm db:migrate:prod && pnpm db:seed:prod && node dist/sr # # ------------------prod ------------------- -FROM node:20.18.0-alpine as prod +FROM node:20.18.0-alpine AS prod RUN npm install -g pnpm WORKDIR /app diff --git a/docker-compose.local.yml b/docker-compose.local.yml index e847118..fa3c196 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -1,15 +1,17 @@ services: - # mysql: - # container_name: mysql - # image: mysql:8.0.33 - # restart: always - # environment: - # - MYSQL_ROOT_PASSWORD=myPassWord - # - MYSQL_DATABASE=test - # ports: - # - 3308:3306 - # volumes: - # - db_vol:/var/lib/mysql + np_mysql: + container_name: np_mysql + image: mysql:8.0.33 + restart: always + environment: + - MYSQL_ROOT_PASSWORD=myPassWord + - MYSQL_DATABASE=test + ports: + - 3309:3306 + networks: + - np_network + volumes: + - db_vol:/var/lib/mysql # - .backup-db:/docker-entrypoint-initdb.d np_redis: @@ -29,10 +31,11 @@ services: container_name: np_api depends_on: - np_redis + - np_mysql build: context: . dockerfile: Dockerfile - target: prod + target: dev restart: always ports: - 4000:4000 diff --git a/readme.md b/readme.md index 409777d..bb52f15 100644 --- a/readme.md +++ b/readme.md @@ -18,12 +18,15 @@ npx nestpress@latest module category blog # for more use of nestpress cli checkout this: https://www.npmjs.com/package/nestpress ``` -## How to run +## How to run with docker - make sure you have [docker](https://www.docker.com/products/docker-desktop/) and [pnpm](https://pnpm.io/) install on your system as node package manager - run mysql database and redis on docker(you should have docker install on your machine) - - run `docker compose up` this will run the database and redis on docker[use git-bash terminal in windows or for mac/linux default terminal is fine] + - run `docker compose -f docker-compose.local.yml up --build` this will run the api server, database and redis on docker[use git-bash terminal in windows or for mac/linux default terminal is fine] + - you can view the server on `http://localhost:4000` + +## How to run without docker - install all dependencies and run the app