diff --git a/.env.example b/.env.example index 7f47ba24d..1a8fe7f37 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,7 @@ NEXT_PUBLIC_BASE_URL_LOCAL=http://127.0.0.1:3000 ADMIN_SECRET="ADMIN_SECRET" JWT_SECRET="JWT_SECRET" # DONT CHANGE FOR RUNNING WITH DOCKER -DATABASE_URL="postgresql://postgres:postgres@db:5432/cms?schema=public" +DATABASE_URL="postgresql://myuser:mypassword@localhost:5432/cms?schema=public" NEXTAUTH_URL="http://localhost:3000" APPX_AUTH_KEY="AUTH_SECRET" NEXTAUTH_SECRET="NEXTAUTH_SECRET" diff --git a/README.md b/README.md index 1f68ff6c8..4e1573251 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,24 @@ git clone https://github.com/code100x/cms.git ```bash cd cms ``` +# Instant Docker Setup -3. (Optional) Start a PostgreSQL database using Docker: +> [!NOTE] +> Your Docker Demon should be online + +1. Running Script for Instant setup + +``` +# Gives permission to execute a setup file +chmod +x setup.sh + +# Runs the setup script file +./setup.sh +``` + +# Traditional Docker Setup + +(Optional) Start a PostgreSQL database using Docker: ```bash docker run -d \ @@ -35,45 +51,40 @@ docker run -d \ -p 5432:5432 \ postgres -``` +``` -The connection URL for this setup will be: -``` -DATABASE_URL=postgresql://myuser:mypassword@localhost:5432/mydatabase?schema=public -``` -4. Create a .env file: +1. Create a .env file: - Copy `.env.example` and rename it to `.env`. - - Configure the `DATABASE_URL` with your PostgreSQL connection string. -5. Install dependencies: +2. Install dependencies: ```bash pnpm install ``` -6. Run database migrations: +3. Run database migrations: ```bash pnpm run prisma:migrate ``` -7. Generate prisma client +4. Generate prisma client ```bash pnpm prisma generate ``` -8. Seed the database: +5. Seed the database: ```bash pnpm run db:seed ``` -9. Start the development server: +6. Start the development server: ```bash pnpm run dev diff --git a/setup.sh b/setup.sh new file mode 100755 index 000000000..703d48eff --- /dev/null +++ b/setup.sh @@ -0,0 +1,31 @@ +# Copies .env.example and changes it to .env so that future commands can find the env file +cp .env.example .env + + +# Start PostgreSQL container +docker run -d \ + --name cms-db \ + -e POSTGRES_USER=myuser \ + -e POSTGRES_PASSWORD=mypassword \ + -e POSTGRES_DB=mydatabase \ + -p 5432:5432 \ + postgres + +# Wait for the PostgreSQL container to be ready +echo "Waiting for PostgreSQL to be ready..." +sleep 10 + +# Install dependencies +pnpm install + +# Run Prisma migrations +pnpm run prisma:migrate + +# Generate Prisma client +pnpm prisma generate + +# Seed the database +pnpm run db:seed + +# Start the development server +pnpm run dev