Skip to content

Commit

Permalink
Adds Docker support (#10)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
captn3m0 committed Oct 13, 2018
1 parent b96721e commit d3497f1
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
oathbringer
oathbringer-reread
skyward
vendor
wok
wor
books
.git
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -68,13 +76,34 @@ 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
- Windows users need wget. Download the latest wget.exe from https://eternallybored.org/misc/wget/ and add it's directory to the PATH environment variable or put it directly in C:\Windows.

## 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
Expand Down Expand Up @@ -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/>
Expand Down
19 changes: 19 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 1 deletion methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d3497f1

Please sign in to comment.