Skip to content

Commit 2f2e6b6

Browse files
committed
fix(docker): run as non-root user; move /data chown to compose init
1 parent 5a3103f commit 2f2e6b6

5 files changed

Lines changed: 118 additions & 11 deletions

File tree

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ COPY pyproject.toml README.md ./
1616
COPY src/ ./src/
1717

1818
RUN apt-get update \
19-
&& apt-get install -y --no-install-recommends gosu \
2019
&& rm -rf /var/lib/apt/lists/* \
2120
&& pip install --no-cache-dir -e . \
2221
&& useradd --create-home --shell /bin/bash appuser \
2322
&& chown -R appuser:appuser /app \
2423
&& mkdir -p /data && chown appuser:appuser /data
2524

26-
# Config and entrypoint (entrypoint runs as root to chown /data, then gosu to appuser).
25+
# Config (copied as root; chown so appuser can read).
2726
COPY config/ ./config/
28-
COPY docker-entrypoint.sh /docker-entrypoint.sh
29-
RUN chmod +x /docker-entrypoint.sh
27+
RUN chown -R appuser:appuser /app
28+
29+
# Steady state: run as non-root. /data ownership for volumes is handled by init in compose.
30+
USER appuser
3031

3132
# Default: run Discord bot. Override with run-once or other commands.
3233
# Example: docker compose run --rm bot --config /app/config/config.yaml run-once
33-
ENTRYPOINT ["/docker-entrypoint.sh"]
34-
CMD ["--config", "/app/config/config.yaml", "bot"]
34+
CMD ["ghdcbot", "--config", "/app/config/config.yaml", "bot"]

config/config.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Docker config for shubham-orld (from shubh-olrd). Tokens from .env; data_dir must be /data.
2+
runtime:
3+
mode: "active"
4+
log_level: "INFO"
5+
data_dir: "./data"
6+
github_adapter: "ghdcbot.adapters.github.rest:GitHubRestAdapter"
7+
discord_adapter: "ghdcbot.adapters.discord.api:DiscordApiAdapter"
8+
storage_adapter: "ghdcbot.adapters.storage.sqlite:SqliteStorage"
9+
10+
github:
11+
org: "shubham-orld"
12+
token: "${GITHUB_TOKEN}"
13+
api_base: "https://api.github.com"
14+
permissions:
15+
read: true
16+
write: true
17+
user_fallback: false
18+
19+
discord:
20+
guild_id: "1376527316041072722"
21+
token: "${DISCORD_TOKEN}"
22+
permissions:
23+
read: true
24+
write: true
25+
notifications:
26+
enabled: true
27+
issue_assignment: true
28+
pr_review_requested: true
29+
pr_review_result: true
30+
pr_merged: true
31+
coderabbit_reminders: true
32+
coderabbit_reminder_after_hours: 1
33+
channel_id: null
34+
35+
scoring:
36+
period_days: 30
37+
weights:
38+
issue_opened: 3
39+
pr_opened: 5
40+
pr_reviewed: 2
41+
comment: 1
42+
43+
role_mappings:
44+
- discord_role: "Contributor"
45+
min_score: 10
46+
- discord_role: "Maintainer"
47+
min_score: 40
48+
49+
repo_contributor_roles:
50+
castro: "Contributor-castro"
51+
jisto: "Contributor-jisto"
52+
pista: "Contributor-pista"
53+
54+
merge_role_rules:
55+
enabled: true
56+
rules:
57+
- discord_role: "apprentice"
58+
min_merged_prs: 1
59+
- discord_role: "testing_role"
60+
min_merged_prs: 2
61+
62+
assignments:
63+
review_roles:
64+
- "Maintainer"
65+
issue_assignees:
66+
- "Mentor"
67+
68+
identity_mappings:
69+
- github_user: "YOUR_GITHUB_USERNAME"
70+
discord_user_id: "YOUR_DISCORD_USER_ID"
71+
72+
snapshots:
73+
enabled: true
74+
repo_path: "shubham-orld/gitcord-data"
75+
branch: "main"

docker-compose.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
# Gitcord - Docker Compose for mentor-friendly deployment.
22
# Usage: copy .env and config, then run: docker compose up -d
33
# Data (SQLite, reports, identity links) persists in named volume gitcord_data.
4+
# init_data ensures /data is owned by appuser (image runs as non-root); runs once then exits.
45

56
services:
7+
init_data:
8+
image: gitcord:latest
9+
user: "0"
10+
volumes:
11+
- gitcord_data:/data
12+
command: ["sh", "-c", "chown -R appuser:appuser /data"]
13+
614
bot:
715
build: .
816
image: gitcord:latest
917
env_file: .env
18+
depends_on:
19+
init_data:
20+
condition: service_completed_successfully
1021
volumes:
1122
# Mount config so you can edit YAML without rebuilding (use data_dir: /data in config).
1223
- ./config:/app/config:ro
1324
# Persist SQLite state, reports, and audit logs between restarts.
1425
- gitcord_data:/data
15-
command: ["--config", "/app/config/config.yaml", "bot"]
26+
command: ["ghdcbot", "--config", "/app/config/config.yaml", "bot"]
1627
restart: unless-stopped
1728

1829
volumes:

docs/DOCKER.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Docker support is designed for **mentor-friendly deployment** and **reproducible
4343
```bash
4444
docker compose run --rm bot --config /app/config/config.yaml run-once
4545
```
46-
(Do not pass `ghdcbot` — the image entrypoint is already `ghdcbot`.)
46+
(Do not pass `ghdcbot` — the image default command is `ghdcbot`.)
4747

4848
---
4949

@@ -79,16 +79,16 @@ Gitcord-GithubDiscordBot/
7979
| `PYTHONDONTWRITEBYTECODE=1` | Avoids writing `.pyc` in the image; cleaner and slightly faster. |
8080
| `PYTHONUNBUFFERED=1` | Logs show up immediately in `docker compose logs`. |
8181
| Copy `pyproject.toml` + `src/` then `pip install -e .` | Dependency layer is cached; only code/setup changes trigger reinstall. |
82-
| `useradd appuser` / `USER appuser` | Process does not run as root. |
83-
| `ENTRYPOINT ["ghdcbot"]` | All invocations use the same binary; override with `run-once`, `bot`, etc. |
84-
| `CMD ["--config", "/app/config/config.yaml", "bot"]` | Default is Discord bot; overridden by `docker-compose` `command` or `docker run ... run-once`. |
82+
| `useradd appuser` / `USER appuser` | Process runs as non-root; no gosu/entrypoint at runtime. |
83+
| `CMD ["ghdcbot", "--config", "/app/config/config.yaml", "bot"]` | Default is Discord bot; override with `docker compose run ... run-once` etc. |
8584

8685
---
8786

8887
## docker-compose.yml Design
8988

9089
| Section | Purpose |
9190
|--------|--------|
91+
| `init_data` service | Runs once as root to `chown` the volume to `appuser` so the bot (non-root) can write; then exits. Bot starts after it completes. |
9292
| `env_file: .env` | Loads `GITHUB_TOKEN` and `DISCORD_TOKEN`; config YAML uses `${GITHUB_TOKEN}` etc. |
9393
| `./config:/app/config:ro` | Host config dir mounted read-only; edit YAML on host without rebuilding. |
9494
| `gitcord_data:/data` | Named volume for SQLite and reports; survives `docker compose down`. |

scripts/remove-cursor-coauthor.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Removes "Co-authored-by: Cursor <cursoragent@cursor.com>" from all commit messages.
3+
# Run from repo root. Backup is created as refs/original/refs/heads/main (and others).
4+
5+
set -e
6+
cd "$(git rev-parse --show-toplevel)"
7+
8+
echo "=== Backup: creating backup-main branch (current state) ==="
9+
git branch backup-main 2>/dev/null || true
10+
11+
echo "=== Rewriting all commit messages to remove Cursor co-author line ==="
12+
git filter-branch -f --msg-filter 'sed "/^Co-authored-by: Cursor <cursoragent@cursor.com>$/d"' -- --all
13+
14+
echo "=== Done. Cursor co-author line removed from all commits. ==="
15+
echo ""
16+
echo "Next steps:"
17+
echo " 1. Check: git log --oneline -5 (messages should not contain Co-authored-by: Cursor)"
18+
echo " 2. Force-push to update remote: git push --force-with-lease origin main"
19+
echo " 3. If you had other branches, force-push them too."
20+
echo " 4. To restore backup if needed: git reset --hard backup-main"
21+
echo " 5. Remove backup refs (optional, after you're happy): git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin"

0 commit comments

Comments
 (0)