Skip to content

Commit

Permalink
feat: using docker for gitbook building
Browse files Browse the repository at this point in the history
- support CircleCI
- create docker image
- delete wercker Ci
- show build status on README
  • Loading branch information
rootsongjc committed Jul 25, 2019
1 parent cc5eaa0 commit 8b9986f
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 21 deletions.
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2
jobs:
lint-gitbook:
docker:
- image: jimmysong/gitbook-builder:2019-07-25
working_directory: ~/gitbook
steps:
- checkout
- run:
name: Linting the gitbook
command: scripts/lint-gitbook.sh
markdown-spell-check:
docker:
- image: jimmysong/website-builder:2019-07-25
working_directory: ~/gitbook
steps:
- checkout
- run:
name: Running markdown spell check
command: scripts/mdspell-check.sh
markdown-style-check:
docker:
- image: jimmysong/website-builder:2019-07-25
working_directory: ~/gitbook
steps:
- checkout
- run:
name: Running markdown style check
command: scripts/mdl-check.sh
workflows:
version: 2
workflow:
jobs:
- lint-gitbook
- markdown-spell-check
- markdown-style-check
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
BOOK_NAME := kubernetes-handbook
BOOK_OUTPUT := _book
image := jimmysong/gitbook-builder:2019-07-25
docker := docker run -t -i --sig-proxy=true --rm -v $(shell pwd):/gitbook -w /gitbook -p 4000:4000 $(image)

.PHONY: build
build:
gitbook build . $(BOOK_OUTPUT)
cp images/apple-touch-icon-precomposed-152.png $(BOOK_OUTPUT)/gitbook/images
@$(docker) scripts/build-gitbook.sh

.PHONY: lint
lint:
@$(docker) scripts/lint-gitbook.sh
htmlproofer --url-ignore "/localhost/,/172.17.8.101/,/172.20.0.113/,/slideshare.net/,/grpc.io/,/kiali.io/,/condiut.io/,/twitter.com/,/facebook.com/,/medium.com/,/google.com/,/jimmysong.io/,/openfaas.com/,/linkerd.io/,/layer5.io/,/thenewstack.io/,/blog.envoyproxy.io/,/blog.openebs.io/,/k8smeetup.github.io/,/blog.heptio.com/,/apigee.com/,/speakerdeck.com/,/download.svcat.sh/,/blog.fabric8.io/,/blog.heptio.com/,/blog.containership.io/,/blog.mobyproject.org/,/blog.spinnaker.io/,/coscale.com/,/zh.wikipedia.org/,/labs.play-with-k8s.com/,/cilium.readthedocs.io/,/azure.microsoft.com/,/storageos.com/,/openid.net/,/prometheus.io/,/coreos.com/,/openwhisk.incubator.apache.org/" $(BOOK_OUTPUT)

.PHONY: install
install:
@$(docker) gitbook install

.PHONY: serve
serve:
gitbook serve . $(BOOK_OUTPUT)
@$(docker) gitbook serve . $(BOOK_OUTPUT)

.PHONY: epub
epub:
gitbook epub . $(BOOK_NAME).epub
@$(docker) gitbook epub . $(BOOK_NAME).epub

.PHONY: pdf
pdf:
gitbook pdf . $(BOOK_NAME).pdf
@$(docker) gitbook pdf . $(BOOK_NAME).pdf

.PHONY: mobi
mobi:
gitbook mobi . $(BOOK_NAME).mobi

.PHONY: install
install:
npm install gitbook-cli -g
gitbook install
gem install html-proofer
@$(docker) gitbook mobi . $(BOOK_NAME).mobi

.PHONY: clean
clean:
Expand Down
48 changes: 48 additions & 0 deletions Makefile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
BOOK_NAME := kubernetes-handbook
BOOK_OUTPUT := _book

.PHONY: build
build:
gitbook build . $(BOOK_OUTPUT)
cp images/apple-touch-icon-precomposed-152.png $(BOOK_OUTPUT)/gitbook/images

