Skip to content

Commit

Permalink
Revert "Add sqlite3 driver supported (#383)"
Browse files Browse the repository at this point in the history
This reverts commit cb79df4.
  • Loading branch information
caoyingjunz committed May 16, 2024
1 parent 2e212e2 commit ee50774
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 88 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Pixiu is an open source container platform for cloud-native application manageme
## 学习分享
- [go-learning](https://github.com/caoyingjunz/go-learning)

## 极速安装
## 安装手册
- [安装手册](install.md)

## 沟通交流
Expand Down
25 changes: 2 additions & 23 deletions cmd/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ type LogFormat string
const (
LogFormatJson LogFormat = "json"
LogFormatText LogFormat = "text"

MysqlDriver string = "mysql"
SqliteDriver string = "sqlite3"
)

var ErrInvalidLogFormat = errors.New("invalid log format")

type Config struct {
Default DefaultOptions `yaml:"default"`
Mysql MysqlOptions `yaml:"mysql"`
Sqlite SqliteOptions `yaml:"sqlite3"`
}

type DefaultOptions struct {
Expand All @@ -43,8 +39,6 @@ type DefaultOptions struct {

// 自动创建指定模型的数据库表结构,不会更新已存在的数据库表
AutoMigrate bool `yaml:"auto_migrate"`
// 数据库存储驱动, 默认为 sqlite3
SQLDriver string `yaml:"sql_driver"`

LogOptions `yaml:",inline"`
}
Expand All @@ -70,14 +64,6 @@ func (o MysqlOptions) Valid() error {
return nil
}

type SqliteOptions struct {
DSN string `yaml:"dsn"`
}

func (o SqliteOptions) Valid() error {
return nil
}

type LogOptions struct {
LogFormat `yaml:"log_format"`
}
Expand All @@ -95,15 +81,8 @@ func (c *Config) Valid() (err error) {
if err = c.Default.Valid(); err != nil {
return
}
if c.Default.SQLDriver == MysqlDriver {
if err = c.Mysql.Valid(); err != nil {
return
}
} else {
if err = c.Sqlite.Valid(); err != nil {
return
}
if err = c.Mysql.Valid(); err != nil {
return
}

return
}
59 changes: 18 additions & 41 deletions cmd/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/spf13/cobra"
"gorm.io/driver/mysql"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"

Expand All @@ -39,7 +38,6 @@ const (

defaultListen = 8080
defaultTokenKey = "pixiu"
defaultSQLiteDSN = "/configs/pixiu.db"
defaultConfigFile = "/etc/pixiu/config.yaml"
defaultLogFormat = config.LogFormatJson
)
Expand Down Expand Up @@ -95,15 +93,6 @@ func (o *Options) Complete() error {
if o.ComponentConfig.Default.LogFormat == "" {
o.ComponentConfig.Default.LogFormat = defaultLogFormat
}
if len(o.ComponentConfig.Default.SQLDriver) == 0 {
o.ComponentConfig.Default.SQLDriver = config.SqliteDriver
}
if o.ComponentConfig.Default.SQLDriver == config.SqliteDriver {
if len(o.ComponentConfig.Sqlite.DSN) == 0 {
o.ComponentConfig.Sqlite.DSN = defaultSQLiteDSN
}

}

if err := o.ComponentConfig.Valid(); err != nil {
return err
Expand Down Expand Up @@ -134,42 +123,30 @@ func (o *Options) register() error {
}

func (o *Options) registerDatabase() error {
sqlConfig := o.ComponentConfig.Mysql
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",
sqlConfig.User,
sqlConfig.Password,
sqlConfig.Host,
sqlConfig.Port,
sqlConfig.Name)

opt := &gorm.Config{}
if o.ComponentConfig.Default.Mode == "debug" {
opt.Logger = logger.Default.LogMode(logger.Info)
}

var (
DB *gorm.DB
err error
)
if o.ComponentConfig.Default.SQLDriver == config.MysqlDriver {
sqlConfig := o.ComponentConfig.Mysql
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",
sqlConfig.User,
sqlConfig.Password,
sqlConfig.Host,
sqlConfig.Port,
sqlConfig.Name)

DB, err = gorm.Open(mysql.Open(dsn), opt)
if err != nil {
return err
}
// 设置数据库连接池
sqlDB, err := DB.DB()
if err != nil {
return err
}
sqlDB.SetMaxIdleConns(maxIdleConns)
sqlDB.SetMaxOpenConns(maxOpenConns)
} else {
dsn := o.ComponentConfig.Sqlite.DSN
DB, err = gorm.Open(sqlite.Open(dsn), opt)
if err != nil {
return err
}
DB, err := gorm.Open(mysql.Open(dsn), opt)
if err != nil {
return err
}
// 设置数据库连接池
sqlDB, err := DB.DB()
if err != nil {
return err
}
sqlDB.SetMaxIdleConns(maxIdleConns)
sqlDB.SetMaxOpenConns(maxOpenConns)

o.Factory, err = db.NewDaoFactory(DB, o.ComponentConfig.Default.AutoMigrate)
if err != nil {
Expand Down
5 changes: 0 additions & 5 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ default:
jwt_key: pixiu
# 自动创建指定模型的数据库表结构,不会更新已存在的数据库表
auto_migrate: true
# 数据库存储驱动, 默认为 sqlite3
sql_driver: sqlite3

log_format: json

Expand All @@ -19,6 +17,3 @@ mysql:
password: Pixiu868686
port: 3306
name: pixiu

sqlite3:
dsn: /tmp/pixiu.db
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/lib/pq v1.10.2 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.12 // indirect
github.com/mittwald/go-helm-client v0.8.1
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
Expand All @@ -42,8 +43,7 @@ require (
golang.org/x/time v0.1.0
google.golang.org/protobuf v1.33.0 // indirect
gorm.io/driver/mysql v1.3.6
gorm.io/driver/sqlite v1.4.4 // indirect
gorm.io/gorm v1.24.0
gorm.io/gorm v1.23.8
helm.sh/helm/v3 v3.6.3
k8s.io/api v0.22.1
k8s.io/apimachinery v0.22.1
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,6 @@ github.com/mattn/go-sqlite3 v1.12.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsO
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0=
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
Expand Down Expand Up @@ -1526,12 +1524,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.3.6 h1:BhX1Y/RyALb+T9bZ3t07wLnPZBukt+IRkMn8UZSNbGM=
gorm.io/driver/mysql v1.3.6/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
gorm.io/driver/sqlite v1.4.4 h1:gIufGoR0dQzjkyqDyYSCvsYR6fba1Gw5YKDqKeChxFc=
gorm.io/driver/sqlite v1.4.4/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI=
gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.24.0 h1:j/CoiSm6xpRpmzbFJsQHYj+I8bGYWLXVHeYEyyKlF74=
gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
Expand Down
54 changes: 44 additions & 10 deletions install.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,63 @@
# 安装手册
# 前置准备
```bash
docker 已经安装
代码 https://github.com/caoyingjunz/pixiu
```
# 数据库
```bash
选择1:直接提供可用数据库

选择2:快速启动数据库
docker run -d --net host --restart=always --privileged=true --name mariadb -e MYSQL_ROOT_PASSWORD="Pixiu868686" mysql:5.7

### 启动 pixiu 服务端
创建 pixiu 数据库
CREATE DATABASE pixiu;
```
# 启动 pixiu 服务端
```bash
# 创建配置文件夹
创建配置文件夹
mkdir -p /etc/pixiu/

# 后端配置
vim /etc/pixiu/config.yaml
后端配置(host 根据实际情况调整)
vim /etc/pixiu/config.yaml 写入后端如下配置
default:
# 运行模式,可选 debug 和 release
mode: debug
listen: 8090
auto_migrate: true

# 前端配置(ip 根据实际情况调整)
数据库地址信息
mysql:
host: pixiu
user: root
password: Pixiu868686
port: 3306
name: pixiu

前端配置(ip 根据实际情况调整)
vim /etc/pixiu/config.json
{
"url": "http://192.168.16.156"
}
```

### 启动 pixiu
# 启动 pixiu
```bash
docker run -d --net host --restart=always --privileged=true -v /etc/pixiu/:/configs --name pixiu-aio jacky06/pixiu-aio

# 登录效果
登录效果
浏览器登陆: http://192.168.16.156
```
# 页面展示
首页
<img width="1647" alt="image" src="https://github.com/youdian-xiaoshuai/pixiu/assets/64686398/9fc5e005-95cd-49ee-a13c-13f22949fd74">

容器服务
![image](https://github.com/youdian-xiaoshuai/pixiu/assets/64686398/9e450085-2297-4453-80e3-40b0775796a8)

集群展示
![image](https://github.com/youdian-xiaoshuai/pixiu/assets/64686398/9d3fa88a-6da1-4d86-bfb2-0f9a50ab77d5)

命名空间
![image](https://github.com/youdian-xiaoshuai/pixiu/assets/64686398/2af3946b-4f66-4859-bee4-68589d889ef5)



0 comments on commit ee50774

Please sign in to comment.