Skip to content

Commit 3a9f3e1

Browse files
authored
Merge pull request #3 from karuboniru/master
Build smaller docker image
2 parents 0d58b70 + 141c5b3 commit 3a9f3e1

5 files changed

Lines changed: 37 additions & 28 deletions

File tree

.github/workflows/docker.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ jobs:
1010
-
1111
name: Checkout
1212
uses: actions/checkout@v4
13-
- run: |
14-
sudo apt-get install aria2
15-
aria2c --seed-time=1 --select-file=1 https://sukebei.nyaa.si/download/3914574.torrent -d .
1613
-
1714
name: Login to Docker Hub
1815
uses: docker/login-action@v3

Dockerfile

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
FROM python:3.11
1+
FROM debian:12-slim AS build-venv
22

3-
WORKDIR /root
4-
5-
ENV content=/root/comiclib watch=False
6-
EXPOSE 8000
7-
8-
RUN apt-get -y update && apt-get -y install ffmpeg
9-
10-
COPY . /tmp/comiclib
11-
12-
RUN pip install --no-cache-dir -U "/tmp/comiclib[full]"
13-
RUN pip install --no-cache-dir -U gunicorn
3+
RUN apt-get update && \
4+
apt-get install --no-install-suggests --no-install-recommends --yes xz-utils python3 python3-venv && \
5+
apt-get clean && \
6+
python3 -m venv /venv && \
7+
/venv/bin/pip install --upgrade pip
148

9+
ADD https://files.niconi.org/api_dump.sqlite.7z /tmp
10+
ADD https://github.com/eugeneware/ffmpeg-static/releases/download/b6.0/ffmpeg-linux-x64 /usr/bin/ffmpeg
1511
ADD https://www.7-zip.org/a/7z2301-linux-x64.tar.xz /tmp/
16-
RUN tar -C /usr/bin/ -xvf /tmp/7z*.tar.xz 7zz
17-
18-
# Please download through BitTorrent yourself.
19-
RUN 7zz x /tmp/comiclib/e-hentai_*/api_dump.sqlite.7z
20-
RUN rm -r /tmp/*
21-
22-
RUN python3 -c "from comiclib import frontend_boost"
23-
24-
VOLUME /root
25-
26-
CMD [ "gunicorn", "comiclib.main:app", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--preload", "--workers", "4" ]
12+
RUN tar -C /usr/bin -xvf /tmp/7z*.tar.xz 7zz
13+
RUN mkdir /exract
14+
WORKDIR /extract
15+
RUN 7zz x /tmp/api_dump.sqlite.7z
16+
COPY . /tmp/comiclib
17+
RUN /venv/bin/pip install --no-cache-dir -U "/tmp/comiclib[full]"
18+
RUN /venv/bin/pip install --no-cache-dir -U gunicorn
19+
RUN mkdir /userdata
20+
# RUN rm -r /tmp/*
21+
22+
FROM gcr.io/distroless/python3-debian12
23+
COPY --from=build-venv /venv /venv
24+
COPY --from=build-venv /usr/bin/7zz /usr/bin
25+
COPY --from=build-venv /usr/bin/ffmpeg /usr/bin
26+
COPY --from=build-venv /extract/api_dump.sqlite /data/api_dump.sqlite
27+
COPY --from=build-venv /userdata /userdata
28+
ENV importEHdb_API_DUMP_PATH=/data/api_dump.sqlite content=/root/comiclib watch=False
29+
EXPOSE 8000
30+
WORKDIR /userdata
31+
VOLUME /userdata
32+
VOLUME /root/comiclib
33+
RUN [ "/venv/bin/python", "-c", "from comiclib import frontend_boost" ]
34+
ENTRYPOINT [ "/venv/bin/python", "-m" , "gunicorn", "comiclib.main:app", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--preload", "--workers", "4" ]

comiclib/scanner/30-importEHdb.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Settings(BaseSettings):
99
importEHdb_thumb: bool = True
1010
importEHdb_matchtitle: Union[bool, str] = Field(default=True, union_mode='left_to_right')
1111
importEHdb_matchtorrent: bool = True
12+
importEHdb_API_DUMP_PATH: str = "api_dump.sqlite"
1213
settings = Settings()
1314

1415
import logging
@@ -38,9 +39,10 @@ class Scanner:
3839
Currently only support matching by the source URL (from previous scanners).'''
3940

4041
def __init__(self) -> None:
41-
if Path("api_dump.sqlite").exists():
42+
if Path(settings.importEHdb_API_DUMP_PATH).exists():
4243
logger.info('Loading ehentai metadata database, please wait...')
43-
self.con = sqlite3.connect("api_dump.sqlite", check_same_thread=False)
44+
# do it in readonly mode, to maintain a readonly container image
45+
self.con = sqlite3.connect("file:"+settings.importEHdb_API_DUMP_PATH+"?mode=ro", uri=True, check_same_thread=False)
4446
if settings.importEHdb_matchtitle:
4547
self.db_title = {blur_title(row[0]): row[1] for row in self.con.execute("SELECT title, gid FROM gallery") if not row[0] is None}
4648
self.db_title_jpn = {blur_title(row[0]): row[1] for row in self.con.execute("SELECT title_jpn, gid FROM gallery") if not row[0] is None}

docs/en/docs/getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pip install -U "comiclib[full] @ git+https://github.com/comiclib/comiclib.git"
3939
``` bash
4040
docker run -p 8000:8000 \
4141
--mount type=bind,source=<YOUR_COMIC_DIRECTORY_HERE>,target=/root/comiclib \
42+
--mount type=bind,source=<USER_DATA_PATH>,target=/userdata \
4243
urenko/comiclib
4344
```
4445
ComicLib now runs at http://localhost:8000 .

docs/zh/docs/getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pip install -U "comiclib[full] @ git+https://github.com/comiclib/comiclib.git"
3939
``` bash
4040
docker run -p 8000:8000 \
4141
--mount type=bind,source=你的漫画库路径,target=/root/comiclib \
42+
--mount type=bind,source=你的数据路径,target=/userdata \
4243
urenko/comiclib
4344
```
4445
现在 ComicLib 运行在了 http://localhost:8000

0 commit comments

Comments
 (0)