mirror of https://github.com/1Panel-dev/1Panel
feat: 增加 docker network 初始化
parent
b8473096f8
commit
ae4662cf26
|
@ -4,6 +4,7 @@ import "time"
|
|||
|
||||
type WebSite struct {
|
||||
BaseModel
|
||||
Protocol string `gorm:"type:varchar(64);not null" json:"protocol"`
|
||||
PrimaryDomain string `gorm:"type:varchar(128);not null" json:"primaryDomain"`
|
||||
Type string `gorm:"type:varchar(64);not null" json:"type"`
|
||||
Alias string `gorm:"type:varchar(128);not null" json:"alias"`
|
||||
|
|
|
@ -264,10 +264,7 @@ func backupInstall(ctx context.Context, install model.AppInstall) error {
|
|||
backup.AppDetailId = install.AppDetailId
|
||||
backup.Param = install.Param
|
||||
|
||||
if err := appInstallBackupRepo.Create(ctx, backup); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return appInstallBackupRepo.Create(ctx, backup)
|
||||
}
|
||||
|
||||
func restoreInstall(install model.AppInstall, backupId uint) error {
|
||||
|
|
|
@ -44,6 +44,7 @@ func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error {
|
|||
ExpireDate: defaultDate,
|
||||
AppInstallID: create.AppInstallID,
|
||||
WebSiteGroupID: create.WebSiteGroupID,
|
||||
Protocol: constant.ProtocolHTTP,
|
||||
}
|
||||
|
||||
if create.AppType == dto.NewApp {
|
||||
|
@ -313,9 +314,12 @@ func (w WebsiteService) OpWebsiteHTTPS(req dto.WebsiteHTTPSOp) (dto.WebsiteHTTPS
|
|||
}
|
||||
|
||||
if req.Enable {
|
||||
website.Protocol = constant.ProtocolHTTPS
|
||||
if err := applySSL(website, ssl); err != nil {
|
||||
return dto.WebsiteHTTPS{}, err
|
||||
}
|
||||
} else {
|
||||
website.Protocol = constant.ProtocolHTTP
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
|
|
@ -9,3 +9,8 @@ const (
|
|||
DateLayout = "2006-01-02"
|
||||
DefaultDate = "1970-01-01"
|
||||
)
|
||||
|
||||
const (
|
||||
ProtocolHTTP = "HTTP"
|
||||
ProtocolHTTPS = "HTTPS"
|
||||
)
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/docker"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||
"path"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
constant.DefaultDataDir = "/opt/1Panel/data"
|
||||
constant.ResourceDir = path.Join(constant.DefaultDataDir, "resource")
|
||||
constant.AppResourceDir = path.Join(constant.ResourceDir, "apps")
|
||||
constant.AppInstallDir = path.Join(constant.DefaultDataDir, "apps")
|
||||
constant.BackupDir = path.Join(constant.DefaultDataDir, "backup")
|
||||
constant.AppBackupDir = path.Join(constant.BackupDir, "apps")
|
||||
|
||||
dirs := []string{constant.DefaultDataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir, constant.BackupDir, constant.AppBackupDir}
|
||||
|
||||
fileOp := files.NewFileOp()
|
||||
for _, dir := range dirs {
|
||||
createDir(fileOp, dir)
|
||||
}
|
||||
|
||||
createDefaultDockerNetwork()
|
||||
}
|
||||
|
||||
func createDir(fileOp files.FileOp, dirPath string) {
|
||||
if !fileOp.Stat(dirPath) {
|
||||
_ = fileOp.CreateDir(dirPath, 0755)
|
||||
}
|
||||
}
|
||||
|
||||
func createDefaultDockerNetwork() {
|
||||
cli, err := docker.NewClient()
|
||||
if err != nil {
|
||||
fmt.Println("init docker client error", err.Error())
|
||||
return
|
||||
}
|
||||
if !cli.NetworkExist("1panel") {
|
||||
if err := cli.CreateNetwork("1panel"); err != nil {
|
||||
fmt.Println("init docker client error", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,11 +3,7 @@ package viper
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/1Panel-dev/1Panel/backend/configs"
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||
"path"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
@ -32,27 +28,4 @@ func Init() {
|
|||
panic(err)
|
||||
}
|
||||
global.CONF = serverConfig
|
||||
InitDir()
|
||||
}
|
||||
|
||||
func InitDir() {
|
||||
constant.DefaultDataDir = "/opt/1Panel/data"
|
||||
constant.ResourceDir = path.Join(constant.DefaultDataDir, "resource")
|
||||
constant.AppResourceDir = path.Join(constant.ResourceDir, "apps")
|
||||
constant.AppInstallDir = path.Join(constant.DefaultDataDir, "apps")
|
||||
constant.BackupDir = path.Join(constant.DefaultDataDir, "backup")
|
||||
constant.AppBackupDir = path.Join(constant.BackupDir, "apps")
|
||||
|
||||
dirs := []string{constant.DefaultDataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir, constant.BackupDir, constant.AppBackupDir}
|
||||
|
||||
fileOp := files.NewFileOp()
|
||||
for _, dir := range dirs {
|
||||
createDir(fileOp, dir)
|
||||
}
|
||||
}
|
||||
|
||||
func createDir(fileOp files.FileOp, dirPath string) {
|
||||
if !fileOp.Stat(dirPath) {
|
||||
_ = fileOp.CreateDir(dirPath, 0755)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package server
|
|||
import (
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"github.com/1Panel-dev/1Panel/backend/init/app"
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/backend/cron"
|
||||
|
@ -23,6 +24,7 @@ import (
|
|||
)
|
||||
|
||||
func Start() {
|
||||
app.Init()
|
||||
viper.Init()
|
||||
log.Init()
|
||||
db.Init()
|
||||
|
|
|
@ -672,14 +672,14 @@ export default {
|
|||
delete: '删除',
|
||||
deleteWarn: '删除操作会把数据一并删除,此操作不可回滚,是否继续?',
|
||||
syncSuccess: '同步成功',
|
||||
canUpdate: '可更新',
|
||||
canUpdate: '可升级',
|
||||
backup: '备份',
|
||||
backupName: '文件名称',
|
||||
backupPath: '文件路径',
|
||||
backupdate: '备份时间',
|
||||
restore: '回滚',
|
||||
restoreWarn: '回滚操作会重启应用,并替换数据,此操作不可回滚,是否继续?',
|
||||
update: '更新',
|
||||
update: '升级',
|
||||
versioneSelect: '请选择版本',
|
||||
},
|
||||
website: {
|
||||
|
@ -740,5 +740,6 @@ export default {
|
|||
renewSuccess: '续签证书',
|
||||
config: '配置',
|
||||
enableHTTPS: '启用HTTPS',
|
||||
aliasHelper: '代号是网站目录的文件夹名称',
|
||||
},
|
||||
};
|
||||
|
|
|
@ -73,7 +73,7 @@ const search = (req: WebSite.NginxConfigReq) => {
|
|||
loading.value = true;
|
||||
GetNginxConfig(req)
|
||||
.then((res) => {
|
||||
if (res.data.length > 0) {
|
||||
if (res.data && res.data.length > 0) {
|
||||
const indexParam = res.data[0];
|
||||
let values = '';
|
||||
for (const param of indexParam.params) {
|
||||
|
|
|
@ -108,7 +108,7 @@ const get = () => {
|
|||
if (res.data) {
|
||||
form.enable = res.data.enable;
|
||||
}
|
||||
if (res.data?.SSL) {
|
||||
if (res.data?.SSL && res.data?.SSL.id > 0) {
|
||||
form.websiteSSLId = res.data.SSL.id;
|
||||
websiteSSL.value = res.data.SSL;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ const search = (req: WebSite.NginxConfigReq) => {
|
|||
loading.value = true;
|
||||
GetNginxConfig(req)
|
||||
.then((res) => {
|
||||
if (res.data.length > 0) {
|
||||
if (res.data && res.data.length > 0) {
|
||||
enable.value = true;
|
||||
for (const param of res.data) {
|
||||
if (param.name === 'limit_conn') {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('website.group')" prop="webSiteGroupID">
|
||||
<el-select v-model="website.webSiteGroupID">
|
||||
<el-select v-model="website.webSiteGroupId">
|
||||
<el-option
|
||||
v-for="(group, index) in groups"
|
||||
:key="index"
|
||||
|
@ -33,7 +33,7 @@
|
|||
:label="$t('website.appInstalled')"
|
||||
prop="appInstallID"
|
||||
>
|
||||
<el-select v-model="website.appInstallID">
|
||||
<el-select v-model="website.appInstallId">
|
||||
<el-option
|
||||
v-for="(appInstall, index) in appInstalles"
|
||||
:key="index"
|
||||
|
@ -94,7 +94,7 @@
|
|||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('website.alias')" prop="alias">
|
||||
<el-input v-model="website.alias"></el-input>
|
||||
<el-input v-model="website.alias" :placeholder="$t('website.aliasHelper')"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('website.remark')" prop="remark">
|
||||
<el-input v-model="website.remark"></el-input>
|
||||
|
@ -129,8 +129,8 @@ const website = ref({
|
|||
alias: '',
|
||||
remark: '',
|
||||
appType: 'installed',
|
||||
appInstallID: 0,
|
||||
webSiteGroupID: 1,
|
||||
appInstallId: 0,
|
||||
webSiteGroupId: 1,
|
||||
otherDomains: '',
|
||||
appinstall: {
|
||||
appID: 0,
|
||||
|
@ -180,7 +180,7 @@ const searchAppInstalled = () => {
|
|||
SearchAppInstalled({ type: 'website' }).then((res) => {
|
||||
appInstalles.value = res.data;
|
||||
if (res.data.length > 0) {
|
||||
website.value.appInstallID = res.data[0].id;
|
||||
website.value.appInstallId = res.data[0].id;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue