From 366a11814c07d364032779438fc25096d8c0b9b1 Mon Sep 17 00:00:00 2001 From: binhkid2 Date: Thu, 19 Feb 2026 11:10:32 +0900 Subject: [PATCH] try use docker --- README.md | 37 +++++++++---------------------- backend/.dockerignore | 19 ++++++++++++++++ backend/.env.example | 7 ++++-- backend/Dockerfile | 14 ++++++++++++ docker-compose.yml | 50 ++++++++++++++++++++++++++++++++++++++++++ frontend/.dockerignore | 13 +++++++++++ frontend/.env.example | 4 ++++ frontend/.gitignore | 2 +- frontend/Dockerfile | 15 +++++++++++++ frontend/README.md | 36 ------------------------------ 10 files changed, 131 insertions(+), 66 deletions(-) create mode 100644 backend/.dockerignore create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yml create mode 100644 frontend/.dockerignore create mode 100644 frontend/.env.example create mode 100644 frontend/Dockerfile delete mode 100644 frontend/README.md diff --git a/README.md b/README.md index 2d49b58..e7a054b 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,5 @@ -

- Nest Logo -

- -[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 -[circleci-url]: https://circleci.com/gh/nestjs/nest - -

A progressive Node.js framework for building efficient and scalable server-side applications.

-

-NPM Version -Package License -NPM Downloads -CircleCI -Discord -Backers on Open Collective -Sponsors on Open Collective - Donate us - Support us - Follow us on Twitter -

- - -## Description - -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. +# BackEnd ## Backend init ```bash @@ -68,4 +43,12 @@ $ npm run test:e2e $ npm run test:cov ``` - \ No newline at end of file + # FrontEnd + ```bash +# development +$ npm run dev + +# build,deploy +$ npm run build + +``` \ No newline at end of file diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..5adc44f --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,19 @@ + # Versioning and metadata +.git +.gitignore +.dockerignore + +# Build dependencies +dist +node_modules +coverage + +# Environment (contains sensitive data) +.env + +# Files not required for production +.editorconfig +Dockerfile +README.md +.eslintrc.js +nodemon.json \ No newline at end of file diff --git a/backend/.env.example b/backend/.env.example index 12e2223..f7e8c03 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -1,7 +1,7 @@ NODE_ENV=development HOST=0.0.0.0 -PORT=3000 -APP_URL=http://localhost:3000 +PORT=3001 +APP_URL=http://localhost:3001 # Database DB_HOST=localhost @@ -36,3 +36,6 @@ SMTP_PASS= GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/callback + + +FRONTEND_URL=http://localhost:3000 \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..2e47f69 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,14 @@ +FROM node:20-alpine AS base +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +RUN npm run build + +FROM node:20-alpine AS production +WORKDIR /app +COPY package*.json ./ +RUN npm ci --omit=dev +COPY --from=base /app/dist ./dist +EXPOSE 3001 +CMD ["node", "dist/main.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5a41163 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,50 @@ +version: '3.9' + +services: + postgres: + image: postgres:16-alpine + restart: unless-stopped + environment: + POSTGRES_USER: ${DB_USER:-postgres} + POSTGRES_PASSWORD: ${DB_PASSWORD:-password} + POSTGRES_DB: ${DB_NAME:-nestjs_blog} + volumes: + - postgres_data:/var/lib/postgresql/data + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-postgres} -d ${DB_NAME:-nestjs_blog}"] + interval: 10s + timeout: 5s + retries: 5 + + backend: + build: + context: ./backend + dockerfile: Dockerfile + restart: unless-stopped + env_file: + - ./backend/.env + ports: + - "3001:3001" + depends_on: + postgres: + condition: service_healthy + volumes: + - ./backend:/app + - /app/node_modules + + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + restart: unless-stopped + env_file: + - ./frontend/.env + ports: + - "3000:3000" + depends_on: + - backend + +volumes: + postgres_data: \ No newline at end of file diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..24d8899 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,13 @@ +node_modules +npm-debug.log +Dockerfile* +docker-compose* +.dockerignore +.git +.gitignore +README.md +LICENSE +.vscode +.next +*.swp +/scripts \ No newline at end of file diff --git a/frontend/.env.example b/frontend/.env.example new file mode 100644 index 0000000..ebd8a0f --- /dev/null +++ b/frontend/.env.example @@ -0,0 +1,4 @@ +NEXT_PUBLIC_API_URL=http://localhost:3001 + +UPLOAD_R2_WORKER_API=***.workers.dev +R2_UPLOAD_API_KEY=*** \ No newline at end of file diff --git a/frontend/.gitignore b/frontend/.gitignore index 5ef6a52..e72b4d6 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -31,7 +31,7 @@ yarn-error.log* .pnpm-debug.log* # env files (can opt-in for committing if needed) -.env* +.env # vercel .vercel diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..3efd581 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,15 @@ +FROM node:20-alpine AS base +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +RUN npm run build + +FROM node:20-alpine AS production +WORKDIR /app +COPY package*.json ./ +RUN npm ci --omit=dev +COPY --from=base /app/.next ./.next +COPY --from=base /app/public ./public +EXPOSE 3000 +CMD ["npm", "start"] \ No newline at end of file diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index e215bc4..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,36 +0,0 @@ -This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). - -## Getting Started - -First, run the development server: - -```bash -npm run dev -# or -yarn dev -# or -pnpm dev -# or -bun dev -``` - -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. - -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. - -This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. - -## Learn More - -To learn more about Next.js, take a look at the following resources: - -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. - -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! - -## Deploy on Vercel - -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. - -Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.