作者 主題: [docker] 自動建立gitbook pdf  (閱讀 6651 次)

0 會員 與 1 訪客 正在閱讀本文。

zarr12steven

  • SA 苦力組
  • 懷疑的國中生
  • **
  • 文章數: 71
    • 檢視個人資料
[docker] 自動建立gitbook pdf
« 於: 2016-02-05 13:56 »
Goal:

主要是要拿來讓大家有個共同寫文件的地方,並且在每次git push後,自動產生pdf的文件。

Step:

先準備好Dockerfile,然後直接執行docker-compose -f docker-compose.yml build,跑完之後再執行docker-compose -f docker-compose.yml up -d,這樣服務就都會起來,gitbook 開 80port,gitlab 開 10080 & 10022 port。

先至gitlab建立一個專案,至少先推一個README.md檔案,把這個專案clone下來,接下來就到project → 目前的專案 → Settings → Runners,此時會看到urltoken,需要把它記下來,再來就是將gitlab-runner 註冊在 gitlab-ci 上,

註冊方法如下:

代碼: [選擇]
docker exec -it NAME gitlab-runner register

請依照畫面跳出的訊息,做註冊,註冊完後就會看到有一個runner在剛剛runner的頁面,記得剛剛註冊的tag需要與.gitlab-ci.yml裡面的tag命名要一樣的,否則會執行失敗

.gitlab-ci.yml 這個檔案必須要存在你的專案的根目錄下,這個檔案主要用於決定 Gitlab CI 要如何對專案 build、test、deploy…等等。詳細的說明可以參考官方文件

補充:

  • gitbook目錄下,一定要有二個檔案,一個是README.md,另一個是SUMMARY.md,而SUMMARY.md這個是來管理你的book的結構,如果沒有這二個檔案請下gitbook init就會產生出來



範例如下:

代碼: [選擇]
# Summary

This is the summary of my book.

* [section 1](section1/README.md)
    * [example 1](section1/example1.md)
    * [example 2](section1/example2.md)
* [section 2](section2/README.md)
    * [example 1](section2/example1.md)
  • .gitlab-ci.yml裡面的image參數,它會去抓Docker registry,但如果內部有private Docker registry,寫法則會如下:

代碼: [選擇]
image: my.registry.tld:5000/namepace/image:tag

In the example above, GitLab Runner will look at my.registry.tld:5000 for the image namespace/image:tag.


非常感謝shuo & sameersbn 的資訊,上述所說的dokcerfile 都是撿現成的來用,所以可以直接去抓二位大神的dockerfile即可。

最後再廢話一句,這個模式後來是把gitbook 產出靜態檔出來後,丟給nginx去show畫面。

Reference:

https://github.com/shuo/docker-gitbook-builder
https://github.com/sameersbn/docker-gitlab
https://github.com/GitbookIO/gitbook
https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/configuration/advanced-configuration.md
http://doc.gitlab.com/ce/ci/docker/using_docker_images.html#define-an-image-from-a-private-docker-registryGitLab Documentation
http://doc.gitlab.com/ce/ci/yaml/README.html#using-a-private-docker-registry
« 上次編輯: 2016-02-05 16:41 由 zarr12steven »
不強就要挨打

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
Re: [docker] 自動建立gitbook pdf
« 回覆 #1 於: 2016-02-05 16:39 »
跪著看完... Orz

HaWay

  • 大隻佬!
  • 區域板主
  • 俺是博士!
  • *****
  • 文章數: 3980
    • 檢視個人資料
Re: [docker] 自動建立gitbook pdf
« 回覆 #2 於: 2016-02-11 17:20 »
 滿酷的,用來共筆寫說明書之類的東西
我做人那麼 nice, 肯定有什麼誤會.....

duncanlo

  • SA 苦力組
  • 俺是博士!
  • *****
  • 文章數: 7312
    • 檢視個人資料
Re: [docker] 自動建立gitbook pdf
« 回覆 #3 於: 2016-02-26 10:08 »
請問在輸出pdf後,在書名的地方,應該是README.md的內容,或是Introduction的部份,
中文會不會出現亂碼(就是一堆?????),但其他章節內容的中文都正常...

是我沒宣告LANG環境變數或是沒book.json嗎?!

謝謝!!

duncanlo

  • SA 苦力組
  • 俺是博士!
  • *****
  • 文章數: 7312
    • 檢視個人資料
Re: [docker] 自動建立gitbook pdf
« 回覆 #4 於: 2016-02-26 23:08 »
又是自問自答...

執行 gitbook pdf 前,需先 export LC_ALL=zh_TW.UTF-8 後再輸出 PDF 就正常,因為該 container 內預設是 POSIX.