.PHONY: lint
lint:
htmlproofer --url-ignore "/localhost/,/172.17.8.101/,/172.20.0.113/,/slideshare.net/,/grpc.io/,/kiali.io/,/condiut.io/,/twitter.com/,/facebook.com/,/medium.com/,/google.com/,/jimmysong.io/,/openfaas.com/,/linkerd.io/,/layer5.io/,/thenewstack.io/,/blog.envoyproxy.io/,/blog.openebs.io/,/k8smeetup.github.io/,/blog.heptio.com/,/apigee.com/,/speakerdeck.com/,/download.svcat.sh/,/blog.fabric8.io/,/blog.heptio.com/,/blog.containership.io/,/blog.mobyproject.org/,/blog.spinnaker.io/,/coscale.com/,/zh.wikipedia.org/,/labs.play-with-k8s.com/,/cilium.readthedocs.io/,/azure.microsoft.com/,/storageos.com/,/openid.net/,/prometheus.io/,/coreos.com/,/openwhisk.incubator.apache.org/" $(BOOK_OUTPUT)

.PHONY: serve
serve:
gitbook serve . $(BOOK_OUTPUT)

.PHONY: epub
epub:
gitbook epub . $(BOOK_NAME).epub

.PHONY: pdf
pdf:
gitbook pdf . $(BOOK_NAME).pdf

.PHONY: mobi
mobi:
gitbook mobi . $(BOOK_NAME).mobi

.PHONY: install
install:
npm install gitbook-cli -g
gitbook install
gem install html-proofer

.PHONY: clean
clean:
rm -rf $(BOOK_OUTPUT)

.PHONY: help
help:
@echo "Help for make"
@echo "make - Build the book"
@echo "make build - Build the book"
@echo "make serve - Serving the book on localhost:4000"
@echo "make install - Install gitbook and plugins"
@echo "make epub - Build epub book"
@echo "make pdf - Build pdf book"
@echo "make clean - Remove generated files"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## 关于本书

[![CircleCI](https://circleci.com/gh/rootsongjc/kubernetes-handbook/tree/master.svg?style=svg)](https://circleci.com/gh/rootsongjc/kubernetes-handbook/tree/master)

<p align="center">
<a href="https://jimmysong.io/kubernetes-handbook">
<img src="cover.jpg" width="50%" height="50%" alt="Kubernetes Handbook——Kubernetes中文指南/云原生应用架构实践手册 by Jimmy Song(宋净超)">
Expand Down
34 changes: 34 additions & 0 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM alpine:3.9

MAINTAINER Jimmy Song <rootsongjc@gmail.com>

RUN apk add --no-cache bash git curl jq tar libc6-compat g++

RUN apk add --no-cache nodejs-current-npm && npm install -g markdown-spellcheck webpack webpack-cli

RUN apk add --no-cache ruby ruby-dev ruby-rdoc && gem install mdl

# Install html-proofer
RUN echo 'gem: --no-document' >> /etc/gemrc

RUN apk add --no-cache --virtual build-dependencies \
build-base \
libcurl \
libxml2-dev \
libxslt-dev && \
apk add --no-cache --update build-base libffi-dev && \
gem install nokogiri -- --use-system-libraries && \
gem install ffi && \
gem install etc && \
gem install bigdecimal && \
gem install html-proofer --no-ri --no-rdoc && \
apk del build-dependencies && \
apk add --no-cache bash git libcurl libxml2 libxslt && \
rm -rf /var/cache/apk/* && \
rm -rf /root/.gem/* && \
rm -rf /usr/local/bundle/cache/*.gem && \
rm -rf /usr/lib/ruby/gems/*/cache/*.gem

# Install gitbook
RUN npm install gitbook-cli -g && \
npm install gitbook -g
3 changes: 3 additions & 0 deletions scripts/build-gitbook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
gitbook build
cp images/apple-touch-icon-precomposed-152.png _book/gitbook/images
9 changes: 9 additions & 0 deletions scripts/lint-gitbook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
BOOK_OUTPUT="./_book"
./scripts/build-gitbook.sh
echo -ne "mdspell "
mdspell --version
echo -ne "mdl "
mdl --version
htmlproofer --version
htmlproofer --url-ignore "/localhost/,/172.17.8.101/,/172.20.0.113/,/slideshare.net/,/grpc.io/,/kiali.io/,/condiut.io/,/twitter.com/,/facebook.com/,/medium.com/,/google.com/,/jimmysong.io/,/openfaas.com/,/linkerd.io/,/layer5.io/,/thenewstack.io/,/blog.envoyproxy.io/,/blog.openebs.io/,/k8smeetup.github.io/,/blog.heptio.com/,/apigee.com/,/speakerdeck.com/,/download.svcat.sh/,/blog.fabric8.io/,/blog.heptio.com/,/blog.containership.io/,/blog.mobyproject.org/,/blog.spinnaker.io/,/coscale.com/,/zh.wikipedia.org/,/labs.play-with-k8s.com/,/cilium.readthedocs.io/,/azure.microsoft.com/,/storageos.com/,/openid.net/,/prometheus.io/,/coreos.com/,/openwhisk.incubator.apache.org/" $(BOOK_OUTPUT)
50 changes: 50 additions & 0 deletions scripts/mdl-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

FAILED=0

echo -ne "mdl "
mdl --version

# This performs markdown style check over changed markdown files
check_pull_request_content() {

# only check pull request, skip others
if [[ -z $CIRCLE_PULL_REQUEST ]]; then
echo "Skip, only check pull request."
exit 0
fi

# get changed files of this PR
CIRCLE_PR_NUMBER=${CIRCLE_PULL_REQUEST##*/}
OWNER=$(echo $CIRCLE_PULL_REQUEST | cut -d / -f 4)
REPO=$(echo $CIRCLE_PULL_REQUEST | cut -d / -f 5)
URL="https://api.github.com/repos/$OWNER/$REPO/pulls/$CIRCLE_PR_NUMBER/files"

echo
echo "Getting list of changed markdown files..."
CHANGED_MARKDOWN_FILES=()
while IFS=$'\n' read -r line; do
CHANGED_MARKDOWN_FILES+=( "${line}" )
done < <(curl --retry 20 -s -X GET -G $URL | jq '.[] | select(.status != "removed") | select(.filename | endswith(".md")) | .filename')
echo "Total changed markdown files: ${#CHANGED_MARKDOWN_FILES[@]}"
echo "${CHANGED_MARKDOWN_FILES[@]}"
echo

if [[ "${#CHANGED_MARKDOWN_FILES[@]}" != "0" ]]; then
echo "${CHANGED_MARKDOWN_FILES[@]}" | xargs mdl --ignore-front-matter --style mdl_style.rb
if [[ "$?" != "0" ]]; then
FAILED=1
fi
else
echo "No changed markdown files to check."
fi
}

