1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-13 17:24:44 +08:00

feat: 安装升级应用增加强制拉取镜像选项 (#3746)

This commit is contained in:
zhengkunwang 2024-01-30 16:11:41 +08:00 committed by GitHub
parent 70863f411d
commit 51d7a84062
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 38 additions and 24 deletions

View File

@ -32,6 +32,7 @@ type AppContainerConfig struct {
EditCompose bool `json:"editCompose"`
DockerCompose string `json:"dockerCompose"`
HostMode bool `json:"hostMode"`
PullImage bool `json:"pullImage"`
}
type AppInstalledSearch struct {
@ -67,6 +68,7 @@ type AppInstalledOperate struct {
DeleteBackup bool `json:"deleteBackup"`
DeleteDB bool `json:"deleteDB"`
Backup bool `json:"backup"`
PullImage bool `json:"pullImage"`
}
type AppInstalledUpdate struct {

View File

@ -459,7 +459,7 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
if err = runScript(appInstall, "init"); err != nil {
return
}
upApp(appInstall)
upApp(appInstall, req.PullImage)
}()
go updateToolApp(appInstall)
return

View File

@ -263,7 +263,7 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error {
case constant.Sync:
return syncByID(install.ID)
case constant.Upgrade:
return upgradeInstall(install.ID, req.DetailId, req.Backup)
return upgradeInstall(install.ID, req.DetailId, req.Backup, req.PullImage)
case constant.Reload:
return opNginx(install.ContainerName, constant.NginxReload)
default:

View File

@ -433,12 +433,12 @@ func deleteLink(ctx context.Context, install *model.AppInstall, deleteDB bool, f
return appInstallResourceRepo.DeleteBy(ctx, appInstallResourceRepo.WithAppInstallId(install.ID))
}
func upgradeInstall(installId uint, detailId uint, backup bool) error {
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
func upgradeInstall(installID uint, detailID uint, backup, pullImage bool) error {
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installID))
if err != nil {
return err
}
detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(detailId))
detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(detailID))
if err != nil {
return err
}
@ -556,7 +556,7 @@ func upgradeInstall(installId uint, detailId uint, backup bool) error {
install.DockerCompose = string(composeByte)
install.Version = detail.Version
install.AppDetailId = detailId
install.AppDetailId = detailID
if out, err := compose.Down(install.GetComposePath()); err != nil {
if out != "" {
@ -581,21 +581,23 @@ func upgradeInstall(installId uint, detailId uint, backup bool) error {
return
}
images, err := composeV2.GetDockerComposeImages(install.Name, content, []byte(detail.DockerCompose))
if err != nil {
upErr = err
return
}
dockerCli, err := composeV2.NewClient()
if err != nil {
upErr = err
return
}
for _, image := range images {
if err = dockerCli.PullImage(image, true); err != nil {
upErr = buserr.WithNameAndErr("ErrDockerPullImage", "", err)
if pullImage {
images, err := composeV2.GetDockerComposeImages(install.Name, content, []byte(detail.DockerCompose))
if err != nil {
upErr = err
return
}
dockerCli, err := composeV2.NewClient()
if err != nil {
upErr = err
return
}
for _, image := range images {
if err = dockerCli.PullImage(image, true); err != nil {
upErr = buserr.WithNameAndErr("ErrDockerPullImage", "", err)
return
}
}
}
if upErr = fileOp.WriteFile(install.GetComposePath(), strings.NewReader(install.DockerCompose), 0775); upErr != nil {
@ -839,14 +841,14 @@ func checkContainerNameIsExist(containerName, appDir string) (bool, error) {
return false, nil
}
func upApp(appInstall *model.AppInstall) {
func upApp(appInstall *model.AppInstall, pullImages bool) {
upProject := func(appInstall *model.AppInstall) (err error) {
if err == nil {
var (
out string
errMsg string
)
if appInstall.App.Type != "php" {
if pullImages && appInstall.App.Type != "php" {
out, err = compose.Pull(appInstall.GetComposePath())
if err != nil {
if out != "" {
@ -861,6 +863,7 @@ func upApp(appInstall *model.AppInstall) {
return err
}
}
out, err = compose.Up(appInstall.GetComposePath())
if err != nil {
if out != "" {

View File

@ -1698,7 +1698,7 @@ const message = {
disable: '未啟用',
disableLeechHelper: '是否禁用防盜鏈',
disableLeech: '禁用防盜鏈',
ipv6: '監聽 IPV6 端口',
ipv6: '監聽 IPV6',
leechReturnError: '請填寫 HTTP 狀態碼',
selectAcme: '選擇 Acme 賬號',
imported: '手動創建',

View File

@ -1698,7 +1698,7 @@ const message = {
disable: '未启用',
disableLeechHelper: '是否禁用防盗链',
disableLeech: '禁用防盗链',
ipv6: '监听 IPV6 端口',
ipv6: '监听 IPV6',
leechReturnError: '请填写 HTTP 状态码',
selectAcme: '选择 acme 账号',
imported: '手动创建',

View File

@ -103,11 +103,14 @@
{{ $t('container.limitHelper', [limits.memory]) }}{{ req.memoryUnit }}B
</span>
</el-form-item>
<el-form-item prop="editCompose">
<el-checkbox v-model="req.editCompose" :label="$t('app.editCompose')" size="large" />
<span class="input-help">{{ $t('app.editComposeHelper') }}</span>
</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">
<codemirror
:autofocus="true"
@ -193,6 +196,7 @@ const initData = () => ({
dockerCompose: '',
version: '',
appID: '',
pullImage: true,
});
const req = reactive(initData());
const limits = ref<Container.ResourceLimit>({

View File

@ -31,6 +31,10 @@
<el-checkbox v-model="operateReq.backup" :label="$t('app.backupApp')" />
<span class="input-help">{{ $t('app.backupAppHelper') }}</span>
</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-col>
<el-col :span="22" :offset="1">
@ -88,6 +92,7 @@ const operateReq = reactive({
operate: 'upgrade',
installId: 0,
backup: true,
pullImage: true,
});
const resourceName = ref('');
const rules = ref<any>({