Adds Docker support (#10)

* Initial WIP for Docker generation

* Adds wkhtmltopdf

* Adds pdftk

* Force remove

* Run wkhtmltopdf inside xvfb

* No arguments to the entrypoint needed

* Adds xvfb to apt install

* Install pdftk from PPA and add skyward

* Adds support for single book generation using Docker
This commit is contained in:
Nemo 2018-10-14 00:22:51 +05:30 committed by GitHub
parent b96721e156
commit d3497f1aed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 112 additions and 1 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
oathbringer
oathbringer-reread
skyward
vendor
wok
wor
books
.git

35
Dockerfile Normal file
View File

@ -0,0 +1,35 @@
# LTS Image
FROM ubuntu:18.04
LABEL maintainer="github.cosmere-ebooks@captnemo.in"
ARG DEBIAN_FRONTEND="noninteractive"
COPY Gemfile Gemfile.lock /src/
WORKDIR /src
RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:malteworld/ppa && \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
calibre \
pandoc \
pdftk \
ruby \
ruby-dev \
wget \
wkhtmltopdf \
xvfb \
zlib1g-dev \
&& gem install bundler --no-ri --no-rdoc \
&& bundle install \
&& apt-get remove -y --purge build-essential \
&& apt-get clean
COPY . /src
ENTRYPOINT ["/src/bootstrap.sh"]
VOLUME ["/output"]

View File

@ -58,8 +58,16 @@ You can read more at the announcement at [BrandonSanderson.com](https://brandons
More details at https://www.tor.com/series/oathbringer-reread-brandon-sanderson/
# Skyward
> Skyward by #1 New York Times bestselling author Brandon Sanderson is the first book in an epic new series about a girl who dreams of becoming a pilot in a dangerous world at war for humanitys future. We know you can't wait for the book to finally hit shelves on 11/6/18, so we're releasing new chapters here every week!
See more details at [underlined](https://www.getunderlined.com/read/excerpt-reveal-start-reading-skyward-by-brandon-sanderson/) or [brandonsanderson.com](https://brandonsanderson.com/books/skyward/skyward/)
## Requirements
Either [Docker](https://docs.docker.com/install/) installed or the following setup:
- Ruby
- Nokogiri gem installed (`gem install nokogiri`)
- `pandoc` installed and available (for all 3 formats)
@ -68,6 +76,8 @@ More details at https://www.tor.com/series/oathbringer-reread-brandon-sanderson/
- (pdf) `wkhtmltopdf` for converting html to pdf
- (pdf) `pdftk` to stitch the final PDF file
### Notes
- The final 2 tools can be skipped if you don't care about the PDF generation.
- You can also skip calibre if you only want the EPUB file.
- Edit the last line in `*.rb` to `:epub` / `:mobi`, `:pdf` to only trigger the specific builds
@ -75,6 +85,25 @@ More details at https://www.tor.com/series/oathbringer-reread-brandon-sanderson/
## Generation
If you have `docker` setup, run the following command inside an empty directory. This will download
all the books from scratch and copy the final books into it.
docker run --rm --volume "$(pwd):/output" captn3m0/cosmere-books:latest [bookname]
The last is an optional bookname, which can be one of the following:
```
edgedancer-reread
oathbringer
oathbringer-reread
skyward
wok-prime
wok-reread
wor-reread
```
If none is passed, all books will be generated.
## Oathbringer
After downloading the repo and installing the requirements, just run
@ -119,6 +148,12 @@ All the generated files will be saved with the filename `books/wok-prime.{epub|p
All the generated files will be saved with the filename `books/oathbringer-reread.{epub|pdf|mobi|html}`. This generation might take a while the script attempts to strip out unnecessary HTML.
## Skyward
ruby skyward.rb
All the generated files will be saved with the filename `books/skyward.{epub|pdf|mobi|html}`. This generation might take a while the script attempts to strip out unnecessary HTML.
## Extra
If you'd like to see any other books covered here, please create an issue, or reach out to me: <https://captnemo.in/contact/>

19
bootstrap.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# Generate all the books
mkdir -p books
if [ -z "$1" ]
then
bundle exec ruby edgedancer-reread.rb
bundle exec ruby oathbringer.rb
bundle exec ruby oathbringer-reread.rb
bundle exec ruby wok-prime.rb
bundle exec ruby wok-reread.rb
bundle exec ruby wor-reread.rb
bundle exec ruby skyward.rb
else
bundle exec ruby "$1.rb"
fi
cp -r books /output/

View File

@ -64,6 +64,15 @@ def gen_mobi(name, format)
end
end
def inside_docker?
File.readlines("/proc/1/sched").each do |line|
return line.strip != "systemd (1, #threads: 1)"
end
rescue Errno::ENOENT => e
false
end
def gen_pdf(name, format)
if commands?(%w[pandoc convert wkhtmltopdf pdftk]) && format_match(format, :pdf)
# Generate PDF as well
@ -72,7 +81,12 @@ def gen_pdf(name, format)
puts '[pdf] Generated html for pdf'
# Print the pdf_html file to pdf
`wkhtmltopdf books/#{name}_pdf.html books/#{name}-nocover.pdf`
if inside_docker?
`xvfb-run wkhtmltopdf books/#{name}_pdf.html books/#{name}-nocover.pdf`
else
`wkhtmltopdf books/#{name}_pdf.html books/#{name}-nocover.pdf`
end
puts '[pdf] Generated PDF without cover'
# Join the cover and pdf together