mirror of
https://github.com/TDSCDMAA/AutoMihoyoBBS.git
synced 2026-06-02 18:43:42 +08:00
完善了对docker的支持
This commit is contained in:
parent
030ed2725b
commit
4f0b1e52c6
32
Dockerfile
32
Dockerfile
@ -1,25 +1,19 @@
|
||||
FROM python:3.8-slim-buster
|
||||
FROM python:3-alpine
|
||||
LABEL maintainer="mailto@wolfbolin.com"
|
||||
|
||||
# Why need these step?
|
||||
# - fast mirror source
|
||||
# - procps contains useful proccess control commands like: free, kill, pkill, ps, top
|
||||
# - wget is quite basic tool
|
||||
# - vim for online debugging
|
||||
# - sync timezone
|
||||
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
|
||||
&& sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
|
||||
&& apt-get update && apt-get install -y --no-install-recommends procps wget vim \
|
||||
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||
ENV CRON_SIGNIN='30 9 * * *'
|
||||
ENV MULTI=TRUE
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN adduser app -D
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
|
||||
&& apk add --no-cache tzdata
|
||||
|
||||
# Project environment
|
||||
WORKDIR /tmp
|
||||
ADD requirements.txt ./
|
||||
RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
|
||||
|
||||
USER app
|
||||
WORKDIR /var/app
|
||||
COPY . /var/app
|
||||
|
||||
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip \
|
||||
&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
|
||||
|
||||
# Docker operation parameters
|
||||
ENV MULTI TRUE
|
||||
|
||||
CMD if [ $MULTI==TRUE ];then python main_multi.py autorun;else python main.py;fi
|
||||
CMD ["python3", "./docker.py" ]
|
||||
|
||||
10
docker-compose.yml
Normal file
10
docker-compose.yml
Normal file
@ -0,0 +1,10 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
mihoyo-bbs:
|
||||
image: darkatse/mihoyo-bbs
|
||||
environment:
|
||||
- CRON_SIGNIN=30 9 * * *
|
||||
- MULTI=TRUE
|
||||
volumes:
|
||||
- .:/var/app
|
||||
57
docker.py
Normal file
57
docker.py
Normal file
@ -0,0 +1,57 @@
|
||||
import datetime
|
||||
import os
|
||||
import logging
|
||||
import signal
|
||||
import time
|
||||
#from settings import *
|
||||
|
||||
from crontab import CronTab
|
||||
|
||||
time_format = "%Y-%m-%d %H:%M:%S"
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s %(levelname)s %(message)s',
|
||||
datefmt='%Y-%m-%dT%H:%M:%S')
|
||||
|
||||
|
||||
log = logging
|
||||
|
||||
def stop_me(_signo, _stack):
|
||||
log.info("Docker container has stoped....")
|
||||
exit(-1)
|
||||
|
||||
|
||||
def main():
|
||||
signal.signal(signal.SIGINT, stop_me)
|
||||
log.info("使用DOCKER运行米游社签到")
|
||||
env = os.environ
|
||||
cron_signin = env["CRON_SIGNIN"]
|
||||
cron = CronTab(cron_signin, loop=True, random_seconds=True)
|
||||
|
||||
def next_run_time():
|
||||
nt = datetime.datetime.now().strftime(time_format)
|
||||
delayt = cron.next(default_utc=False)
|
||||
nextrun = datetime.datetime.now() + datetime.timedelta(seconds=delayt)
|
||||
nextruntime = nextrun.strftime(time_format)
|
||||
log.info(f"Current running datetime: {nt}")
|
||||
log.info(f"Next run datetime: {nextruntime}")
|
||||
|
||||
def sign():
|
||||
log.info("Starting signing")
|
||||
multi = env["MULTI"]
|
||||
if multi:
|
||||
os.system("python3 ./main_multi.py autorun")
|
||||
else:
|
||||
os.system("python3 ./main.py")
|
||||
|
||||
sign()
|
||||
next_run_time()
|
||||
while True:
|
||||
ct = cron.next(default_utc=False)
|
||||
time.sleep(ct)
|
||||
sign()
|
||||
next_run_time()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -1,2 +1,3 @@
|
||||
httpx>=0.21.1
|
||||
requests>=2.26.0
|
||||
crontab~=0.22.9
|
||||
|
||||
Loading…
Reference in New Issue
Block a user