diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..88249539f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +.git +.gitignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..ef4dd412a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:20-alpine + +WORKDIR /usr/src/app + +COPY package* . + +COPY prisma ./prisma + +RUN npm install + +COPY . . + +ENV DATABASE_URL="postgresql://postgres:mysecretpassword@db:5432/paper" + +RUN npx prisma generate + +EXPOSE 3000 + +CMD ["npm", "run", "docker-dev"] \ No newline at end of file diff --git a/README.md b/README.md index 4e67898c9..aaf3af8a1 100644 --- a/README.md +++ b/README.md @@ -65,32 +65,53 @@ git clone https://github.com/mfts/papermark.git cd papermark ``` -### 2. Install npm dependencies +### Without Docker + +#### 2. Install npm dependencies ```shell npm install ``` -### 3. Copy the environment variables to `.env` and change the values +#### 3. Copy the environment variables to `.env` and change the values ```shell cp .env.example .env ``` -### 4. Initialize the database +#### 4. Initialize the database ```shell npx prisma generate npx prisma migrate deploy ``` -### 5. Run the dev server +#### 5. Run the dev server ```shell npm run dev ``` -### 6. Open the app in your browser +#### 6. Open the app in your browser + +Visit [http://localhost:3000](http://localhost:3000) in your browser. + +### with Docker + +#### 2. Copy the environment variables to `.env` and change the values where the DATABASE_URL="postgresql://postgres:mysecretpassword@db:5432/paper?schema=public" + +```shell +cp .env.example .env +``` + +#### 3. Run docker compose -up + +```shell +docker compose up +``` + + +#### 4. Open the app in your browser Visit [http://localhost:3000](http://localhost:3000) in your browser. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..2628f94fb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +version: "3.6" +services: + db: + image: postgres + container_name: db + restart: always + environment: + POSTGRES_USER: postgres + POSTGRES_DB: paper + POSTGRES_PASSWORD: mysecretpassword + 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 + + app: + build: . + container_name: app + env_file: + - .env + ports: + - "3000:3000" + volumes: + - .:/usr/src/app + - /usr/src/app/node_modules + depends_on: + db: + condition: service_healthy + +volumes: + postgres-data: diff --git a/package.json b/package.json index 48f02c700..426b2e722 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "node": ">=18.17.0" }, "scripts": { + "docker-dev":"npx prisma migrate deploy && next dev", "dev": "next dev", "build": "next build", "start": "next start",