系列文章:
Overview
本篇說明如何用 Jenkins、Docker、Nginx 建立靜態網頁專案的 CI/CD pipeline。
Setup Steps
- 初始化專案
- Push 到 GitLab repository,取得 repository URI
- 建立 Jenkins 專用的 GitLab 使用者,設定 SSH 金鑰(public key)
- 在 Docker 上跑 Nginx 容器,掛載靜態內容與 nginx 設定檔兩個 volume:參考:nginx.conf 設定範例
sudo docker run --name um1215-client \ -v /home/administrator/um1215/:/usr/share/nginx/html:ro \ -v /home/administrator/um1215/nginx.conf:/etc/nginx/nginx.conf:ro \ -p 21201:80 -d --restart=unless-stopped nginx - 設定 Jenkins task:
- 取得 webhook 連結並加入 GitLab
- 設定 private key 與 repository URI 以供 Jenkins 取得專案
- 若使用 Node.js,選擇 nvm wrapper 並指定版本
- 新增 shell 建置指令:
npm install npm install -d npm run build
- 設定 Publish Over SSH
- 完成設定
原文發表於 Medium