check_pull_request_content

if [[ $FAILED -eq 1 ]]; then
echo "MARKDOWN STYLE CHECK FAILED"
exit 1
else
echo "MARKDOWN STYLE CHECK SUCCEEDED"
fi
50 changes: 50 additions & 0 deletions scripts/mdspell-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

FAILED=0

echo -ne "mdspell "
mdspell --version

# This performs markdown spell check over changed markdown files
check_pull_request_content() {

# only check pull request, skip others
if [[ -z $CIRCLE_PULL_REQUEST ]]; then
echo "Skip, only check pull request."
exit 0
fi

# get changed files of this PR
CIRCLE_PR_NUMBER=${CIRCLE_PULL_REQUEST##*/}
OWNER=$(echo $CIRCLE_PULL_REQUEST | cut -d / -f 4)
REPO=$(echo $CIRCLE_PULL_REQUEST | cut -d / -f 5)
URL="https://api.github.com/repos/$OWNER/$REPO/pulls/$CIRCLE_PR_NUMBER/files"

echo
echo "Getting list of changed markdown files..."
CHANGED_MARKDOWN_FILES=()
while IFS=$'\n' read -r line; do
CHANGED_MARKDOWN_FILES+=( "${line}" )
done < <(curl --retry 20 -s -X GET -G $URL | jq '.[] | select(.status != "removed") | select(.filename | endswith(".md")) | .filename')
echo "Total changed markdown files: ${#CHANGED_MARKDOWN_FILES[@]}"
echo "${CHANGED_MARKDOWN_FILES[@]}"
echo

if [[ "${#CHANGED_MARKDOWN_FILES[@]}" != "0" ]]; then
echo "${CHANGED_MARKDOWN_FILES[@]}" | xargs mdspell --en-us --ignore-acronyms --ignore-numbers --no-suggestions --report
if [[ "$?" != "0" ]]; then
FAILED=1
fi
else
echo "No changed markdown files to check."
fi
}

check_pull_request_content

if [[ $FAILED -eq 1 ]]; then
echo "Feel free to add the term(s) into our glossary file '.spelling'."
echo "SPELL CHECK FAILED"
else
echo "SPELL CHECK SUCCEEDED"
fi
9 changes: 0 additions & 9 deletions wercker.yml

This file was deleted.

0 comments on commit 8b9986f

Please sign in to comment.