Skip to content

Commit

Permalink
fix(Docker Image Issues): 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
thezak48 committed Nov 14, 2023
1 parent 14a08bb commit 0e26115
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 27 deletions.
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN echo "http://dl-4.alpinelinux.org/alpine/v3.14/main" >> /etc/apk/repositorie
echo "http://dl-4.alpinelinux.org/alpine/v3.14/community" >> /etc/apk/repositories


RUN apk --no-cache add chromium chromium-chromedriver
RUN apk --no-cache add chromium chromium-chromedriver shadow
RUN pip install --upgrade pip

LABEL maintainer="thezak48" \
Expand All @@ -17,18 +17,21 @@ LABEL maintainer="thezak48" \
org.opencontainers.image.title="manga_dl" \
org.opencontainers.image.description="manga_dl is an application to to download manga's, manhua's or manhwa's."

ENV PUID=1000
ENV PGID=1000
ENV APP_DIR="/app" CONFIG_DIR="/config" PUID="1000" PGID="1000" UMASK="002" TZ="Etc/UTC"
ENV PYTHONUNBUFFERED=1

COPY . /
RUN mkdir "${APP_DIR}" && \
mkdir "${CONFIG_DIR}" && \
useradd -u 1000 -U -d "${CONFIG_DIR}" -s /bin/false manga && \
usermod -G users manga

VOLUME ["${CONFIG_DIR}"]

COPY . ${APP_DIR}

WORKDIR ${APP_DIR}

RUN pip install --no-cache-dir -r requirements.txt

RUN addgroup -g $PGID appgroup && \
adduser -D -u $PUID -G appgroup appuser && \
mkdir -p /config && \
chown -R appuser:appgroup /config
USER appuser

CMD [ "python", "/manga_dl.py" ]
CMD [ "python", "./manga_dl.py" ]
10 changes: 4 additions & 6 deletions manga_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ def submit(self, fn, *args, **kwargs):


if os.path.exists("/.dockerenv"):
dirname = "config"
config_path = "/config"
else:
dirname = "data"
config_path = os.path.dirname(__file__), "data"

log = setup_logging(dirname)
log = setup_logging(config_path)

config = ConfigHandler(
log, os.path.join(os.path.dirname(__file__), dirname, "config.ini")
)
config = ConfigHandler(log, os.path.join(config_path, "config.ini"))

if config.has_option("General", "driver_path"):
driver_path = config.get("General", "driver_path")
Expand Down
14 changes: 10 additions & 4 deletions manga_dl/utilities/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class FileHandler:
def __init__(self, logger):
self.logger = logger

def create_comic_info(self, series, genres, summary, language_iso="en"):
def create_comic_info(
self, series, genres, summary, comic_info_path, language_iso="en"
):
"""
Create a ComicInfo.xml file for the .cbz file.
"""
Expand All @@ -30,10 +32,14 @@ def create_comic_info(self, series, genres, summary, language_iso="en"):
ET.SubElement(root, "LanguageISO").text = language_iso

tree = ET.ElementTree(root)
tree.write("ComicInfo.xml", encoding="utf-8", xml_declaration=True)

os.makedirs(comic_info_path, exist_ok=True)
file_path = os.path.join(comic_info_path, "ComicInfo.xml")

tree.write(file_path, encoding="utf-8", xml_declaration=True)
self.logger.info("ComicInfo.xml for %s created", series)

def make_cbz(self, directory_path, compelte_dir, output_path):
def make_cbz(self, directory_path, compelte_dir, output_path, comic_info_path):
"""
Create a .cbz file from a directory.
"""
Expand All @@ -53,7 +59,7 @@ def make_cbz(self, directory_path, compelte_dir, output_path):
)
self.logger.info("%s added to %s", file, output_path)

zipf.write("ComicInfo.xml", "ComicInfo.xml")
zipf.write(comic_info_path, "ComicInfo.xml")
self.logger.info("ComicInfo.xml added to %s", output_path)

zipf.close()
Expand Down
8 changes: 7 additions & 1 deletion manga_dl/utilities/image_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,18 @@ def download_chapter(

if completed:
FileHandler(self.logger).create_comic_info(
series=title_id, genres=genres, summary=summary
series=title_id,
genres=genres,
summary=summary,
comic_info_path=os.path.join(save_location, "tmp", title_id),
)
FileHandler(self.logger).make_cbz(
directory_path=os.path.join(save_location, "tmp", title_id, f"Ch. {x}"),
compelte_dir=complete_dir,
output_path=f"{x}.cbz",
comic_info_path=os.path.join(
save_location, "tmp", title_id, "ComicInfo.xml"
),
)
FileHandler(self.logger).cleanup(
directory_path=os.path.join(save_location, "tmp", title_id, f"Ch. {x}")
Expand Down
4 changes: 2 additions & 2 deletions manga_dl/utilities/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rich.logging import RichHandler


def setup_logging(dirname):
def setup_logging(config_path):
"""Setup logging."""
sys.stdout.reconfigure(encoding="utf-8")
console = Console()
Expand All @@ -24,7 +24,7 @@ def setup_logging(dirname):

current_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
log_filename = f"manga_dl_{current_time}.log"
log_dir = f"./{dirname}/logs"
log_dir = f"{config_path}/logs"
os.makedirs(log_dir, exist_ok=True)
log_filepath = os.path.join(log_dir, log_filename)
file_handler = RotatingFileHandler(
Expand Down
10 changes: 6 additions & 4 deletions manga_dl/utilities/sites/kaiscans.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from time import sleep
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


class Kaiscans:
Expand Down Expand Up @@ -86,9 +85,12 @@ def get_chapter_images(self, url: str):
"""
Get the manga chapter images for a given chapter URL.
"""
options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(self.driver_path, options=options)
options = webdriver.ChromeOptions()
options.add_argument("headless")
options.add_argument("no-sandbox")
options.add_argument("disable-dev-shm-usage")
options.add_argument("user-data-dir=/config/.cache/selenium")
driver = webdriver.Chrome(options=options)
driver.get(url)

sleep(5)
Expand Down

0 comments on commit 0e26115

Please sign in to comment.