ceajs / cea

高校统一身份验证开发框架(已集成 CPDAILY 签到&查寝插件)
MIT License
90 stars 16 forks source link

Docker 腾讯轻量服务器运行报错 #37

Closed allinu closed 2 years ago

allinu commented 2 years ago

部署环境:腾讯云轻量服务器 + Docker

构建的 Dockerfile

FROM ubuntu:latest
ENV TZ="Asia/Shanghai"
WORKDIR /cea
COPY ./cea-cron ./
RUN export DEBIAN_FRONTEND=noninteractive \
    && apt-get update \
    && apt-get install -yq cron tzdata curl \
    && ln -fs /usr/share/zoneinfo/$TZ /etc/localtime  \
    && dpkg-reconfigure -f noninteractive tzdata \
    && curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
    && apt-get install -y nodejs \
    && apt-get install -y postfix \
    && crontab /cea/cea-cron \
    && npm install -g cea \
    && apt-get clean \
    && rm -rf \
    "/tmp/!(conf)" \
    /usr/share/doc/* \
    /var/cache/* \
    /var/lib/apt/lists/* \
    /var/tmp/*
WORKDIR /cea/conf
VOLUME [ "/cea/conf/" ]
CMD postfix start && cron -f

报错信息:

# cea sign
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:371:5)
    at onParseError (node:internal/url:552:9)
    at new URL (node:internal/url:628:5)
    at FetchWithCookie.fetch (file:///usr/lib/node_modules/cea/node_modules/@ceajs/core/lib/src/utils/fetch-helper.js:25:34)
    at FetchWithCookie.get (file:///usr/lib/node_modules/cea/node_modules/@ceajs/core/lib/src/utils/fetch-helper.js:8:27)
    at login (file:///usr/lib/node_modules/cea/node_modules/@ceajs/core/lib/src/crawler/login.js:57:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async loginAndStoreCookie (file:///usr/lib/node_modules/cea/node_modules/@ceajs/core/lib/src/index.js:22:20)
    at async handleLogin (file:///usr/lib/node_modules/cea/node_modules/@ceajs/core/lib/src/index.js:41:17)
    at async file:///usr/lib/node_modules/cea/node_modules/@ceajs/core/lib/src/index.js:14:13 {
  input: 'null',
  code: 'ERR_INVALID_URL'
}

附加信息:

  1. 镜像构建成功
  2. 加载配置文件通过 image
beetcb commented 2 years ago

请提供一下在容器里运行以下命令的结果 @allinu cea get schools

allinu commented 2 years ago

@beetcb

以下,使用相同的配置文件

远程服务器端

image

本机电脑

image

beetcb commented 2 years ago

感觉不可能错,有 bind 文件夹吗 -v /tmp/conf:/tmp/conf ?

https://docs.docker.com/storage/bind-mounts/

虽然按理说没关系,但是这个报错意思就是没找到加载后的配置,也就是 /tmp/conf 目录下面缓存文件

beetcb commented 2 years ago

你用 docker file 声明的话,volume 里也要包含那个/tmp/conf 目录的,让加载的配置持久化 @allinu

allinu commented 2 years ago

@beetcb 好的我把这个目录加上测试一下

allinu commented 2 years ago

修改后如下

Dockerfile

FROM ubuntu:latest
ENV TZ="Asia/Shanghai"
WORKDIR /cea
COPY ./cea-cron ./
RUN export DEBIAN_FRONTEND=noninteractive \
    && apt-get update \
    && apt-get install -yq cron tzdata curl \
    && ln -fs /usr/share/zoneinfo/$TZ /etc/localtime  \
    && dpkg-reconfigure -f noninteractive tzdata \
    && curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
    && apt-get install -y nodejs \
    && apt-get install -y postfix \
    && crontab /cea/cea-cron \
    && npm install -g cea \
    && apt-get clean \
    && rm -rf \
    "/tmp/!(conf)" \
    /usr/share/doc/* \
    /var/cache/* \
    /var/lib/apt/lists/* \
    /var/tmp/*
WORKDIR /cea/conf
VOLUME [ "/cea/conf/","/tmp/conf"]
CMD postfix start && cron -f

Docker-Compose 部分

  sign_sever:
    depends_on:
      - api-server
    image: liona/cea
    restart: always
    volumes:
      - ./config:/cea/conf
      - ./tmp/config:/tmp/conf

查看目录下文件信息如下

image

重新构建了镜像,重新部署了,重新运行了命令 报错信息没有改变 @beetcb

我使用的源文件在这两个地方

beetcb commented 2 years ago

实例中 /tmp/conf 下必须有配置缓存,不能使用其它目录的

ls /tmp/conf/ ?

beetcb commented 2 years ago

为啥你宿主主机上缓存文件在 ./tmp 而不在 /tmp 😂 软链吗

allinu commented 2 years ago

@beetcb 我将内部的/tmp/conf目录映射到了本地的./tmp/config/这个不影响把,我其他的项目都是这样运行了,docker跑起来之后,我加载了配置文件,然后生成了缓存配置,然后在本地查看的缓存内容,本地映射的缓存目录与内部目录实时同步的,不是软链接,只是单纯的 -v

beetcb commented 2 years ago

哦,不影响 看起来没错呀 🐶,只是 bind mount 和 volume 应该使用一个就好了吧,你都用了,不清楚有没有副作用

我建议先看看实例上 /tmp/conf 到底有什么,确认一下

allinu commented 2 years ago

我下午检查一下目录内容,如果要是目录没有问题的话,我再用其他镜像构建一下,要是没啥大问题就好解决了,我怕是那个什么学校边缘啥的,那个我看你们都在讨论,我属实没看明白😅,我怕是那个问题就来提问了😜,我先解决看看

beetcb commented 2 years ago

嗯,因为本地能成功运行,那就是 dcoker 配置的问题了

allinu commented 2 years ago

排除目录映射错误

image

allinu commented 2 years ago

@beetcb 找到了,我最担心的事情发生了 网站屏蔽了腾讯云服务厂商的 IP 无解了

image