cube-studio/myapp/models/model_docker.py

47 lines
1.7 KiB
Python
Raw Normal View History

2021-09-07 18:09:47 +08:00
from flask_appbuilder import Model
from sqlalchemy.orm import relationship
from sqlalchemy import (
Boolean,
Text
2021-09-07 18:09:47 +08:00
)
from myapp.models.base import MyappModelBase
from myapp.models.helpers import AuditMixinNullable
from myapp import app
from sqlalchemy import Column, Integer, String, ForeignKey
2022-10-10 11:44:53 +08:00
2021-09-07 18:09:47 +08:00
from flask import Markup
metadata = Model.metadata
conf = app.config
2021-10-14 17:33:57 +08:00
# from myapp.utils.py.py_k8s import K8s
2021-09-07 18:09:47 +08:00
class Docker(Model,AuditMixinNullable,MyappModelBase):
__tablename__ = 'docker'
id = Column(Integer, primary_key=True)
2022-08-08 20:11:53 +08:00
project_id = Column(Integer, ForeignKey('project.id'), nullable=False)
2021-11-25 18:05:19 +08:00
project = relationship(
"Project", foreign_keys=[project_id]
)
2021-09-07 18:09:47 +08:00
describe = Column(String(200), nullable=True)
base_image = Column(String(200), nullable=True)
target_image=Column(String(200), nullable=True,default='')
2021-10-14 17:33:57 +08:00
last_image = Column(String(200), nullable=True, default='')
need_gpu = Column(Boolean, nullable=True, default=False)
2022-08-08 20:11:53 +08:00
consecutive_build = Column(Boolean, default=True)
2021-10-14 17:33:57 +08:00
expand = Column(Text(65536), default='{}')
2021-09-07 18:09:47 +08:00
def __repr__(self):
return self.label
@property
def save(self):
return Markup(f'<a href="/docker_modelview/save/{self.id}">保存</a>')
@property
def debug(self):
2022-08-04 16:00:41 +08:00
return Markup(f'<a target=_blank href="/docker_modelview/debug/{self.id}">调试</a> | <a href="/docker_modelview/delete_pod/{self.id}">清理</a> | <a target=_blank href="/docker_modelview/save/{self.id}">保存</a>')
2021-10-14 17:33:57 +08:00
2021-11-25 18:05:19 +08:00
@property
def image_history(self):
return Markup(f'基础镜像:{self.base_image}<br>当前镜像:{self.last_image if self.last_image else self.base_image}<br>目标镜像:{self.target_image}')