diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000000000..47a4673748ef34 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,31 @@ +{ + "name": "Cal.diy", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspace", + + // Override DATABASE_URL/REDIS_URL to use the Docker service names. + // These take precedence over .env, so no need to edit that file for the DB connection. + "remoteEnv": { + "DATABASE_URL": "postgresql://postgres:postgres@database:5432/calendso", + "DATABASE_DIRECT_URL": "postgresql://postgres:postgres@database:5432/calendso", + "REDIS_URL": "redis://redis:6379" + }, + + // On first container start: copy .env.example → .env only when .env is absent, then always install deps + // HUSKY=0 skips git hook installation, which fails in container environments + "postCreateCommand": "[ -f .env ] || cp .env.example .env; HUSKY=0 yarn install", + + // Forward the web app port to the host + "forwardPorts": [3000], + + "customizations": { + "vscode": { + "extensions": [ + "biomejs.biome", + "bradlc.vscode-tailwindcss", + "prisma.prisma" + ] + } + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000000000..0aa42d02775ad3 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,37 @@ +# Dev container services - PostgreSQL and Redis for local development. +# The app itself runs in the devcontainer, not here. +services: + app: + image: mcr.microsoft.com/devcontainers/javascript-node:1-20-bookworm + volumes: + - ..:/workspace:cached + command: sleep infinity + depends_on: + - database + - redis + + database: + image: postgres:15-alpine + restart: unless-stopped + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: calendso + ports: + # Expose on 5450 to match DATABASE_URL in .env.example + - "5450:5432" + volumes: + - postgres-data:/var/lib/postgresql/data + + redis: + image: redis:7-alpine + restart: unless-stopped + ports: + # Expose on 6379 to allow host access with redis-cli or GUI tools + - "6379:6379" + volumes: + - redis-data:/data + +volumes: + postgres-data: + redis-data: diff --git a/.env.example b/.env.example index 93583231249e36..1fd5e690f9005e 100644 --- a/.env.example +++ b/.env.example @@ -14,10 +14,10 @@ # *********************************************************************************************************** # - DATABASE ************************************************************************************************ -DATABASE_URL="postgresql://postgres:@localhost:5450/calendso" +DATABASE_URL="postgresql://postgres:postgres@localhost:5450/calendso" # Needed to run migrations while using a connection pooler like PgBouncer # Use the same one as DATABASE_URL if you're not using a connection pooler -DATABASE_DIRECT_URL="postgresql://postgres:@localhost:5450/calendso" +DATABASE_DIRECT_URL="postgresql://postgres:postgres@localhost:5450/calendso" INSIGHTS_DATABASE_URL= # *********************************************************************************************************** @@ -32,7 +32,7 @@ NEXT_PUBLIC_EMBED_LIB_URL='http://localhost:3000/embed/embed.js' # To enable SAML login, set both these variables # @see https://github.com/calcom/cal.diy/tree/main/packages/features/ee#setting-up-saml-login -# SAML_DATABASE_URL="postgresql://postgres:@localhost:5450/cal-saml" +# SAML_DATABASE_URL="postgresql://postgres:postgres@localhost:5450/cal-saml" SAML_DATABASE_URL= # SAML_ADMINS='pro@example.com' SAML_ADMINS= diff --git a/README.md b/README.md index 59b76f2646bb8a..e5a2af7d3bb11d 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,46 @@ for Logger level to be set at info, for example. [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/calcom/cal.diy) +#### Dev Container setup + +A Dev Container configuration is included so you can spin up a fully working development environment without installing PostgreSQL or Redis locally. It works with [VS Code Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers) and [GitHub Codespaces](https://github.com/features/codespaces). + +**Requirements:** [Docker](https://www.docker.com/get-started) and the [VS Code Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). + +1. Open the project in VS Code and click **Reopen in Container** when prompted (or run `Dev Containers: Reopen in Container` from the Command Palette). + +2. On first start, the container will automatically: + - Copy `.env.example` to `.env` (skipped if `.env` already exists) + - Run `yarn install` + +3. Open `.env` and fill in the two required secrets: + + ```sh + # Generate NEXTAUTH_SECRET + openssl rand -base64 32 + + # Generate CALENDSO_ENCRYPTION_KEY (must be 32 bytes for AES256) + openssl rand -base64 24 + ``` + + > The `DATABASE_URL` and `REDIS_URL` are pre-configured by the Dev Container and do not need to be changed. + +4. Run database migrations: + + ```sh + yarn workspace @calcom/prisma db-migrate + ``` + +5. Start the dev server: + + ```sh + yarn dev + ``` + +6. Open [http://localhost:3000](http://localhost:3000). + +> **Note:** PostgreSQL is exposed on host port `5450` (credentials: `postgres` / `postgres`) and Redis on `6379`, matching the defaults in `.env.example`. This lets you connect to the database with tools like TablePlus or psql from your host machine. The database URL for host access is `postgresql://postgres:postgres@localhost:5450/calendso`. + #### Manual setup 1. Configure environment variables in the `.env` file. Replace ``, ``, ``, and `` with their applicable values