mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-10 23:47:39 +08:00
feat: 安装升级应用增加强制拉取镜像选项 (#3746)
This commit is contained in:
parent
70863f411d
commit
51d7a84062
8 changed files with 38 additions and 24 deletions
|
@ -32,6 +32,7 @@ type AppContainerConfig struct {
|
||||||
EditCompose bool `json:"editCompose"`
|
EditCompose bool `json:"editCompose"`
|
||||||
DockerCompose string `json:"dockerCompose"`
|
DockerCompose string `json:"dockerCompose"`
|
||||||
HostMode bool `json:"hostMode"`
|
HostMode bool `json:"hostMode"`
|
||||||
|
PullImage bool `json:"pullImage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppInstalledSearch struct {
|
type AppInstalledSearch struct {
|
||||||
|
@ -67,6 +68,7 @@ type AppInstalledOperate struct {
|
||||||
DeleteBackup bool `json:"deleteBackup"`
|
DeleteBackup bool `json:"deleteBackup"`
|
||||||
DeleteDB bool `json:"deleteDB"`
|
DeleteDB bool `json:"deleteDB"`
|
||||||
Backup bool `json:"backup"`
|
Backup bool `json:"backup"`
|
||||||
|
PullImage bool `json:"pullImage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppInstalledUpdate struct {
|
type AppInstalledUpdate struct {
|
||||||
|
|
|
@ -459,7 +459,7 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
|
||||||
if err = runScript(appInstall, "init"); err != nil {
|
if err = runScript(appInstall, "init"); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
upApp(appInstall)
|
upApp(appInstall, req.PullImage)
|
||||||
}()
|
}()
|
||||||
go updateToolApp(appInstall)
|
go updateToolApp(appInstall)
|
||||||
return
|
return
|
||||||
|
|
|
@ -263,7 +263,7 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error {
|
||||||
case constant.Sync:
|
case constant.Sync:
|
||||||
return syncByID(install.ID)
|
return syncByID(install.ID)
|
||||||
case constant.Upgrade:
|
case constant.Upgrade:
|
||||||
return upgradeInstall(install.ID, req.DetailId, req.Backup)
|
return upgradeInstall(install.ID, req.DetailId, req.Backup, req.PullImage)
|
||||||
case constant.Reload:
|
case constant.Reload:
|
||||||
return opNginx(install.ContainerName, constant.NginxReload)
|
return opNginx(install.ContainerName, constant.NginxReload)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -433,12 +433,12 @@ func deleteLink(ctx context.Context, install *model.AppInstall, deleteDB bool, f
|
||||||
return appInstallResourceRepo.DeleteBy(ctx, appInstallResourceRepo.WithAppInstallId(install.ID))
|
return appInstallResourceRepo.DeleteBy(ctx, appInstallResourceRepo.WithAppInstallId(install.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func upgradeInstall(installId uint, detailId uint, backup bool) error {
|
func upgradeInstall(installID uint, detailID uint, backup, pullImage bool) error {
|
||||||
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
|
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(detailId))
|
detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(detailID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -556,7 +556,7 @@ func upgradeInstall(installId uint, detailId uint, backup bool) error {
|
||||||
|
|
||||||
install.DockerCompose = string(composeByte)
|
install.DockerCompose = string(composeByte)
|
||||||
install.Version = detail.Version
|
install.Version = detail.Version
|
||||||
install.AppDetailId = detailId
|
install.AppDetailId = detailID
|
||||||
|
|
||||||
if out, err := compose.Down(install.GetComposePath()); err != nil {
|
if out, err := compose.Down(install.GetComposePath()); err != nil {
|
||||||
if out != "" {
|
if out != "" {
|
||||||
|
@ -581,6 +581,7 @@ func upgradeInstall(installId uint, detailId uint, backup bool) error {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pullImage {
|
||||||
images, err := composeV2.GetDockerComposeImages(install.Name, content, []byte(detail.DockerCompose))
|
images, err := composeV2.GetDockerComposeImages(install.Name, content, []byte(detail.DockerCompose))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
upErr = err
|
upErr = err
|
||||||
|
@ -597,6 +598,7 @@ func upgradeInstall(installId uint, detailId uint, backup bool) error {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if upErr = fileOp.WriteFile(install.GetComposePath(), strings.NewReader(install.DockerCompose), 0775); upErr != nil {
|
if upErr = fileOp.WriteFile(install.GetComposePath(), strings.NewReader(install.DockerCompose), 0775); upErr != nil {
|
||||||
return
|
return
|
||||||
|
@ -839,14 +841,14 @@ func checkContainerNameIsExist(containerName, appDir string) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func upApp(appInstall *model.AppInstall) {
|
func upApp(appInstall *model.AppInstall, pullImages bool) {
|
||||||
upProject := func(appInstall *model.AppInstall) (err error) {
|
upProject := func(appInstall *model.AppInstall) (err error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
var (
|
var (
|
||||||
out string
|
out string
|
||||||
errMsg string
|
errMsg string
|
||||||
)
|
)
|
||||||
if appInstall.App.Type != "php" {
|
if pullImages && appInstall.App.Type != "php" {
|
||||||
out, err = compose.Pull(appInstall.GetComposePath())
|
out, err = compose.Pull(appInstall.GetComposePath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if out != "" {
|
if out != "" {
|
||||||
|
@ -861,6 +863,7 @@ func upApp(appInstall *model.AppInstall) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err = compose.Up(appInstall.GetComposePath())
|
out, err = compose.Up(appInstall.GetComposePath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if out != "" {
|
if out != "" {
|
||||||
|
|
|
@ -1698,7 +1698,7 @@ const message = {
|
||||||
disable: '未啟用',
|
disable: '未啟用',
|
||||||
disableLeechHelper: '是否禁用防盜鏈',
|
disableLeechHelper: '是否禁用防盜鏈',
|
||||||
disableLeech: '禁用防盜鏈',
|
disableLeech: '禁用防盜鏈',
|
||||||
ipv6: '監聽 IPV6 端口',
|
ipv6: '監聽 IPV6',
|
||||||
leechReturnError: '請填寫 HTTP 狀態碼',
|
leechReturnError: '請填寫 HTTP 狀態碼',
|
||||||
selectAcme: '選擇 Acme 賬號',
|
selectAcme: '選擇 Acme 賬號',
|
||||||
imported: '手動創建',
|
imported: '手動創建',
|
||||||
|
|
|
@ -1698,7 +1698,7 @@ const message = {
|
||||||
disable: '未启用',
|
disable: '未启用',
|
||||||
disableLeechHelper: '是否禁用防盗链',
|
disableLeechHelper: '是否禁用防盗链',
|
||||||
disableLeech: '禁用防盗链',
|
disableLeech: '禁用防盗链',
|
||||||
ipv6: '监听 IPV6 端口',
|
ipv6: '监听 IPV6',
|
||||||
leechReturnError: '请填写 HTTP 状态码',
|
leechReturnError: '请填写 HTTP 状态码',
|
||||||
selectAcme: '选择 acme 账号',
|
selectAcme: '选择 acme 账号',
|
||||||
imported: '手动创建',
|
imported: '手动创建',
|
||||||
|
|
|
@ -103,11 +103,14 @@
|
||||||
{{ $t('container.limitHelper', [limits.memory]) }}{{ req.memoryUnit }}B
|
{{ $t('container.limitHelper', [limits.memory]) }}{{ req.memoryUnit }}B
|
||||||
</span>
|
</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item prop="editCompose">
|
<el-form-item prop="editCompose">
|
||||||
<el-checkbox v-model="req.editCompose" :label="$t('app.editCompose')" size="large" />
|
<el-checkbox v-model="req.editCompose" :label="$t('app.editCompose')" size="large" />
|
||||||
<span class="input-help">{{ $t('app.editComposeHelper') }}</span>
|
<span class="input-help">{{ $t('app.editComposeHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item pro="pullImage">
|
||||||
|
<el-checkbox v-model="req.pullImage" :label="$t('container.forcePull')" size="large" />
|
||||||
|
<span class="input-help">{{ $t('container.forcePullHelper') }}</span>
|
||||||
|
</el-form-item>
|
||||||
<div v-if="req.editCompose">
|
<div v-if="req.editCompose">
|
||||||
<codemirror
|
<codemirror
|
||||||
:autofocus="true"
|
:autofocus="true"
|
||||||
|
@ -193,6 +196,7 @@ const initData = () => ({
|
||||||
dockerCompose: '',
|
dockerCompose: '',
|
||||||
version: '',
|
version: '',
|
||||||
appID: '',
|
appID: '',
|
||||||
|
pullImage: true,
|
||||||
});
|
});
|
||||||
const req = reactive(initData());
|
const req = reactive(initData());
|
||||||
const limits = ref<Container.ResourceLimit>({
|
const limits = ref<Container.ResourceLimit>({
|
||||||
|
|
|
@ -31,6 +31,10 @@
|
||||||
<el-checkbox v-model="operateReq.backup" :label="$t('app.backupApp')" />
|
<el-checkbox v-model="operateReq.backup" :label="$t('app.backupApp')" />
|
||||||
<span class="input-help">{{ $t('app.backupAppHelper') }}</span>
|
<span class="input-help">{{ $t('app.backupAppHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item pro="pullImage">
|
||||||
|
<el-checkbox v-model="operateReq.pullImage" :label="$t('container.forcePull')" size="large" />
|
||||||
|
<span class="input-help">{{ $t('container.forcePullHelper') }}</span>
|
||||||
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="22" :offset="1">
|
<el-col :span="22" :offset="1">
|
||||||
|
@ -88,6 +92,7 @@ const operateReq = reactive({
|
||||||
operate: 'upgrade',
|
operate: 'upgrade',
|
||||||
installId: 0,
|
installId: 0,
|
||||||
backup: true,
|
backup: true,
|
||||||
|
pullImage: true,
|
||||||
});
|
});
|
||||||
const resourceName = ref('');
|
const resourceName = ref('');
|
||||||
const rules = ref<any>({
|
const rules = ref<any>({
|
||||||
|
|
Loading…
Add table
Reference in a new issue