diff --git a/DOCKER_GIT_DEPLOYMENT.md b/DOCKER_GIT_DEPLOYMENT.md index 0231cf5..175db9b 100644 --- a/DOCKER_GIT_DEPLOYMENT.md +++ b/DOCKER_GIT_DEPLOYMENT.md @@ -134,19 +134,19 @@ When `GIT_REPO_URL` is provided: 2. If `GIT_COMMIT` is specified, checkout that specific commit 3. Install dependencies from the repository's package.json 4. Build the application -5. **Create the default admin account automatically** +5. **Admin account is created when container starts (not during build)** 6. Start the production server When `GIT_REPO_URL` is not provided: 1. Copy local files into the container 2. Install dependencies 3. Build the application -4. **Create the default admin account automatically** +4. **Admin account is created when container starts (not during build)** 5. Start the production server ## Default Admin Account -Both development and production Docker builds automatically create a default admin account with these credentials: +Both development and production Docker containers automatically create a default admin account **when the container starts** (not during build). This ensures the database is properly persisted in mounted volumes. - **Email**: `admin@localhost.com` - **Password**: `admin123456` @@ -193,7 +193,9 @@ The script will skip creation if an admin account already exists. - For private repositories, verify authentication tokens/keys ### Admin Account Issues -- If admin creation fails during build, check database initialization -- Ensure the database file is writable in the container +- If admin creation fails during startup, check database initialization +- Ensure the `./data` directory is writable on the host +- Database files are persisted in the mounted `./data` volume +- Admin account is created on container startup, not during build - If admin already exists, the script will skip creation (this is normal) -- To recreate admin account, delete the database and rebuild the container +- To recreate admin account, delete the database file in `./data/` and restart the container diff --git a/Dockerfile b/Dockerfile index 504f3f5..018dd1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,11 +32,12 @@ COPY . . # Build the application for production RUN npm run build -# Create the default admin account -RUN node scripts/create-admin.js +# Copy the entrypoint script +COPY docker-entrypoint.sh /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh # Expose the default Next.js port EXPOSE 3000 -# Start the production server -CMD ["npm", "start"] +# Use the entrypoint script +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/Dockerfile.dev b/Dockerfile.dev index 083fb48..7a9e61b 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -16,11 +16,12 @@ RUN npm install # Copy the rest of the app COPY . . -# Create the default admin account for development -RUN node scripts/create-admin.js +# Copy the development entrypoint script +COPY docker-entrypoint-dev.sh /docker-entrypoint-dev.sh +RUN chmod +x /docker-entrypoint-dev.sh # Expose the default Next.js port EXPOSE 3000 -# Start the dev server -CMD ["npm", "run", "dev"] +# Use the development entrypoint script +ENTRYPOINT ["/docker-entrypoint-dev.sh"] diff --git a/deploy.bat b/deploy.bat index f370a33..406e261 100644 --- a/deploy.bat +++ b/deploy.bat @@ -26,4 +26,4 @@ docker-compose -f docker-compose.prod.yml down docker-compose -f docker-compose.prod.yml up -d echo Deployment completed successfully! -echo Application is running at http://localhost:3000 +echo Application is running at http://localhost:3001 diff --git a/deploy.sh b/deploy.sh index 8e1f9a6..7517246 100644 --- a/deploy.sh +++ b/deploy.sh @@ -29,4 +29,4 @@ docker-compose -f docker-compose.prod.yml down docker-compose -f docker-compose.prod.yml up -d echo "Deployment completed successfully!" -echo "Application is running at http://localhost:3000" +echo "Application is running at http://localhost:3001" diff --git a/docker-entrypoint-dev.sh b/docker-entrypoint-dev.sh new file mode 100644 index 0000000..27272f0 --- /dev/null +++ b/docker-entrypoint-dev.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Development container startup script +# This runs when the development container starts + +echo "🚀 Starting development environment..." + +# Ensure data directory exists +mkdir -p /app/data + +# Create admin account if it doesn't exist +echo "🔧 Setting up admin account..." +node scripts/create-admin.js + +# Start the development server +echo "✅ Starting development server..." +exec npm run dev diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..b4392e4 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Container startup script +# This runs when the container starts, not during build + +echo "🚀 Starting application..." + +# Ensure data directory exists +mkdir -p /app/data + +# Create admin account if it doesn't exist +echo "🔧 Setting up admin account..." +node scripts/create-admin.js + +# Start the application +echo "✅ Starting production server..." +exec npm start