feat: enhance Docker setup with environment variable management and add example docker-compose file
This commit is contained in:
22
.env.example
22
.env.example
@@ -1,11 +1,17 @@
|
||||
# Navidrome Server Configuration
|
||||
# Navidrome Server Configuration (for development)
|
||||
NEXT_PUBLIC_NAVIDROME_URL=http://localhost:4533
|
||||
NEXT_PUBLIC_NAVIDROME_USERNAME=your_username
|
||||
NEXT_PUBLIC_NAVIDROME_PASSWORD=your_password
|
||||
NEXT_PUBLIC_POSTHOG_KEY=KEY
|
||||
NEXT_PUBLIC_POSTHOG_HOST=HOSTURL
|
||||
# NEXT_PUBLIC_COMMIT_SHA=$(git rev-parse --short HEAD)
|
||||
# Example for external server:
|
||||
# NEXT_PUBLIC_NAVIDROME_URL=https://your-navidrome-server.com
|
||||
# NEXT_PUBLIC_NAVIDROME_USERNAME=your_username
|
||||
# NEXT_PUBLIC_NAVIDROME_PASSWORD=your_password
|
||||
|
||||
# PostHog Analytics (optional)
|
||||
NEXT_PUBLIC_POSTHOG_KEY=your_posthog_key
|
||||
NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com
|
||||
|
||||
# For Docker deployment, use these variable names in your .env file:
|
||||
# NAVIDROME_URL=https://your-navidrome-server.com
|
||||
# NAVIDROME_USERNAME=your_username
|
||||
# NAVIDROME_PASSWORD=your_password
|
||||
# POSTHOG_KEY=your_posthog_key
|
||||
# POSTHOG_HOST=https://us.i.posthog.com
|
||||
# HOST_PORT=3000
|
||||
# PORT=3000
|
||||
|
||||
22
DOCKER.md
22
DOCKER.md
@@ -56,16 +56,30 @@ cp docker-compose.override.yml.example docker-compose.override.yml
|
||||
|
||||
All configuration is done through environment variables. If Navidrome server configuration is not provided via environment variables, the application will automatically prompt you to configure it within the client interface.
|
||||
|
||||
### Optional Variables
|
||||
### Runtime Environment Variables (Docker)
|
||||
|
||||
- `NEXT_PUBLIC_NAVIDROME_URL`: URL of your Navidrome server (optional - app will prompt if not set)
|
||||
- `NEXT_PUBLIC_NAVIDROME_USERNAME`: Navidrome username (optional - app will prompt if not set)
|
||||
- `NEXT_PUBLIC_NAVIDROME_PASSWORD`: Navidrome password (optional - app will prompt if not set)
|
||||
When running with Docker, use these variable names (without the `NEXT_PUBLIC_` prefix):
|
||||
|
||||
- `NAVIDROME_URL`: URL of your Navidrome server (optional - app will prompt if not set)
|
||||
- `NAVIDROME_USERNAME`: Navidrome username (optional - app will prompt if not set)
|
||||
- `NAVIDROME_PASSWORD`: Navidrome password (optional - app will prompt if not set)
|
||||
- `PORT`: Port for the application to listen on (default: `3000`)
|
||||
- `HOST_PORT`: Host port to map to container port (docker-compose only, default: `3000`)
|
||||
- `POSTHOG_KEY`: PostHog analytics key (optional)
|
||||
- `POSTHOG_HOST`: PostHog analytics host (optional)
|
||||
|
||||
### Development Environment Variables
|
||||
|
||||
For local development (non-Docker), use these variable names:
|
||||
|
||||
- `NEXT_PUBLIC_NAVIDROME_URL`: URL of your Navidrome server
|
||||
- `NEXT_PUBLIC_NAVIDROME_USERNAME`: Navidrome username
|
||||
- `NEXT_PUBLIC_NAVIDROME_PASSWORD`: Navidrome password
|
||||
- `NEXT_PUBLIC_POSTHOG_KEY`: PostHog analytics key (optional)
|
||||
- `NEXT_PUBLIC_POSTHOG_HOST`: PostHog analytics host (optional)
|
||||
|
||||
**Note**: Docker deployment uses a runtime replacement mechanism to inject environment variables, while development uses Next.js's built-in `NEXT_PUBLIC_` variables.
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic Setup (App will prompt for configuration)
|
||||
|
||||
21
Dockerfile
21
Dockerfile
@@ -16,13 +16,13 @@ RUN pnpm install
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Set default environment variables (can be overridden at runtime)
|
||||
# Navidrome configuration is optional - app will prompt if not provided
|
||||
ENV NEXT_PUBLIC_NAVIDROME_URL=""
|
||||
ENV NEXT_PUBLIC_NAVIDROME_USERNAME=""
|
||||
ENV NEXT_PUBLIC_NAVIDROME_PASSWORD=""
|
||||
ENV NEXT_PUBLIC_POSTHOG_KEY=""
|
||||
ENV NEXT_PUBLIC_POSTHOG_HOST=""
|
||||
# Set environment variable placeholders during build
|
||||
# These will be replaced at runtime with actual values
|
||||
ENV NEXT_PUBLIC_NAVIDROME_URL=NEXT_PUBLIC_NAVIDROME_URL
|
||||
ENV NEXT_PUBLIC_NAVIDROME_USERNAME=NEXT_PUBLIC_NAVIDROME_USERNAME
|
||||
ENV NEXT_PUBLIC_NAVIDROME_PASSWORD=NEXT_PUBLIC_NAVIDROME_PASSWORD
|
||||
ENV NEXT_PUBLIC_POSTHOG_KEY=NEXT_PUBLIC_POSTHOG_KEY
|
||||
ENV NEXT_PUBLIC_POSTHOG_HOST=NEXT_PUBLIC_POSTHOG_HOST
|
||||
ENV PORT=3000
|
||||
|
||||
# Generate git commit hash for build info (fallback if not available)
|
||||
@@ -31,8 +31,15 @@ RUN echo "NEXT_PUBLIC_COMMIT_SHA=docker-build" > .env.local
|
||||
# Build the application
|
||||
RUN pnpm build
|
||||
|
||||
# Copy entrypoint script
|
||||
COPY entrypoint.sh /usr/bin/
|
||||
RUN chmod +x /usr/bin/entrypoint.sh
|
||||
|
||||
# Expose the port
|
||||
EXPOSE $PORT
|
||||
|
||||
# Set entrypoint to replace env vars at runtime
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
|
||||
# Start the application
|
||||
CMD ["sh", "-c", "pnpm start -p $PORT"]
|
||||
29
docker-compose.example.yml
Normal file
29
docker-compose.example.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mice:
|
||||
container_name: mice-public
|
||||
image: ghcr.io/sillyangel/mice:latest
|
||||
ports:
|
||||
- "40625:40625"
|
||||
environment:
|
||||
# Navidrome Server Configuration
|
||||
- NAVIDROME_URL=https://navi.sillyangel.dev
|
||||
- NAVIDROME_USERNAME=kryptonite
|
||||
- NAVIDROME_PASSWORD=kryptonite
|
||||
|
||||
# PostHog Analytics
|
||||
- POSTHOG_KEY=phc_Sa39J7754MwaHrPxYiWnWETVSD3g1cU4nOplMGczRE9
|
||||
- POSTHOG_HOST=https://us.i.posthog.com
|
||||
|
||||
# Application Port
|
||||
- PORT=40625
|
||||
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:40625"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
restart: unless-stopped
|
||||
@@ -6,12 +6,11 @@ services:
|
||||
ports:
|
||||
- "${HOST_PORT:-3000}:${PORT:-3000}"
|
||||
environment:
|
||||
# Navidrome Server Configuration (OPTIONAL)
|
||||
# Uncomment and configure these if you want to pre-configure the server connection
|
||||
# If not set, the app will prompt you to configure these settings on first launch
|
||||
# - NEXT_PUBLIC_NAVIDROME_URL=${NAVIDROME_URL:-}
|
||||
# - NEXT_PUBLIC_NAVIDROME_USERNAME=${NAVIDROME_USERNAME:-}
|
||||
# - NEXT_PUBLIC_NAVIDROME_PASSWORD=${NAVIDROME_PASSWORD:-}
|
||||
# Navidrome Server Configuration
|
||||
# These will be injected at runtime using the entrypoint script
|
||||
- NEXT_PUBLIC_NAVIDROME_URL=${NAVIDROME_URL:-}
|
||||
- NEXT_PUBLIC_NAVIDROME_USERNAME=${NAVIDROME_USERNAME:-}
|
||||
- NEXT_PUBLIC_NAVIDROME_PASSWORD=${NAVIDROME_PASSWORD:-}
|
||||
|
||||
# PostHog Analytics (optional)
|
||||
- NEXT_PUBLIC_POSTHOG_KEY=${POSTHOG_KEY:-}
|
||||
|
||||
20
entrypoint.sh
Normal file
20
entrypoint.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "🔧 Replacing environment variable placeholders..."
|
||||
|
||||
# Replace env variable placeholders with real values for NEXT_PUBLIC_ variables
|
||||
printenv | grep NEXT_PUBLIC_ | while read -r line ; do
|
||||
key=$(echo "$line" | cut -d "=" -f1)
|
||||
value=$(echo "$line" | cut -d "=" -f2-)
|
||||
|
||||
echo " 🔄 Replacing $key with actual value"
|
||||
|
||||
# Replace in all .next files
|
||||
find /app/.next/ -type f \( -name "*.js" -o -name "*.json" \) -exec sed -i "s|$key|$value|g" {} \; 2>/dev/null || true
|
||||
done
|
||||
|
||||
echo "✅ Environment variable replacement complete"
|
||||
|
||||
# Execute the container's main process (CMD in Dockerfile)
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user