Skip to content

Commit 1c8ae71

Browse files
bakerboy448claude
andcommitted
Fixed: Docker config file support and documentation
Critical fixes for v1.4.0: - s6 run script now passes --config /config/config.json to application - s6 service uses symlink instead of text file (fixes exec format error) - init script validates config file OR environment variables (not requiring both) - Added troubleshooting tools (procps, htop, vim-tiny) - Updated README with correct /config mount pattern and Docker Compose examples This hotfix resolves container startup failures and improves Docker deployment experience. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3020912 commit 1c8ae71

File tree

2 files changed

+111
-54
lines changed

2 files changed

+111
-54
lines changed

Dockerfile

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3232
ca-certificates \
3333
curl \
3434
xz-utils \
35+
procps \
36+
htop \
37+
vim-tiny \
3538
&& rm -rf /var/lib/apt/lists/*
3639

3740
# Install s6-overlay for proper init and user management
@@ -73,41 +76,37 @@ RUN mkdir -p /config /config/data /config/logs /app /etc/s6-overlay/s6-rc.d/modl
7376
RUN echo '#!/command/with-contenv bash\n\
7477
set -e\n\
7578
\n\
76-
# Validate critical environment variables\n\
77-
echo "Validating required environment variables..."\n\
78-
\n\
79-
missing_vars=()\n\
80-
\n\
81-
[ -z "$REDDIT_CLIENT_ID" ] && missing_vars+=("REDDIT_CLIENT_ID")\n\
82-
[ -z "$REDDIT_CLIENT_SECRET" ] && missing_vars+=("REDDIT_CLIENT_SECRET")\n\
83-
[ -z "$REDDIT_USERNAME" ] && missing_vars+=("REDDIT_USERNAME")\n\
84-
[ -z "$REDDIT_PASSWORD" ] && missing_vars+=("REDDIT_PASSWORD")\n\
85-
[ -z "$SOURCE_SUBREDDIT" ] && missing_vars+=("SOURCE_SUBREDDIT")\n\
86-
\n\
87-
if [ ${#missing_vars[@]} -ne 0 ]; then\n\
88-
echo "ERROR: Missing required environment variables:" >&2\n\
89-
printf " - %s\n" "${missing_vars[@]}" >&2\n\
90-
echo "" >&2\n\
91-
echo "Please set all required environment variables and restart the container." >&2\n\
92-
exit 1\n\
79+
# Validate that we have either config file OR environment variables\n\
80+
if [ ! -f /config/config.json ]; then\n\
81+
echo "No config file found at /config/config.json, checking environment variables..."\n\
82+
missing_vars=()\n\
83+
[ -z "$REDDIT_CLIENT_ID" ] && missing_vars+=("REDDIT_CLIENT_ID")\n\
84+
[ -z "$REDDIT_CLIENT_SECRET" ] && missing_vars+=("REDDIT_CLIENT_SECRET")\n\
85+
[ -z "$REDDIT_USERNAME" ] && missing_vars+=("REDDIT_USERNAME")\n\
86+
[ -z "$REDDIT_PASSWORD" ] && missing_vars+=("REDDIT_PASSWORD")\n\
87+
[ -z "$SOURCE_SUBREDDIT" ] && missing_vars+=("SOURCE_SUBREDDIT")\n\
88+
if [ ${#missing_vars[@]} -ne 0 ]; then\n\
89+
echo "ERROR: No config file and missing required environment variables:" >&2\n\
90+
printf " - %s\n" "${missing_vars[@]}" >&2\n\
91+
echo "" >&2\n\
92+
echo "Either mount a config file to /config/config.json OR set environment variables." >&2\n\
93+
exit 1\n\
94+
fi\n\
95+
echo "Using environment variables for configuration"\n\
96+
else\n\
97+
echo "Using config file: /config/config.json"\n\
9398
fi\n\
9499
\n\
95-
echo "All required environment variables are set."\n\
96-
\n\
97100
PUID=${PUID:-1000}\n\
98101
PGID=${PGID:-1000}\n\
99-
\n\
100102
echo "Setting UID:GID to ${PUID}:${PGID}"\n\
101103
\n\
102-
# Update user and group IDs\n\
103104
groupmod -o -g "$PGID" modlogbot\n\
104105
usermod -o -u "$PUID" modlogbot\n\
105106
\n\
106-
# Fix ownership\n\
107-
echo "Fixing ownership of /config and /app"\n\
108-
chown -R modlogbot:modlogbot /config /app\n\
107+
echo "Fixing ownership of /config"\n\
108+
chown -R modlogbot:modlogbot /config\n\
109109
\n\
110-
# Ensure data directory has correct permissions\n\
111110
if [ ! -f /config/data/modlog.db ]; then\n\
112111
echo "Initializing database directory"\n\
113112
touch /config/data/modlog.db\n\
@@ -118,14 +117,14 @@ fi' > /etc/s6-overlay/scripts/init-modlogbot-run && \
118117
# Create s6 service run script
119118
RUN echo '#!/command/with-contenv bash\n\
120119
cd /app\n\
121-
exec s6-setuidgid modlogbot python modlog_wiki_publisher.py --continuous' > /etc/s6-overlay/scripts/modlog-bot-run && \
120+
exec s6-setuidgid modlogbot python modlog_wiki_publisher.py --config /config/config.json --continuous' > /etc/s6-overlay/scripts/modlog-bot-run && \
122121
chmod +x /etc/s6-overlay/scripts/modlog-bot-run
123122

124123
# Setup s6 service definitions
125124
RUN echo 'oneshot' > /etc/s6-overlay/s6-rc.d/init-modlogbot/type && \
126125
echo '/etc/s6-overlay/scripts/init-modlogbot-run' > /etc/s6-overlay/s6-rc.d/init-modlogbot/up && \
127126
echo 'longrun' > /etc/s6-overlay/s6-rc.d/modlog-bot/type && \
128-
echo '/etc/s6-overlay/scripts/modlog-bot-run' > /etc/s6-overlay/s6-rc.d/modlog-bot/run && \
127+
ln -s /etc/s6-overlay/scripts/modlog-bot-run /etc/s6-overlay/s6-rc.d/modlog-bot/run && \
129128
echo 'init-modlogbot' > /etc/s6-overlay/s6-rc.d/modlog-bot/dependencies && \
130129
touch /etc/s6-overlay/s6-rc.d/user/contents.d/init-modlogbot && \
131130
touch /etc/s6-overlay/s6-rc.d/user/contents.d/modlog-bot

README.md

Lines changed: 85 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -228,53 +228,111 @@ The database includes comprehensive moderation data with full transparency:
228228
229229
### Quick Start with Docker
230230
231+
The recommended approach is to use a config file for all settings:
232+
231233
```bash
232-
# Using Docker Compose (recommended)
233-
docker-compose up -d
234+
# 1. Create config directory structure
235+
mkdir -p ./config/data ./config/logs
236+
237+
# 2. Create config.json from template
238+
cp config_template.json ./config/config.json
239+
# Edit ./config/config.json with your credentials
234240
235-
# Using Docker directly
241+
# 3. Run with config file (recommended)
236242
docker run -d \
237243
--name reddit-modlog \
244+
-e PUID=1000 \
245+
-e PGID=1000 \
246+
-v ./config:/config \
247+
ghcr.io/bakerboy448/redditmodlog:latest
248+
249+
# 4. Using Docker Compose (recommended)
250+
docker compose up -d
251+
```
252+
253+
**What gets mounted to `/config`:**
254+
- `config.json` - Your configuration file (auto-updated with new defaults on upgrades)
255+
- `data/modlog.db` - SQLite database (persistent)
256+
- `logs/` - Per-subreddit log files
257+
258+
### Alternative: Environment Variables
259+
260+
You can use environment variables instead of a config file:
261+
262+
```bash
263+
docker run -d \
264+
--name reddit-modlog \
265+
-e PUID=1000 \
266+
-e PGID=1000 \
238267
-e REDDIT_CLIENT_ID=your_client_id \
239268
-e REDDIT_CLIENT_SECRET=your_client_secret \
240269
-e REDDIT_USERNAME=your_username \
241270
-e REDDIT_PASSWORD=your_password \
242271
-e SOURCE_SUBREDDIT=yoursubreddit \
243-
-e PUID=1000 \
244-
-e PGID=1000 \
245-
-v ./data:/config/data \
246-
-v ./logs:/config/logs \
272+
-v ./config:/config \
247273
ghcr.io/bakerboy448/redditmodlog:latest
248274
```
249275
250-
### Docker Environment Variables
251-
252-
```env
253-
# User/Group IDs for file permissions
254-
PUID=1000
255-
PGID=1000
256-
257-
# Reddit API credentials (REQUIRED)
258-
REDDIT_CLIENT_ID=your_client_id
259-
REDDIT_CLIENT_SECRET=your_client_secret
260-
REDDIT_USERNAME=your_bot_username
261-
REDDIT_PASSWORD=your_bot_password
262-
263-
# Application settings
264-
SOURCE_SUBREDDIT=yoursubreddit
265-
WIKI_PAGE=modlog
266-
RETENTION_DAYS=30
267-
BATCH_SIZE=100
268-
UPDATE_INTERVAL=300
269-
ANONYMIZE_MODERATORS=true
276+
### Docker Compose Example
277+
278+
```yaml
279+
version: '3.8'
280+
281+
services:
282+
redditmodlog-opensignups:
283+
image: ghcr.io/bakerboy448/redditmodlog:latest
284+
container_name: redditmodlog-opensignups
285+
restart: unless-stopped
286+
environment:
287+
- PUID=1000
288+
- PGID=1000
289+
volumes:
290+
- ./opensignups:/config
291+
mem_limit: 256m
292+
cpus: 0.5
270293
```
271294
295+
### Environment Variables
296+
297+
**User/Group IDs** (for file permissions):
298+
- `PUID` - User ID (default: 1000)
299+
- `PGID` - Group ID (default: 1000)
300+
301+
**Reddit API Credentials** (required if not using config file):
302+
- `REDDIT_CLIENT_ID` - Reddit app client ID
303+
- `REDDIT_CLIENT_SECRET` - Reddit app client secret
304+
- `REDDIT_USERNAME` - Bot username
305+
- `REDDIT_PASSWORD` - Bot password
306+
- `SOURCE_SUBREDDIT` - Subreddit name
307+
308+
**Optional Settings** (override config.json if set):
309+
- `WIKI_PAGE` - Wiki page name (default: modlog)
310+
- `RETENTION_DAYS` - Database retention in days (default: 90, max: 365)
311+
- `BATCH_SIZE` - Entries per fetch (default: 50, max: 500)
312+
- `UPDATE_INTERVAL` - Seconds between updates (default: 600, max: 3600)
313+
- `ANONYMIZE_MODERATORS` - true/false (default: true)
314+
315+
**Internal Paths** (don't modify):
316+
- `DATABASE_PATH=/config/data/modlog.db`
317+
- `LOGS_DIR=/config/logs`
318+
272319
### Docker Image
273320
274321
Pre-built images available at:
275322
- `ghcr.io/bakerboy448/redditmodlog:latest`
323+
- `ghcr.io/bakerboy448/redditmodlog:v1.4.x` (specific versions)
276324
- Multi-architecture: `linux/amd64`, `linux/arm64`
277325
326+
### Docker Features
327+
328+
- ✅ s6-overlay v3 init system for proper process management
329+
- ✅ PUID/PGID support for file permission management
330+
- ✅ Automatic config file updates on version upgrades
331+
- ✅ Single `/config` mount for all persistent data
332+
- ✅ Supports both config file and environment variable configuration
333+
- ✅ Built-in troubleshooting tools (htop, vim)
334+
- ✅ Health checks for monitoring
335+
278336
## Systemd Service (Production)
279337
280338
### Installation

0 commit comments

Comments
 (0)