From ef1e76a13431e1ab1f2083e8dbf51709ab4ece7f Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 25 Apr 2023 21:13:37 +0100 Subject: [PATCH] Various changes (#74) --- .gitattributes | 84 ++++++++++++++++++++++++ .github/ISSUE_TEMPLATE/issue.bug.yml | 45 +++++++++++++ .github/ISSUE_TEMPLATE/issue.feature.yml | 31 +++++++++ .github/PULL_REQUEST_TEMPLATE.md | 19 ++++++ .github/workflows/greetings.yml | 15 +++++ renovate.json => .renovaterc.json | 0 Dockerfile | 25 +++++-- README.md | 64 ++++++++---------- root/etc/crontabs/root | 2 +- root/etc/services.d/cron/run | 2 - root/opt/docker-entrypoint.sh | 15 +++++ root/opt/requirements.txt | 1 - 12 files changed, 258 insertions(+), 45 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/ISSUE_TEMPLATE/issue.bug.yml create mode 100644 .github/ISSUE_TEMPLATE/issue.feature.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/greetings.yml rename renovate.json => .renovaterc.json (100%) delete mode 100644 root/etc/services.d/cron/run delete mode 100644 root/opt/requirements.txt diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..17d526d5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,84 @@ + +# Common settings that generally should always be used with your language specific settings + +# Auto detect text files and perform LF normalization +* text=auto + +# +# The above will handle all files NOT found below +# + +# Documents +*.bibtex text diff=bibtex +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain +*.md text diff=markdown +*.mdx text diff=markdown +*.tex text diff=tex +*.adoc text +*.textile text +*.mustache text +*.csv text eol=crlf +*.tab text +*.tsv text +*.txt text +*.sql text +*.epub diff=astextplain + +# Graphics +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.tif binary +*.tiff binary +*.ico binary +# SVG treated as text by default. +*.svg text +# If you want to treat it as binary, +# use the following line instead. +# *.svg binary +*.eps binary + +# Scripts +*.bash text eol=lf +*.fish text eol=lf +*.sh text eol=lf +*.zsh text eol=lf +# These are explicitly windows files and should use crlf +*.bat text eol=crlf +*.cmd text eol=crlf +*.ps1 text eol=crlf + +# Serialisation +*.json text +*.toml text +*.xml text +*.yaml text +*.yml text + +# Archives +*.7z binary +*.gz binary +*.tar binary +*.tgz binary +*.zip binary + +# Text files where line endings should be preserved +*.patch -text + +# +# Exclude files from exporting +# + +.gitattributes export-ignore +.gitignore export-ignore +.gitkeep export-ignore diff --git a/.github/ISSUE_TEMPLATE/issue.bug.yml b/.github/ISSUE_TEMPLATE/issue.bug.yml new file mode 100644 index 00000000..72ef6659 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/issue.bug.yml @@ -0,0 +1,45 @@ +# Based on the issue template +name: Bug report +description: Create a report to help us improve +title: "[BUG] " +labels: [Bug] +body: + - type: checkboxes + attributes: + label: Is there an existing issue for this? + description: Please search to see if an issue already exists for the bug you encountered. + options: + - label: I have searched the existing issues + required: true + - type: textarea + attributes: + label: Current Behavior + description: Tell us what happens instead of the expected behavior. + validations: + required: true + - type: textarea + attributes: + label: Expected Behavior + description: Tell us what should happen. + validations: + required: false + - type: textarea + attributes: + label: Steps To Reproduce + description: Steps to reproduce the behavior. + placeholder: | + 1. In this environment... + 2. With this config... + 3. Run '...' + 4. See error... + validations: + required: true + - type: textarea + attributes: + label: Docker creation + description: | + Command used to create docker container + Provide your docker create/run command or compose yaml snippet, or a screenshot of settings if using a gui to create the container + render: bash + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/issue.feature.yml b/.github/ISSUE_TEMPLATE/issue.feature.yml new file mode 100644 index 00000000..099dcdb5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/issue.feature.yml @@ -0,0 +1,31 @@ +# Based on the issue template +name: Feature request +description: Suggest an idea for this project +title: "[FEAT] <title>" +labels: [enhancement] +body: + - type: checkboxes + attributes: + label: Is this a new feature request? + description: Please search to see if a feature request already exists. + options: + - label: I have searched the existing issues + required: true + - type: textarea + attributes: + label: Wanted change + description: Tell us what you want to happen. + validations: + required: true + - type: textarea + attributes: + label: Reason for change + description: Justify your request, why do you want it, what is the benefit. + validations: + required: true + - type: textarea + attributes: + label: Proposed code change + description: Do you have a potential code change in mind? + validations: + required: false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..c7221258 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,19 @@ +# Pull Request + +<!-- - [ ] I have read the [contributing](https://github.com/ghostwriters/docker-packt-cli/blob/main/.github/CONTRIBUTING.md) guideline and understand that I have made the correct modifications. + +--- --> + +## Description + +- + +## Benefits of this PR and context + +- + +## How Has This Been Tested? + +- + +--- diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 00000000..a690669b --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,15 @@ +name: Greetings + +permissions: read-all + +on: [pull_request_target, issues] + +jobs: + greeting: + runs-on: ubuntu-latest + steps: + - uses: actions/first-interaction@1d8459ca65b335265f1285568221e229d45a995e # v1.1.1 + with: + issue-message: "Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid." + pr-message: "Thanks for opening this pull request! Be sure to follow the [pull request template](https://github.com/GhostWriters/docker-packt-cli/blob/main/.github/PULL_REQUEST_TEMPLATE.md)!" + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/renovate.json b/.renovaterc.json similarity index 100% rename from renovate.json rename to .renovaterc.json diff --git a/Dockerfile b/Dockerfile index f8835d5a..567c3029 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,10 @@ # Set the base image FROM ghcr.io/linuxserver/baseimage-alpine:3.17 +# Set the timezone +ARG TZ=Europe/London +ENV TZ=$TZ + # Set the maintainer LABEL maintainer="GhostWriters" @@ -8,13 +12,26 @@ LABEL maintainer="GhostWriters" COPY root / # Install required packages and application dependencies -RUN apk add --no-cache py3-pip && \ - pip3 install --no-cache-dir -r /opt/requirements.txt +RUN apk update && apk add --no-cache py3-pip tzdata && \ + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \ + echo $TZ > /etc/timezone && \ + pip3 install --no-cache-dir packt==1.7.0 + +# Update UID and GID of existing user "abc" to match PUID and PGID if supplied +ARG PUID=1000 +ARG PGID=1000 +RUN if [ "$PUID" -ne 1000 ] || [ "$PGID" -ne 1000 ]; then \ + usermod -u $PUID abc && \ + groupmod -g $PGID abc; \ + fi + +# Set user "abc" as default user +USER abc # Add a health check command to ensure the container is running correctly HEALTHCHECK --interval=1m \ - --timeout=3s \ - CMD ps -ef | grep cron || exit 1 + --timeout=3s \ + CMD ps -ef | grep cron || exit 1 # Specify the entrypoint ENTRYPOINT ["/opt/docker-entrypoint.sh"] diff --git a/README.md b/README.md index d3dab420..96a3d3ba 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,49 @@ -# Container for Packt daily download script +# docker-packt-cli [![GitHub contributors](https://img.shields.io/github/contributors/GhostWriters/docker-packt-cli.svg?style=flat-square&color=607D8B)](https://github.com/GhostWriters/docker-packt-cli/graphs/contributors) [![GitHub last commit main](https://img.shields.io/github/last-commit/GhostWriters/docker-packt-cli/main.svg?style=flat-square&color=607D8B&label=code%20committed)](https://github.com/GhostWriters/docker-packt-cli/commits/main) [![GitHub license](https://img.shields.io/github/license/GhostWriters/docker-packt-cli.svg?style=flat-square&color=607D8B)](https://github.com/GhostWriters/docker-packt-cli/blob/main/LICENSE) [![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg?style=flat-square&color=607D8B)](https://github.com/renovatebot/renovate) -These instructions detail how to set up a docker container that includes a scheduled cron job to automatically claim the daily free -book from Packt at 1am each night. Packt offers free learning e-books each day, and you can find more information about this service -at <https://www.packtpub.com/packt/offers/free-learning>. -To learn more about docker, please visit the official documentation at <https://docs.docker.com/get-started/overview/>. -If you're new to cron jobs, you can learn more about them on the Unix/Linux manpages at <https://help.ubuntu.com/community/CronHowto>. -For more information about the code used in this container, please see the -project page at <https://gitlab.com/packt-cli/packt-cli>. +A Docker container for automatically downloading a free eBook each day from Packt publishing using the `packt-cli` tool. -## Run +## Usage -Run with: +To run the `docker-packt-cli` container, use the following `docker run` command: ```docker docker run -d \ - --name=packt --rm \ - -e PACKT_EMAIL=<xxx@xxx.xxx> \ - -e PACKT_PASSWORD=<password> \ - -e PACKT_DOWNLOAD_FORMATS=pdf, epub, mobi, code \ - -e PACKT_ANTICAPTCHA_KEY=<key> \ - -e PUID=<UID> \ - -e PGID=<GID> \ - -e TZ=<timezone> \ - -v /home/user/packt/config:/config \ - -v /home/user/packt/books:/data \ - --restart unless-stopped \ - ghostwriters/docker-packt-cli:latest + --name=packt --rm \ + -e PACKT_EMAIL=<xxx@xxx.xxx> \ + -e PACKT_PASSWORD=<password> \ + -e PACKT_DOWNLOAD_FORMATS=pdf,epub,mobi,code \ + -e PACKT_ANTICAPTCHA_KEY=<key> \ + -e PUID=<UID> \ + -e PGID=<GID> \ + -e TZ=<timezone> \ + -v /home/user/packt/config:/config \ + -v /home/user/packt/books:/data \ + --restart unless-stopped + ghcr.io/ghostwriters/docker-packt-cli/docker-packt-cli:latest ``` -## Volumes and variables +You will need to replace `<xxx@xxx.xxx>` and `<password>` with your Packt account email and password, respectively. Additionally, you can customize the output formats of the downloaded books by modifying the `PACKT_DOWNLOAD_FORMATS` environment variable. The default formats are `pdf`, `epub`, `mobi`, and `code`. -Volumes: +To automatically solve the CAPTCHA, you will need an AntiCaptcha API key, which you can set by attaching the `-e PACKT_ANTICAPTCHA_KEY=<key>` flag to your docker run command. -- /config, where the configFile.cfg and log file are placed -- /data, where files are downloaded to +You can mount two volumes to persist the Packt credentials and store the downloaded books in a directory on your host system. The `/config` directory will store your Packt credentials, and the `/data` directory will store the downloaded books. You can change the paths of the host directories by modifying the values after the `-v` flag. -OPTIONAL: Variables: +Once you run the container, it will automatically download a free eBook each day from Packt publishing and store the files in the `/home/user/packt/books` directory on your host system. -- PACKT_EMAIL - email address registered with Packt account -- PACKT_PASSWORD - password for Packt account -- PACKT_DOWNLOAD_FORMATS - pdf, epub, mobi, code -- PACKT_ANTICAPTCHA_KEY - get an api key from [anti-captcha.com](https://anti-captcha.com) -- PACKT_DOWNLOAD_BOOK_TITLES - specify individual books +## Contributing -If variables are set, they overwrite what is already in the configFile.cfg file -at container startup. If not set, the config file will be left alone. - -**NOTE:** Anticaptcha key required to download the daily book. +If you have any feedback or run into issues with the container, please open an [issue](https://github.com/GhostWriters/docker-packt-cli/issues/new) on the GitHub repository. If you would like to contribute to this project, you can submit a [pull request](https://github.com/GhostWriters/docker-packt-cli/pulls). ## Special Thanks - [packt-cli](https://gitlab.com/packt-cli/packt-cli) for maintaining the package to handle the downloading. -- [LinuxServer.io](https://www.linuxserver.io) for maintaining most Docker images used in this project. +- [LinuxServer.io](https://www.linuxserver.io) for maintaining the Docker image used in this project. + +## License + +This project is licensed under the MIT License. See the [LICENSE](https://github.com/GhostWriters/docker-packt-cli/blob/main/LICENSE) file for more details. diff --git a/root/etc/crontabs/root b/root/etc/crontabs/root index 7b7dbfcc..5b122f07 100644 --- a/root/etc/crontabs/root +++ b/root/etc/crontabs/root @@ -1 +1 @@ -0 1 * * * packt-cli -gd -c /config/configFile.cfg 2>&1 | tee /config/logFile.log +0 8 * * * packt-cli -gd -c /config/configFile.cfg 2>&1 | tee /config/logFile.log diff --git a/root/etc/services.d/cron/run b/root/etc/services.d/cron/run deleted file mode 100644 index dec6fc10..00000000 --- a/root/etc/services.d/cron/run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -/usr/sbin/crond -f diff --git a/root/opt/docker-entrypoint.sh b/root/opt/docker-entrypoint.sh index 5e8ea42d..c52bc315 100755 --- a/root/opt/docker-entrypoint.sh +++ b/root/opt/docker-entrypoint.sh @@ -1,5 +1,20 @@ #!/bin/sh +date + +echo 'Running as user:' "$(whoami)" +id "$(whoami)" + +# if [ ! -d /config ]; then +# echo "ERROR: /config volume is not mounted" +# exit 1 +# fi + +# if [ ! -d /data ]; then +# echo "ERROR: /data volume is not mounted" +# exit 1 +# fi + CFG=/config/configFile.cfg # Downloads and copies a new configfile template if one is not present in the config dir. diff --git a/root/opt/requirements.txt b/root/opt/requirements.txt deleted file mode 100644 index f2bd5a05..00000000 --- a/root/opt/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -packt==1.8.0