fix(ci): harden publishing and validate examples

This commit is contained in:
yeasy
2026-07-10 19:29:30 -07:00
parent 8eabe30dc2
commit daa6661b2b
26 changed files with 27456 additions and 171 deletions
+3
View File
@@ -0,0 +1,3 @@
# 经自动验证的示例
本目录保存书中四类关键示例的单一真相源ComposeDockerfileKubernetes 清单和 GitHub Actions 工作流`tools/test_examples.py` 会调用这些工具各自的原生校验命令CI 中缺少任一工具都会失败本地环境缺少工具则明确报告 `SKIP`
+8
View File
@@ -0,0 +1,8 @@
name: docker-practice
services:
web:
image: nginx:1.28-alpine
ports:
- "8080:80"
restart: unless-stopped
+3
View File
@@ -0,0 +1,3 @@
FROM nginx:1.28-alpine
COPY --chown=nginx:nginx index.html /usr/share/nginx/html/index.html
+10
View File
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="zh-Hans">
<head>
<meta charset="utf-8">
<title>Docker 实践指南示例</title>
</head>
<body>
<h1>Docker 实践指南</h1>
</body>
</html>
@@ -0,0 +1,43 @@
name: Validate container examples
on:
push:
branches:
- master
pull_request:
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Install pinned validators
env:
KUBECONFORM_VERSION: "0.8.0"
KUBECONFORM_SHA256: "9bc2bffbf71f261128533edaf912153948b7ff238f9a531ae6d34466ec287883"
ACTIONLINT_VERSION: "1.7.12"
ACTIONLINT_SHA256: "8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8"
run: |
mkdir -p "$RUNNER_TEMP/bin"
curl -fsSL --retry 3 \
"https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-amd64.tar.gz" \
-o "$RUNNER_TEMP/kubeconform.tar.gz"
echo "${KUBECONFORM_SHA256} $RUNNER_TEMP/kubeconform.tar.gz" | sha256sum -c -
tar xzf "$RUNNER_TEMP/kubeconform.tar.gz" -C "$RUNNER_TEMP/bin" kubeconform
curl -fsSL --retry 3 \
"https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz" \
-o "$RUNNER_TEMP/actionlint.tar.gz"
echo "${ACTIONLINT_SHA256} $RUNNER_TEMP/actionlint.tar.gz" | sha256sum -c -
tar xzf "$RUNNER_TEMP/actionlint.tar.gz" -C "$RUNNER_TEMP/bin" actionlint
echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH"
- name: Validate canonical examples
run: python3 tools/test_examples.py --require-tools
+45
View File
@@ -0,0 +1,45 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.28-alpine
ports:
- name: http
containerPort: 80
readinessProbe:
httpGet:
path: /
port: http
resources:
requests:
cpu: 50m
memory: 32Mi
limits:
cpu: 200m
memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- name: http
port: 80
targetPort: http