diff --git a/Dockerfile b/Dockerfile index e1905e41..d09890ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.10.11-slim ENV LANG="C.UTF-8" \ + HOME="/moviepilot" \ + TERM="xterm" \ TZ="Asia/Shanghai" \ PUID=0 \ PGID=0 \ @@ -30,16 +32,33 @@ ENV LANG="C.UTF-8" \ WORKDIR "/app" COPY . . RUN apt-get update \ - && apt-get -y install musl-dev nginx gettext-base \ - && mkdir -p /etc/nginx \ + && apt-get -y install \ + musl-dev \ + nginx \ + gettext-base \ + locales \ + procps \ + gosu \ + bash \ + && mkdir -p /etc/nginx ${HOME} \ && cp -f nginx.conf /etc/nginx/nginx.template.conf \ + && groupadd -r moviepilot -g 911 \ + && useradd -r moviepilot -g moviepilot -d ${HOME} -s /bin/bash -u 911 \ + && pip install --upgrade pip \ && pip install -r requirements.txt \ + && playwright install-deps chromium \ && python_ver=$(python3 -V | awk '{print $2}') \ && echo "/app/" > /usr/local/lib/python${python_ver%.*}/site-packages/app.pth \ && echo 'fs.inotify.max_user_watches=5242880' >> /etc/sysctl.conf \ && echo 'fs.inotify.max_user_instances=5242880' >> /etc/sysctl.conf \ - && playwright install-deps chromium \ - && rm -rf /root/.cache/ + && locale-gen zh_CN.UTF-8 \ + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf \ + /tmp/* \ + /moviepilot/.cache \ + /var/lib/apt/lists/* \ + /var/tmp/* EXPOSE 3000 VOLUME ["/config"] -ENTRYPOINT [ "bash", "-c", "/app/start.sh & nginx -g 'daemon off;'" ] +ENTRYPOINT [ "/app/start.sh" ] diff --git a/start.sh b/start.sh index f1d7425b..645b8cb8 100644 --- a/start.sh +++ b/start.sh @@ -1,9 +1,17 @@ -#!/bin/sh +#!/bin/bash -umask ${UMASK} # 使用 `envsubst` 将模板文件中的 ${NGINX_PORT} 替换为实际的环境变量值 envsubst '${NGINX_PORT}' < /etc/nginx/nginx.template.conf > /etc/nginx/nginx.conf +# 更改 moviepilot userid 和 groupid +groupmod -o -g ${PGID} moviepilot +usermod -o -u ${PUID} moviepilot +# 更改文件权限 +chown -R moviepilot:moviepilot ${HOME} /app /config # 下载浏览器内核 -playwright install chromium +gosu moviepilot:moviepilot playwright install chromium +# 启动前端nginx服务 +nginx +# 设置后端服务权限掩码 +umask ${UMASK} # 启动后端服务 -python3 app/main.py +exec gosu moviepilot:moviepilot python3 app/main.py