packt-cli / Packt-Publishing-Free-Learning

Scripts that automatically claim and download free daily eBooks from https://www.packtpub.com/packt/offers/free-learning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker

ranrinc opened this issue · comments

Will you create Dockerfile in the future?

@ranrinc Good idea! maybe you can create it :) ?

My little weird setup with podman…
Dockerfile

FROM registry.fedoraproject.org/fedora-minimal:34
RUN microdnf -y update && microdnf -y install python3-pip python3-wheel --nodocs --setopt install_weak_deps=0 && microdnf clean all
RUN pip3 install packt
COPY configFile.cfg /configFile.cfg
COPY init.sh /init.sh
VOLUME /srv/books
VOLUME /srv/log
RUN mkdir -p /srv/books
RUN mkdir -p /srv/log
ENTRYPOINT ./init.sh -DFOREGROUND
ARG CACHEBUST
RUN pip3 install packt --upgrade

and init.sh

#!/bin/bash
# grab new ebooks from site
{ date +%F; packt-cli -gd -f; } >> /srv/log/packt.log

# check if first day of month, and before noon, if so download ebooks
[[ $(date +%-d) -eq 1 ]] && [[ $(date +%-H) -lt 12 ]] && packt-cli -da -f >> /srv/log/packt.log                 

rm LOG_FILE.log

As it is a podman I don't care if it run as root inside a container.

I run that on schedule twice a day in case some error occur with anticaptcha, timeout or no free bots
On first day of month I run command to run full download, in case there was some problem downloading it during earlier.
The configFile.cfg is copied from local directory into container, so no need to give sensitive information inside docker/podman command.

And I locally rebuild image in case there was some update to packt-cli

@Tokariew is it working? would love to test it. Is there a way to get away with alpine instead of fedora?

How do you setup to run on docker? Any chances in uploading to Gdrive?

Yes it is working for me for the last 1.5 year… Only changed fedora version on which is based.
I will try to rewrite it to alpine, and test how to run it with uploading to Gdrive

I run it with podman instead of docker.

podman build --tag packt-downloader -f Dockerfile --build-arg CACHEBUST=$(date +%s)
podman create -v "/media/btrfs/Hoard/Packt:/srv/books:z" -v "/home/tokariew/logs:/srv/log:z" --name packt localhost/packt-downloader

After running that for the first time I generate systemd service file with

podman generate systemd packt --name

and write systemd timer for it.

minimalistic Dockerfile

FROM alpine
RUN apk add --no-cache python3 py3-pip
RUN pip3 install packt
WORKDIR /srv
VOLUME /srv
CMD /bin/sh

example of how to run it:

podman run --rm -it --name packt -v "/home/tokariew/tmp/packt:/srv:z" localhost/packt-downloader:latest packt-cli -gd

configFile.cfg and client_secret.json should be placed in mounted volume, that way it can be publish on registry and not only build locally

to upload to Google Drive you can copy existing working .credentials folder into mounted volume
or run as following for the first time:

podman run --rm -it --name packt -v "/home/tokariew/tmp/packt:/srv:z" localhost/packt-downloader:latest packt-cli -c configFile.cfg -sgd --noauth_local_webserver

after first time it can be run without -c configFile.cfg and --noauth_local_webserver