From 2e40f7d6a000324f1425696215e168452e9ef747 Mon Sep 17 00:00:00 2001 From: Ameer jafar Date: Mon, 16 Sep 2024 09:40:10 +0530 Subject: [PATCH] added the docker --- .dockerignore | 5 +++++ Dockerfile | 17 +++++++++++++++++ apps/backend/.env.example | 4 ++++ apps/frontend/package.json | 2 +- docker-compose.yml | 35 +++++++++++++++++++++++++++++++++++ package-lock.json | 17 +++++++++++++++++ package.json | 4 +++- 7 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..11420c7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +.git +.gitignore +.env.example +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f88393e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ + +FROM node:20-alpine + +WORKDIR /usr/src/app + +COPY package*.json ./ + +COPY apps/frontend/package*.json ./apps/frontend/ +COPY apps/backend/package*.json ./apps/backend/ +RUN npm install + +COPY . . + + +EXPOSE 5173 + +CMD ["npm", "run", "dev:docker"] diff --git a/apps/backend/.env.example b/apps/backend/.env.example index e69de29..04cb8dc 100644 --- a/apps/backend/.env.example +++ b/apps/backend/.env.example @@ -0,0 +1,4 @@ +CLIENT_ID="" +CLIENT_SECRET="" +GIT_CLIENT_ID="" +GIT_CLIENT_SECRET="" diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 3462b3d..edc5e4d 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --host", "build": "tsc -b && vite build", "lint": "eslint .", "preview": "vite preview", diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f830383 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,35 @@ +version: '3.8' + +services: + app: + build: . + container_name: build-your-own + environment: + - DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres + ports: + - '3000:3000' + - '5173:5173' + depends_on: + db: + condition: service_healthy + + db: + image: postgres:9.6 + container_name: db + restart: always + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: build-your-own + ports: + - '5432:5432' + volumes: + - postgres-data:/var/lib/postgresql/data + healthcheck: + test: ['CMD-SHELL', 'pg_isready -d $$POSTGRES_DB -U $$POSTGRES_USER'] + interval: 10s + timeout: 5s + retries: 5 + +volumes: + postgres-data: diff --git a/package-lock.json b/package-lock.json index 9749279..afcc243 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "ts-node": "^10.9.2" }, "devDependencies": { + "husky": "^8.0.0", "prettier": "^3.2.5", "turbo": "^2.1.1", "typescript": "^5.4.5" @@ -7932,6 +7933,22 @@ "node": ">=10.17.0" } }, + "node_modules/husky": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", + "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", + "dev": true, + "license": "MIT", + "bin": { + "husky": "lib/bin.js" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/package.json b/package.json index 4b5620b..f45acf9 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "dev": "turbo dev", "lint": "turbo lint", "format": "prettier --write \"**/*.{ts,tsx, js, jsx, md, mdx, css}\"", - "prepare": "husky install" + "prepare": "husky install", + "dev:docker": "npm run prisma:docker && npm run dev", + "prisma:docker": "cd packages/db && npx prisma migrate dev --skip-seed" }, "lint-staged": { "src/**/*.{ts,tsx,js,jsx,md,mdx,css}": [