fix: 用 printf 生成 Ingress YAML,修复缩进问题
All checks were successful
Deploy Static Sites / deploy (push) Successful in 2s
All checks were successful
Deploy Static Sites / deploy (push) Successful in 2s
This commit is contained in:
parent
9aceadb791
commit
2b6f2f10cc
@ -36,62 +36,50 @@ jobs:
|
|||||||
|
|
||||||
- name: Auto generate and apply Ingress
|
- name: Auto generate and apply Ingress
|
||||||
run: |
|
run: |
|
||||||
# 收集所有项目目录名
|
|
||||||
PROJECTS=""
|
PROJECTS=""
|
||||||
for dir in */; do
|
for dir in */; do
|
||||||
case "$dir" in
|
case "$dir" in
|
||||||
.gitea/|.git/|k8s/) continue ;;
|
.gitea/|.git/|k8s/) continue ;;
|
||||||
esac
|
esac
|
||||||
name="${dir%/}"
|
PROJECTS="$PROJECTS ${dir%/}"
|
||||||
PROJECTS="$PROJECTS $name"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# 生成 Ingress YAML
|
# 头部
|
||||||
cat > /tmp/ingress.yaml <<'HEADER'
|
printf 'apiVersion: networking.k8s.io/v1\n' > /tmp/ingress.yaml
|
||||||
apiVersion: networking.k8s.io/v1
|
printf 'kind: Ingress\n' >> /tmp/ingress.yaml
|
||||||
kind: Ingress
|
printf 'metadata:\n' >> /tmp/ingress.yaml
|
||||||
metadata:
|
printf ' name: static-sites-ingress\n' >> /tmp/ingress.yaml
|
||||||
name: static-sites-ingress
|
printf ' annotations:\n' >> /tmp/ingress.yaml
|
||||||
annotations:
|
printf ' kubernetes.io/ingress.class: "traefik"\n' >> /tmp/ingress.yaml
|
||||||
kubernetes.io/ingress.class: "traefik"
|
printf ' cert-manager.io/cluster-issuer: "letsencrypt-prod"\n' >> /tmp/ingress.yaml
|
||||||
cert-manager.io/cluster-issuer: "letsencrypt-prod"
|
printf 'spec:\n' >> /tmp/ingress.yaml
|
||||||
spec:
|
printf ' tls:\n' >> /tmp/ingress.yaml
|
||||||
tls:
|
|
||||||
HEADER
|
|
||||||
|
|
||||||
# 生成 TLS 段
|
|
||||||
for name in $PROJECTS; do
|
for name in $PROJECTS; do
|
||||||
cat >> /tmp/ingress.yaml <<EOF
|
printf ' - hosts:\n' >> /tmp/ingress.yaml
|
||||||
- hosts:
|
printf ' - %s.airlabs.art\n' "$name" >> /tmp/ingress.yaml
|
||||||
- ${name}.airlabs.art
|
printf ' secretName: %s-tls\n' "$name" >> /tmp/ingress.yaml
|
||||||
secretName: ${name}-tls
|
|
||||||
EOF
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# 生成 rules 段
|
printf ' rules:\n' >> /tmp/ingress.yaml
|
||||||
echo " rules:" >> /tmp/ingress.yaml
|
|
||||||
for name in $PROJECTS; do
|
for name in $PROJECTS; do
|
||||||
cat >> /tmp/ingress.yaml <<EOF
|
printf ' - host: %s.airlabs.art\n' "$name" >> /tmp/ingress.yaml
|
||||||
- host: ${name}.airlabs.art
|
printf ' http:\n' >> /tmp/ingress.yaml
|
||||||
http:
|
printf ' paths:\n' >> /tmp/ingress.yaml
|
||||||
paths:
|
printf ' - path: /\n' >> /tmp/ingress.yaml
|
||||||
- path: /
|
printf ' pathType: Prefix\n' >> /tmp/ingress.yaml
|
||||||
pathType: Prefix
|
printf ' backend:\n' >> /tmp/ingress.yaml
|
||||||
backend:
|
printf ' service:\n' >> /tmp/ingress.yaml
|
||||||
service:
|
printf ' name: static-sites\n' >> /tmp/ingress.yaml
|
||||||
name: static-sites
|
printf ' port:\n' >> /tmp/ingress.yaml
|
||||||
port:
|
printf ' number: 80\n' >> /tmp/ingress.yaml
|
||||||
number: 80
|
|
||||||
EOF
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "--- 生成的 Ingress ---"
|
echo "--- 生成的 Ingress ---"
|
||||||
cat /tmp/ingress.yaml
|
cat /tmp/ingress.yaml
|
||||||
|
|
||||||
# 上传并 apply
|
|
||||||
scp /tmp/ingress.yaml root@118.196.70.19:/tmp/ingress.yaml
|
scp /tmp/ingress.yaml root@118.196.70.19:/tmp/ingress.yaml
|
||||||
ssh root@118.196.70.19 "kubectl apply -f /tmp/ingress.yaml"
|
ssh root@118.196.70.19 "kubectl apply -f /tmp/ingress.yaml"
|
||||||
|
|
||||||
echo "✓ Ingress 已自动更新"
|
echo "✓ Ingress 已自动更新"
|
||||||
|
|
||||||
- name: Verify
|
- name: Verify
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user