跳轉到

Jenkins Inline Dockerfile Web Image Build

概念概覽

Pipeline 架構

核心知識

Pipeline 架構

BuildPSWebImage-MakeWish.groovy 的特色是 Dockerfile 在 Groovy 內用字串動態產生,而非專案內放固定 Dockerfile:

def dockerfile = """
FROM ${params.baseImage}
COPY ./ /var/www/html/
ADD ./env/vendor-data/vendorData.tar.gz /var/www/html/Gamania
USER root
RUN mkdir -p /var/www/html/Gamania/logs/syncdb /var/www/html/Gamania/logs/batch
RUN chown -R 1000:1000 /var/www/html/
RUN chmod +x /var/www/html/env/scripts/*
COPY ./env/scripts/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
""".stripIndent()
writeFile file: 'Dockerfile', text: dockerfile

ECR 雙 Tag 策略

Build 完後同時推兩個 tag: - func-web-{version} — 版本固定 tag(可回滾) - func-web-latest — 最新 tag(供 helm values 預設使用)

多 Agent 協作

  • mac agent:Pull Repo + archiveArtifacts
  • ps-db (Ubuntu):copyArtifacts + docker build + push ECR
  • gamania-agent-node:kubectl 操作 + init + chown

版號相同不會更新

若 ECR tag 版號不變(如都是 func-web-5),k8s 不會拉新 image(除非 imagePullPolicy=Always)。必須帶新版號或強制 rollout restart 才能更新 pod。

經驗教訓

  • inline Dockerfile 方便在 pipeline 中動態插入修正(如 chown),但不在 repo 版控內,需注意改了哪支 Groovy

  • push 相同版號 tag 到 ECR,k8s 不一定重拉 image,需帶新版號或 imagePullPolicy: Always

  • init-all.sh 在 Jenkins pipeline 中跑完後,必須補 chown -R 1000:1000 /var/www/html/Gamania/logs

常見陷阱

  • Dockerfile 在 Groovy 內,修改後只有重新 build 才會生效,需確認 Groovy 已 commit 且 Jenkins 拉到最新版

  • copyArtifacts 從上一個 stage 取得 source,不是直接 git clone,需確認 archiveArtifacts 有包含所有需要的檔案

最佳實踐

  • 同時推 versioned tag 和 latest tag,確保 helm deploy 能用 latest 也能指定版本回滾

  • init script 後補 chown,不要假設 script 內部能自己維護正確 owner

相關概念

來源 Sessions

日期 Session 貢獻摘要

| 2026-04-14 | 2915f12c-2e40-49a6-9734-a50edf42bc3a | 記錄 BuildPSWebImage-MakeWish Pipeline 的 inline Dockerfile 產生模式,以及 build → tag → push ECR (versioned + latest) → restart pod → init → chown 的完整流程。 |


本概念頁面由 Semi-Brain Wiki 系統自動維護

最後更新: 2026-04-14