首页 » Python » python3 高级篇 » 正文

django 发布系统(一)

一、需求

  • 代码仓库地址(一个大应用或许有多个代码分支)
  • 应用(父应用,子应用)
  • 部署环境集群(测试,预发,线上)

二、表设计

models.py

from django.db import models

# Create your models here.

class Record(models.Model):     ##记录上线日志,如果出现bug可以查看信息
    timestamp = models.CharField(max_length=64, blank=True, verbose_name="时间")
    project = models.ForeignKey(to="App", blank=True, null=True, verbose_name="应用", related_name="proj")
    package = models.ManyToManyField(to="Package", blank=True, null=True, verbose_name="代码", related_name="pack")
    env = models.ForeignKey(to="RecordEnv", blank=True, null=True, verbose_name="环境", related_name="env")
    def __str__(self):
        return self.timestamp
    class Meta:
        verbose_name_plural = "部署记录"


class App(models.Model):
    name = models.CharField(max_length=32, blank=True, null=True, verbose_name='应用名')
    path = models.CharField(max_length=64, blank=True, null=True, verbose_name='应用路径')
    environment = models.ForeignKey(to='RecordEnv', blank=True, null=True, verbose_name='环境')
    hosts = models.ManyToManyField(to='Host', blank=True, null=True, verbose_name='对应主机', related_name="apphost")
    # _script = models.CharField(max_length=32, blank=True, null=True, verbose_name='部署脚本')   ##单独一台主机去分发脚本
    package = models.ForeignKey(to='Package', blank=True, null=True, verbose_name='代码', related_name='apppack')
    _app = models.ForeignKey(to='App', blank=True, null=True, verbose_name='上级应用')      ##关联自己
    class Meta:
        verbose_name_plural = "项目表"


class RecordEnv(models.Model):
    name = models.CharField(max_length=64, blank=True, null=True, verbose_name="环境名")
    def __str__(self):
        return self.name
    class Meta:
        verbose_name_plural = "环境"


class Host(models.Model):
    hostname = models.CharField(max_length=32, blank=True, null=True, verbose_name="salt_id")
    ip = models.CharField(max_length=32, blank=True, null=True, verbose_name="IP")
    def __str__(self):
        return self.hostname
    class Meta:
        verbose_name_plural = "主机表"


class Package(models.Model):
    name = models.CharField(max_length=64, blank=True, null=True, verbose_name='包名/版本号/需求编号')
    pack_path = models.CharField(max_length=64, blank=True, null=True, verbose_name='代码的路径')
    def __str__(self):
        return self.name
    class Meta:
        verbose_name_plural = '代码'
赞 (0)

发表评论