~cytrogen/srht-deploy

srht-deploy/git-custom/Dockerfile -rw-r--r-- 1.3 KiB
6b7b1351 — Cytrogen 修复 README 里的 Markdown 格式错误 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
FROM ghcr.io/k8ieone/srht-git:latest

# --- 依赖修复 ---
# pgpy: git.sr.ht 需要但镜像缺失
# openssh-server: SSH push 支持
RUN apk add --no-cache py3-pip openssh-server \
    && pip3 install pgpy

# --- SSH 配置 ---
# 生成主机密钥
RUN ssh-keygen -A

# 解锁 git 用户(SSH 登录需要)
RUN echo 'git:x' | chpasswd

# 配置 sshd 使用 sourcehut 的 key dispatch
COPY sshd_config_patch /tmp/sshd_config_patch
RUN cat /tmp/sshd_config_patch >> /etc/ssh/sshd_config \
    && rm /tmp/sshd_config_patch

# 修复 start.sh 中 sshd 启动路径(Alpine 需要绝对路径)
RUN sed -i 's|sshd &|/usr/sbin/sshd \&|' /start.sh

# --- libgit2 属主检查修复 ---
# gunicorn 以 root 运行,但 SSH 推送创建的仓库属于 git 用户
# libgit2 (pygit2) 会拒绝 root 访问非 root 的仓库
# 在启动时将仓库顶层目录 chown 为 root(内部文件保持 git 用户,不影响 SSH 推送)
RUN sed -i '1a find /var/lib/git -mindepth 2 -maxdepth 2 -type d -exec chown root:git {} \\; -exec chmod g+ws {} \\; 2>/dev/null || true' /start.sh

# --- Jinja2 修复 ---
# 上游 core.sr.ht 已修复但此镜像未包含:启用 {% do %} 模板标签
COPY fix_jinja2_do.py /tmp/fix_jinja2_do.py
RUN python3 /tmp/fix_jinja2_do.py && rm /tmp/fix_jinja2_do.py