diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..9380d33 --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +# Create a .env file in root directory and add these values. You can simply copy it as cp .env.example .env +# Then run docker compose -f docker-compose.dev.yml up to start postgres inside docker and run migrations if you want +# Don't forget to add the same username, password and DB name to run backend api at /apps/api inside .env + +POSTGRES_DB=opensox +POSTGRES_PASSWORD=opensox_dev_password +POSTGRES_USER=opensox diff --git a/README.md b/README.md index d51d265..1eaf7b4 100644 --- a/README.md +++ b/README.md @@ -227,44 +227,16 @@ docker run -p 4000:4000 \ Your API server will be available at `http://localhost:4000`. -### Using Docker Compose (Optional) - -For a complete setup with PostgreSQL, you can create a `docker-compose.yml` file: - -```yaml -version: '3.8' -services: - postgres: - image: postgres:15 - environment: - POSTGRES_USER: opensox - POSTGRES_PASSWORD: opensox - POSTGRES_DB: opensox - ports: - - "5432:5432" - volumes: - - postgres_data:/var/lib/postgresql/data - - api: - build: . - ports: - - "4000:4000" - environment: - DATABASE_URL: postgresql://opensox:opensox@postgres:5432/opensox?schema=public - JWT_SECRET: your-secret-key - PORT: 4000 - NODE_ENV: production - depends_on: - - postgres - -volumes: - postgres_data: -``` +### Using Docker Compose for Database (Only) -Then run: +For a DB setup with PostgreSQL, cp .env.example .env in root directory with required variables, then run docker-compose.dev.yml ```bash -docker-compose up -d +cp .env.example .env +``` +Then run, +```bash +docker-compose -f docker-compose.dev.yml up -d ``` ## Our contributors diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..9023682 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,18 @@ + +services: + postgres: + image: postgres:18 + env_file: + - .env + ports: + - "5432:5432" + volumes: + - opensox_postgres_data:/var/lib/postgresql + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"] + interval: 10s + timeout: 5s + retries: 5 + +volumes: + opensox_postgres_data: