Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to SRE Workbook. #21

Merged
merged 7 commits into from Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 19 additions & 7 deletions README.md
@@ -1,10 +1,16 @@
# google-sre-ebook
# Google SRE Book/s

![Cover](cover.jpg)
Generates a EPUB/MOBI/PDF for the Google SRE Book/s.

Generates a EPUB/MOBI/PDF for the Google SRE Book.
Original sources are downloaded from https://landing.google.com/sre/books

Original sources are downloaded from https://landing.google.com/sre/
# Books

## Site Reliability Engineering (2016)
<img src="cover/sre-book.jpg" width="320" alt="site reliability engineering cover" >

## The Site Reliability Workbook (2018)
<img src="cover/workbook.jpg" width="320" alt="the site reliability workbook cover" >

# Build

Expand All @@ -14,8 +20,14 @@ Requirements:

- Docker

You can generate either of books using `BOOK_SLUG` variable.

Available values for `BOOK_SLUG`:
- `sre_book` Site Reliability Engineering.
- `srw_book` The Site Reliability Workbook.

```
$ docker run --rm --volume "$(pwd):/output" captn3m0/google-sre-ebook:latest
$ docker run --rm --volume "$(pwd):/output" -e BOOK_SLUG='sre_book' captn3m0/google-sre-ebook:latest
```

- You should see the final EPUB/MOBI/PDF files in the `output` directory after the above runs.
Expand All @@ -26,7 +38,7 @@ $ docker run --rm --volume "$(pwd):/output" captn3m0/google-sre-ebook:latest
```
$ mkdir /tmp/sreoutput
$ chcon -Rt svirt_sandbox_file_t /tmp/sreoutput
$ docker run --rm --volume "/tmp/sreoutput:/output" captn3m0/google-sre-ebook:latest
$ docker run --rm --volume "/tmp/sreoutput:/output" -e BOOK_SLUG='sre_book' captn3m0/google-sre-ebook:latest
```

The build for the above Docker image can be audited at <https://cloud.docker.com/swarm/captn3m0/repository/docker/captn3m0/google-sre-ebook/builds>.
Expand All @@ -46,7 +58,7 @@ Requirements:

# Known Issues

- metadata.xml is not complete. There are just too many authors
- metadata is not complete. There are just too many authors
- Foreword/Preface is not part of the index

# LICENSE
Expand Down
23 changes: 23 additions & 0 deletions books.sh
@@ -0,0 +1,23 @@
# Google SRE Books.

# NOTE: The indentation before inner vars should be always "tab" not "space".
declare -A BOOKS
BOOKS=(

# Site Reliability Engineering
["SRE_BOOK"]='
BOOK_NAME=sre-book
BOOK_NAME_FULL=Site Reliability Engineering
BOOK_FILE=google-sre-book
BOOK_TOC_URL=https://landing.google.com/sre/sre-book/toc/index.html
'

# Site Reliability Workbook
["SRW_BOOK"]='
BOOK_NAME=workbook
BOOK_NAME_FULL=The Site Reliability Workbook
BOOK_FILE=google-sre-workbook
BOOK_TOC_URL=https://landing.google.com/sre/workbook/toc/index.html
'

)
39 changes: 27 additions & 12 deletions bootstrap.sh
@@ -1,21 +1,26 @@
#!/bin/bash
if [[ "${DEBUG}" == 1 ]]; then
set -x
fi
set -euo pipefail
IFS=$'\n\t'

# Vars.
export BOOK_NAME="sre-book"
export BOOK_NAME_FULL="Site Reliability Engineering"
BOOK_FILE="google-${BOOK_NAME}"
TOC_URL="https://landing.google.com/sre/${BOOK_NAME}/toc/index.html"
# Get book details.
source books.sh
export ${BOOKS[${BOOK_SLUG^^}]}

# Common vars.
IMGS_DOMAIN="lh3.googleusercontent.com"

#
# Make sure that links are relative \
# # Remove the /sre/ directories
# Save stuff in html/ directory
# Do not create a landing.google.com directory
# Enable recursion, timestamping (--mirror)
# Images are hosted elsewhere, download them as well.
# We need to go up a level from /toc/ where we start
# The "ture" at the end to ignore non-200 URLs like 404.
wget \
--convert-links \
--directory-prefix=html \
Expand All @@ -27,18 +32,21 @@ wget \
--mirror \
--no-verbose \
--recursive \
--domains=${IMGS_DOMAIN},landing.google.com ${TOC_URL}
--domains=${IMGS_DOMAIN},landing.google.com ${BOOK_TOC_URL} || true

#
echo "Get working mode..."
MODE=${1:-}

if [ "$MODE" != "docker" ];then
bundle install
fi

#
# Add extension to files.
# That because `pandoc` cannot generate the right `mime type` without the extension.
# https://github.com/captn3m0/google-sre-ebook/issues/19
echo "Fix images extension issue ..."
IMGS_FILES="$(ls html/${IMGS_DOMAIN}/*)"
for FILE_NAME_FULL in ${IMGS_FILES}; do

Expand All @@ -48,24 +56,31 @@ for FILE_NAME_FULL in ${IMGS_FILES}; do

# Rename and replace file.
mv "${FILE_NAME_FULL}" "${FILE_NAME_FULL}.${FILE_TYPE,,}" &&
grep -rl "${FILE_NAME_BASE}" ./html | xargs sed -i "s/${FILE_NAME_BASE}/${FILE_NAME_BASE}.${FILE_TYPE,,}/g"
grep -rl -- "${FILE_NAME_BASE}" ./html | xargs sed -i -- "s/${FILE_NAME_BASE}/${FILE_NAME_BASE}.${FILE_TYPE,,}/g"

done

#
# Generate epub from html.
echo "Generate book ..."
bundle exec ruby generate.rb
pushd html/landing.google.com/sre/${BOOK_NAME}/toc
pandoc --from=html --to=epub \
--output=../../../../../${BOOK_FILE}.epub \
--epub-metadata=../../../../../${BOOK_NAME}.xml \
--epub-cover-image=../../../../../${BOOK_NAME}.jpg \
pandoc --from=html --to=epub \
--output=../../../../../${BOOK_FILE}.epub \
--epub-metadata=../../../../../metadata/${BOOK_NAME}.xml \
--epub-cover-image=../../../../../cover/${BOOK_NAME}.jpg \
complete.html
popd

#
# Generate other format from epub.
for EXTENSION in mobi pdf; do
ebook-convert ${BOOK_FILE}.epub ${BOOK_FILE}.${EXTENSION}
done

if [ "$1"=="docker" ]; then
#
# If it works inside docker.
if [ "$MODE" == "docker" ]; then
chown -v $(id -u):$(id -g) ${BOOK_FILE}.*
mv -f ${BOOK_FILE}.* /output
fi
Binary file added cover/sre-book.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cover/workbook.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
11 changes: 11 additions & 0 deletions metadata/workbook.xml
@@ -0,0 +1,11 @@
<dc:identifier id="epub-id-1" opf:scheme="ISBN-10">1492029459</dc:identifier>
<dc:identifier id="epub-id-1" opf:scheme="ISBN-13">978-1492029458</dc:identifier>
<dc:title id="epub-title-1">The Site Reliability Workbook: Practical Ways to Implement SRE</dc:title>
<dc:date>2018-08-10</dc:date>
<dc:language>en-US</dc:language>

<dc:creator id="epub-creator-1" opf:role="edt">Betsy Beyer</dc:creator>
<dc:creator id="epub-creator-1" opf:role="edt">Niall Richard Murphy</dc:creator>
<dc:creator id="epub-creator-1" opf:role="edt">David K. Rensin</dc:creator>
<dc:creator id="epub-creator-1" opf:role="edt">Kent Kawahara</dc:creator>
<dc:creator id="epub-creator-1" opf:role="edt">Stephen Thorne</dc:creator>
Binary file removed sre-book.jpg
Binary file not shown.