From 8fdbc660a594bf009fd800bb9fb658aeff088e31 Mon Sep 17 00:00:00 2001 From: hprasa638 Date: Mon, 14 Oct 2024 16:08:09 +0530 Subject: [PATCH] adding dockerfile and compose files for hosting chessu in container --- .dockerignore | 8 ++++++++ .gitignore | 1 + Dockerfile | 17 +++++++++++++++++ README.md | 26 ++++++++++++++++++++++++++ docker-compose.yml | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+) 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..0949f4b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.github +CODE_OF_CONDUCT.md +CONTRIBUTING.md +LICENSE +README.md +docker-compose.yml +Dockerfile +LICENSE diff --git a/.gitignore b/.gitignore index 1a277f5..b6fba5f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ yarn.lock node_modules .pnp +.pnpm-store .pnp.js .next diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a46864a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM node:lts-alpine3.20 + +ENV PNPM_HOME=/usr/local/bin + +WORKDIR /opt/chessu/ + +COPY . . + +RUN apk update && \ + corepack enable && corepack prepare pnpm@latest --activate && \ + pnpm config set store-dir /opt/chessu/.pnpm-store && \ + pnpm install -g pnpm@latest && \ + pnpm install --unsafe-perm + +ENTRYPOINT ["pnpm"] + +CMD ["start"] diff --git a/README.md b/README.md index a7ec9cf..4919d21 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,32 @@ This project is structured as a monorepo using **pnpm** workspaces, separated in - To run the frontend and backend servers separately, use `pnpm dev:client` and `pnpm dev:server`, respectively. 5. You can now access the frontend at http://localhost:3000 and the backend at http://localhost:3001. +## Running chessu with Docker + +To build the project with Docker, you can use the provided `Dockerfile`. +```sh +docker build -t chessu . +``` + +This command will build the Docker image with the name `chessu`. You can then run the image with the following command: +```sh +docker run -p 3000:3000 -p 3001:3001 chessu +``` + +Once built, to start the project with POSTGRES, you can use the provided `docker-compose.yml` file. +```sh +docker-compose up +``` +Please make sure to modify the values in the `server/.env` file to match the values in the `docker-compose.yml` file or vice versa. + +The entrypoint for the Docker image is set to run pnpm. +The Dockerfile's `CMD` instruction is set to run the project in production mode. +If you want to run the project in development mode, you can override the `CMD` instruction by running the following command: +```sh +docker run -p 3000:3000 -p 3001:3001 chessu dev # runs both client and server in development mode +docker run -p 3000:3000 -p 3001:3001 chessu dev:client # runs only the client in development mode +docker run -p 3000:3000 -p 3001:3001 chessu dev:server # runs only the server in development mode +``` ## Contributing Please read our [Contributing Guidelines](./CONTRIBUTING.md) before starting a pull request. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7e53304 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: '3.8' + +services: + chessu: + image: chessu:latest # Replace with the correct image if needed + container_name: chessu_container + environment: + POSTGRES_DB: chessu + POSTGRES_USER: exampleuser + POSTGRES_PASSWORD: examplepassword + DATABASE_URL: postgres://chessu_user:chessu_pass@db:5432/chessu + ports: + - "3000:3000" + - "3001:3001" + depends_on: + - db + networks: + - chessu_network + + db: + image: postgres:15 + container_name: postgres_container + environment: + POSTGRES_DB: chessu + POSTGRES_USER: exampleuser + POSTGRES_PASSWORD: examplepassword + volumes: + - postgres_data:/var/lib/postgresql/data + networks: + - chessu_network + +volumes: + postgres_data: + +networks: + chessu_network: + driver: bridge