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:
parent
b96721e156
commit
d3497f1aed
|
@ -0,0 +1,8 @@
|
|||
oathbringer
|
||||
oathbringer-reread
|
||||
skyward
|
||||
vendor
|
||||
wok
|
||||
wor
|
||||
books
|
||||
.git
|
|
@ -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"]
|
35
README.md
35
README.md
|
@ -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 humanity’s 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/>
|
||||
|
|
|
@ -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/
|
16
methods.rb
16
methods.rb
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue