Rock-Candy-Tea / hexo-circle-of-friends

Python gets the friend's articles from hexo's friend-links
Apache License 2.0
277 stars 533 forks source link

建议:后端部署方案优化 #104

Closed it985 closed 3 weeks ago

it985 commented 1 year ago

docker部署 文中写道 1,clone repo 2,docker pull yyyzyyyz/fcircle:latest 3,python3 deploy.py 选择docker--->部署 可以直接优化成docker pull yyyzyyyz/fcircle:latest (可以直接一步到位) 原因,都用docker了,再让使用者去python3 deploy.py 选择部署方式是不是有点繁琐(ps:至少我个人来说)

hiltay commented 1 year ago

这部分应该可以适当优化,在启动容器时一步到位完成 后续会考虑简化docker部署的操作,感谢反馈

it985 commented 1 year ago

这部分应该可以适当优化,在启动容器时一步到位完成 后续会考虑简化docker部署的操作,感谢反馈

好的,期待ing....

2X-ercha commented 1 year ago

之前做了个测试可以大概可以作为解决方案之一:

  1. 引入 pip 库 cron-lite,直接将爬虫 run.py 作为子进程通过 cron 调用
  2. 新建 py 如下:

    import os
    from cron_lite import cron_task, start_all
    from threading import Thread
    
    @cron_task("0 0/8 * * *")
    def spider_task():
      print("[cron]: fcircle spider start!")
      os.system("python -u ./fcircle/run.py")
    
    if __name__ == "__main__":
      api_process = start_all(spawn = True)
      os.system("python -u ./api/main.py")
  3. dockerfile 如下(这里测试使用的是 python 的官方镜像,跟原本的不太相同,不够构建大小可能会更小一点)
    FROM python:3.10.11-alpine3.18
    MAINTAINER noionion
    EXPOSE 8000
    WORKDIR /home/fcircle_server
    COPY . /home/fcircle_server
    ENV TimeZone=Asia/Shanghai
    ENV BASEPATH=/home/fcircle_server/
    RUN pip3 install -r ./requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple \
      && ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone
    CMD ["python3", "-u", "./main.py"]
  4. 常规提供的 docker 部署指令:
    docker run -d \
    --name fcircle \
    -p 8000:8000 \
    fcircle:xxx

以上仅供参考,对现在友圈的配置和逻辑不太熟悉了,不太好直接修改进行 pull 了。但依照大多数提供 docker 部署的开源程序,提供 docker 部署的单指令是较为常态化的解决方案。setting.py的内容也可以考虑移动到前端设置中。