From 8b9986f8e737b995540b489d74d2aae10f136d96 Mon Sep 17 00:00:00 2001 From: Jimmy song Date: Thu, 25 Jul 2019 13:39:57 +0800 Subject: [PATCH] feat: using docker for gitbook building - support CircleCI - create docker image - delete wercker Ci - show build status on README --- .circleci/config.yml | 36 +++++++++++++++++++++++++++++ Makefile | 42 ++++++++++++++++----------------- Makefile.local | 48 ++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ scripts/Dockerfile | 34 +++++++++++++++++++++++++++ scripts/build-gitbook.sh | 3 +++ scripts/lint-gitbook.sh | 9 ++++++++ scripts/mdl-check.sh | 50 ++++++++++++++++++++++++++++++++++++++++ scripts/mdspell-check.sh | 50 ++++++++++++++++++++++++++++++++++++++++ wercker.yml | 9 -------- 10 files changed, 253 insertions(+), 30 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 Makefile.local create mode 100644 scripts/Dockerfile create mode 100755 scripts/build-gitbook.sh create mode 100755 scripts/lint-gitbook.sh create mode 100755 scripts/mdl-check.sh create mode 100755 scripts/mdspell-check.sh delete mode 100644 wercker.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..5591a60c6 --- /dev/null +++ b/.circleci/config.yml @@ -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 diff --git a/Makefile b/Makefile index d147079a9..ae94b0141 100644 --- a/Makefile +++ b/Makefile @@ -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: 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 + @$(docker) gitbook install + +.PHONY: serve +serve: + @$(docker) gitbook serve . $(BOOK_OUTPUT) + +.PHONY: epub +epub: + @$(docker) gitbook epub . $(BOOK_NAME).epub + +.PHONY: pdf +pdf: + @$(docker) gitbook pdf . $(BOOK_NAME).pdf + +.PHONY: mobi +mobi: + @$(docker) gitbook mobi . $(BOOK_NAME).mobi .PHONY: clean clean: diff --git a/Makefile.local b/Makefile.local new file mode 100644 index 000000000..d147079a9 --- /dev/null +++ b/Makefile.local @@ -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" diff --git a/README.md b/README.md index 57a54ec18..ca83b94bb 100644 --- a/README.md +++ b/README.md @@ -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) +

Kubernetes Handbook——Kubernetes中文指南/云原生应用架构实践手册 by Jimmy Song(宋净超) diff --git a/scripts/Dockerfile b/scripts/Dockerfile new file mode 100644 index 000000000..51e8872e2 --- /dev/null +++ b/scripts/Dockerfile @@ -0,0 +1,34 @@ +FROM alpine:3.9 + +MAINTAINER Jimmy Song + +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 diff --git a/scripts/build-gitbook.sh b/scripts/build-gitbook.sh new file mode 100755 index 000000000..9d93335a6 --- /dev/null +++ b/scripts/build-gitbook.sh @@ -0,0 +1,3 @@ +#!/bin/bash +gitbook build +cp images/apple-touch-icon-precomposed-152.png _book/gitbook/images diff --git a/scripts/lint-gitbook.sh b/scripts/lint-gitbook.sh new file mode 100755 index 000000000..2535bf5ec --- /dev/null +++ b/scripts/lint-gitbook.sh @@ -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) diff --git a/scripts/mdl-check.sh b/scripts/mdl-check.sh new file mode 100755 index 000000000..9b82a6a12 --- /dev/null +++ b/scripts/mdl-check.sh @@ -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 diff --git a/scripts/mdspell-check.sh b/scripts/mdspell-check.sh new file mode 100755 index 000000000..c120432fe --- /dev/null +++ b/scripts/mdspell-check.sh @@ -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 diff --git a/wercker.yml b/wercker.yml deleted file mode 100644 index 924918b63..000000000 --- a/wercker.yml +++ /dev/null @@ -1,9 +0,0 @@ -box: billryan/gitbook:base -build: - steps: - - script: - name: build - code: | - make install - make build - make lint