5eecbecd7f
- Portal: wrap .panel-head in matching card (border, radius, shadow) with cyan->purple left accent bar; h2 28px -> 20px; description right-aligned with vertical divider; top edge now aligns with side-menu & links-panel - Login: switch from absolute-positioned icons to el-input prefix slot; layout brand row (logo + title + uppercase subtitle); add form-title section with gradient bar; consistent cyan focus; gradient button; dashed top divider for back-link; card width 420 -> 460 - Add .gitignore (node_modules, dist, __pycache__, .env, etc.)
208 lines
8.0 KiB
Python
208 lines
8.0 KiB
Python
"""Seed default admin + demo content mirroring the reference design."""
|
|
from extensions import db
|
|
from models import Category, Option, OptionRow, Resource, SideLink, SiteSetting, User
|
|
|
|
DEFAULT_SETTINGS = {
|
|
"site_name": "OPS 资源中心",
|
|
"hero_tag": "INTERNAL RESOURCES",
|
|
"hero_title": "内部资源 快速上手",
|
|
"hero_subtitle": "执行一条命令完成初始化,发现更多面向开发者的内部镜像与工具",
|
|
"hero_command": "curl -sSL http://ops.internal/init.sh | bash",
|
|
"hero_command_label": "RUN THE COMMAND TO INSTALL",
|
|
"announcement": "欢迎使用内部资源中心 · 新增资源请联系运维组",
|
|
"footer_text": "OPS Resource Portal · 内部使用",
|
|
}
|
|
|
|
|
|
def seed_admin():
|
|
if not User.query.filter_by(username="admin").first():
|
|
u = User(username="admin")
|
|
u.set_password("admin123")
|
|
db.session.add(u)
|
|
db.session.commit()
|
|
print("[seed] admin user created (admin / admin123)")
|
|
|
|
|
|
def seed_settings():
|
|
changed = False
|
|
for k, v in DEFAULT_SETTINGS.items():
|
|
if not SiteSetting.query.get(k):
|
|
db.session.add(SiteSetting(key=k, value=v))
|
|
changed = True
|
|
if changed:
|
|
db.session.commit()
|
|
|
|
|
|
def seed_demo():
|
|
"""Populate demo content only on a completely empty database."""
|
|
if Category.query.first():
|
|
return
|
|
|
|
# ---------------- Categories ----------------
|
|
cats = {}
|
|
for i, (name, icon, desc) in enumerate([
|
|
("基础设备", "🖥️", "物理机 / KVM / Docker 等基础环境入口"),
|
|
("基础系统", "💿", "各操作系统的初始化与配置"),
|
|
("初始化执行命令", "⚡", "新机器上架后执行的标准命令"),
|
|
("软件列表", "📦", "内部常用软件与工具清单"),
|
|
("pypi源", "🐍", "内部 PyPI 镜像源配置"),
|
|
("镜像源", "🪞", "apt / yum / npm 等镜像源汇总"),
|
|
]):
|
|
c = Category(name=name, icon=icon, description=desc, sort_order=i)
|
|
db.session.add(c)
|
|
cats[name] = c
|
|
db.session.flush()
|
|
|
|
# ---------------- Option rows ----------------
|
|
def add_rows(cat, rows):
|
|
out = {}
|
|
for i, (title, labels) in enumerate(rows):
|
|
row = OptionRow(category_id=cat.id, title=title, sort_order=i)
|
|
db.session.add(row)
|
|
db.session.flush()
|
|
opts = []
|
|
for j, (label, icon) in enumerate(labels):
|
|
o = Option(row_id=row.id, label=label, icon=icon, sort_order=j)
|
|
db.session.add(o)
|
|
opts.append(o)
|
|
db.session.flush()
|
|
out[title] = opts
|
|
return out
|
|
|
|
env_labels = [("物理机", "🖥️"), ("KVM虚拟机", "🧩"), ("Docker容器", "🐳")]
|
|
os_labels = [("ubuntu", ""), ("debian", ""), ("centos", ""), ("kylin", "")]
|
|
|
|
opts_base = add_rows(cats["基础设备"], [("运行环境", env_labels)])
|
|
opts_sys = add_rows(cats["基础系统"], [("运行环境", env_labels), ("操作系统", os_labels)])
|
|
opts_pypi = add_rows(cats["pypi源"], [("运行环境", env_labels), ("操作系统", os_labels)])
|
|
|
|
# ---------------- Resources ----------------
|
|
r = Resource(
|
|
category_id=cats["pypi源"].id,
|
|
title="配置内部 pip 源",
|
|
type="command",
|
|
content="mkdir -p ~/.pip && wget http://ops.streamcomputing.com/repo_list/pip.conf -O ~/.pip/pip.conf",
|
|
description="一键写入 pip.conf,立即生效",
|
|
sort_order=0,
|
|
)
|
|
db.session.add(r)
|
|
|
|
db.session.add(Resource(
|
|
category_id=cats["pypi源"].id,
|
|
title="Docker 构建时注入 pip 源",
|
|
type="command",
|
|
content="RUN mkdir -p /root/.pip && wget -q http://ops.streamcomputing.com/repo_list/pip.conf -O /root/.pip/pip.conf",
|
|
description="适用于 Dockerfile 构建场景",
|
|
sort_order=1,
|
|
options=[opts_pypi["运行环境"][2]], # Docker容器
|
|
))
|
|
|
|
db.session.add(Resource(
|
|
category_id=cats["pypi源"].id,
|
|
title="PyPI 包索引浏览",
|
|
type="link",
|
|
url="http://ops.streamcomputing.com/pypi/",
|
|
description="Index of / — 内部镜像的全量包列表",
|
|
sort_order=2,
|
|
))
|
|
|
|
db.session.add(Resource(
|
|
category_id=cats["基础系统"].id,
|
|
title="Ubuntu / Debian 初始化",
|
|
type="command",
|
|
content="wget http://ops.streamcomputing.com/repo_list/ubuntu.sources -O /etc/apt/sources.list.d/internal.sources && apt-get update",
|
|
description="替换为内部 apt 源并刷新索引",
|
|
sort_order=0,
|
|
options=[opts_sys["操作系统"][0], opts_sys["操作系统"][1]], # ubuntu, debian
|
|
))
|
|
db.session.add(Resource(
|
|
category_id=cats["基础系统"].id,
|
|
title="CentOS / Kylin 初始化",
|
|
type="command",
|
|
content="wget http://ops.streamcomputing.com/repo_list/CentOS-Base.repo -O /etc/yum.repos.d/CentOS-Base.repo && yum makecache",
|
|
description="替换为内部 yum 源并建立缓存",
|
|
sort_order=1,
|
|
options=[opts_sys["操作系统"][2], opts_sys["操作系统"][3]], # centos, kylin
|
|
))
|
|
db.session.add(Resource(
|
|
category_id=cats["基础系统"].id,
|
|
title="KVM 虚拟机 cloud-init 说明",
|
|
type="text",
|
|
content="KVM 模板镜像已内置 cloud-init,首次启动会自动扩容磁盘并注入 SSH 公钥。\n如需自定义主机名,请在创建时传入 metadata。",
|
|
description="适用于 KVM 模板镜像",
|
|
sort_order=2,
|
|
options=[opts_sys["运行环境"][1]], # KVM虚拟机
|
|
))
|
|
|
|
db.session.add(Resource(
|
|
category_id=cats["初始化执行命令"].id,
|
|
title="标准初始化脚本",
|
|
type="command",
|
|
content="curl -sSL http://ops.streamcomputing.com/init/bootstrap.sh | bash",
|
|
description="包含时区、内核参数、监控 agent 安装",
|
|
sort_order=0,
|
|
))
|
|
db.session.add(Resource(
|
|
category_id=cats["初始化执行命令"].id,
|
|
title="初始化自检",
|
|
type="command",
|
|
content="ops-check --all --report",
|
|
description="初始化完成后执行,输出自检报告",
|
|
sort_order=1,
|
|
))
|
|
|
|
db.session.add(Resource(
|
|
category_id=cats["软件列表"].id,
|
|
title="内部软件清单",
|
|
type="link",
|
|
url="http://ops.streamcomputing.com/software/",
|
|
description="常用软件版本与下载入口",
|
|
sort_order=0,
|
|
))
|
|
db.session.add(Resource(
|
|
category_id=cats["软件列表"].id,
|
|
title="CLI 工具合集",
|
|
type="text",
|
|
content="ops-cli / dbtool / netprobe / logtail\n安装方式见各软件详情页。",
|
|
sort_order=1,
|
|
))
|
|
|
|
db.session.add(Resource(
|
|
category_id=cats["基础设备"].id,
|
|
title="设备申领入口",
|
|
type="link",
|
|
url="http://ops.streamcomputing.com/devices/",
|
|
description="物理机 / 虚拟机 / 容器资源申领",
|
|
sort_order=0,
|
|
))
|
|
|
|
db.session.add(Resource(
|
|
category_id=cats["镜像源"].id,
|
|
title="镜像源总览",
|
|
type="link",
|
|
url="http://ops.streamcomputing.com/mirrors/",
|
|
description="apt / yum / pypi / npm / docker registry",
|
|
sort_order=0,
|
|
))
|
|
|
|
# ---------------- Side links ----------------
|
|
for i, (title, url) in enumerate([
|
|
("Docker镜像仓库", "http://ops.streamcomputing.com/docker/"),
|
|
("Docker基础镜像使用方法以及镜像列表", "http://ops.streamcomputing.com/docker/guide"),
|
|
("KVM模板镜像下载", "http://ops.streamcomputing.com/kvm/images"),
|
|
("KVM模板镜像信息一览表", "http://ops.streamcomputing.com/kvm/list"),
|
|
("iso镜像下载", "http://ops.streamcomputing.com/iso/"),
|
|
("grafana网址", "http://grafana.streamcomputing.com/"),
|
|
("ops文档中心", "http://docs.streamcomputing.com/"),
|
|
]):
|
|
db.session.add(SideLink(title=title, url=url, sort_order=i))
|
|
|
|
db.session.commit()
|
|
print("[seed] demo content created")
|
|
|
|
|
|
def seed_all():
|
|
seed_admin()
|
|
seed_settings()
|
|
seed_demo()
|