mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-01-09 00:24:55 +08:00
feat: Optimize image pulling during application installation (#10648)
This commit is contained in:
parent
d773391763
commit
fcf864156d
13 changed files with 34 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
|
@ -484,6 +485,15 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
|
|||
req.Params["RESTY_ADD_PACKAGE_BUILDDEPS"] = ""
|
||||
req.Params["RESTY_CONFIG_OPTIONS_MORE"] = ""
|
||||
}
|
||||
if app.Key == "openresty" && (app.Resource == "remote" || app.Resource == "custom") && common.CompareVersion(appDetail.Version, "1.27") {
|
||||
if dir, ok := req.Params["WEBSITE_DIR"]; ok {
|
||||
siteDir := dir.(string)
|
||||
if siteDir == "" || !strings.HasPrefix(siteDir, "/") {
|
||||
siteDir = path.Join(global.Dir.DataDir, dir.(string))
|
||||
}
|
||||
req.Params["WEBSITE_DIR"] = siteDir
|
||||
}
|
||||
}
|
||||
paramByte, err = json.Marshal(req.Params)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -511,7 +521,7 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
|
|||
return err
|
||||
}
|
||||
if app.Key == "openresty" {
|
||||
if err = handleSiteDir(app, appDetail, &req, t); err != nil {
|
||||
if err = handleSiteDir(app, appDetail, req, t); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = handleOpenrestyFile(appInstall); err != nil {
|
||||
|
|
|
|||
|
|
@ -1163,7 +1163,11 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error
|
|||
appInstall.Message = errMsg + errOur
|
||||
installErr := errors.New(appInstall.Message)
|
||||
task.LogFailedWithErr(i18n.GetMsgByKey("PullImage"), installErr)
|
||||
return installErr
|
||||
if exist, _ := dockerCLi.ImageExists(image); !exist {
|
||||
return installErr
|
||||
} else {
|
||||
task.Log(i18n.GetMsgByKey("UseExistImage"))
|
||||
}
|
||||
} else {
|
||||
task.Log(i18n.GetMsgByKey("PullImageSuccess"))
|
||||
}
|
||||
|
|
@ -1939,7 +1943,7 @@ func getAppTags(appID uint, lang string) ([]response.TagDTO, error) {
|
|||
return res, nil
|
||||
}
|
||||
|
||||
func handleSiteDir(app model.App, appDetail model.AppDetail, req *request.AppInstallCreate, t *task.Task) error {
|
||||
func handleSiteDir(app model.App, appDetail model.AppDetail, req request.AppInstallCreate, t *task.Task) error {
|
||||
if app.Key == "openresty" && (app.Resource == "remote" || app.Resource == "custom") && common.CompareVersion(appDetail.Version, "1.27") {
|
||||
if dir, ok := req.Params["WEBSITE_DIR"]; ok {
|
||||
siteDir := dir.(string)
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ ErrCustomRuntimes: 'There is an installed runtime environment, please delete it
|
|||
ErrAppVersionDeprecated: "The {{ .name }} application is not compatible with the current 1Panel version, skipped"
|
||||
ErrDockerFailed: "The state of Docker is abnormal, please check the service status"
|
||||
ErrDockerComposeCmdNotFound: "The Docker Compose command does not exist, please install this command on the host machine first"
|
||||
UseExistImage: 'Failed to pull image, using existing image'
|
||||
|
||||
#ssh
|
||||
ExportIP: "Login IP"
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ ErrCustomRuntimes: 'Hay un entorno de ejecución instalado, elimínelo primero'
|
|||
ErrAppVersionDeprecated: "La aplicación {{ .name }} no es compatible con la versión actual de 1Panel, omitida"
|
||||
ErrDockerFailed: "El estado de Docker es anómalo, revise el servicio"
|
||||
ErrDockerComposeCmdNotFound: "El comando Docker Compose no existe, por favor instálelo primero en el host"
|
||||
UseExistImage: 'Error al extraer la imagen, usando imagen existente'
|
||||
|
||||
#ssh
|
||||
ExportIP: "IP de inicio de sesión"
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ ErrCustomRuntimes: 'ランタイム環境がインストールされています
|
|||
ErrAppVersionDeprecated: "{{ .name }} アプリケーションは現在の 1Panel バージョンと互換性がありません、スキップしました"
|
||||
ErrDockerFailed: "Docker の状態が異常です。サービス状態を確認してください"
|
||||
ErrDockerComposeCmdNotFound: "Docker Compose コマンドは存在しません。ホストマシンにこのコマンドを先にインストールしてください"
|
||||
UseExistImage: 'イメージのプルに失敗しました、既存のイメージを使用します'
|
||||
|
||||
#ssh
|
||||
ExportIP: "ログインIP"
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ ErrCustomRuntimes: '설치된 런타임 환경이 있습니다. 먼저 삭제해
|
|||
ErrAppVersionDeprecated: "{{ .name }} 응용 프로그램은 현재 1Panel 버전과 호환되지 않아 건너뛰었습니다"
|
||||
ErrDockerFailed: "Docker의 상태가 비정상입니다. 서비스 상태를 확인하세요"
|
||||
ErrDockerComposeCmdNotFound: "Docker Compose 명령이 없습니다. 호스트 머신에 먼저 이 명령을 설치하세요"
|
||||
UseExistImage: '이미지 가져오기 실패, 기존 이미지 사용'
|
||||
|
||||
#ssh
|
||||
ExportIP: "로그인 IP"
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ ErrCustomRuntimes: 'Terdapat persekitaran masa jalan yang dipasang, sila padamka
|
|||
ErrAppVersionDeprecated: "Aplikasi {{ .name }} tidak sesuai dengan versi 1Panel saat ini, dilewati"
|
||||
ErrDockerFailed: "Keadaan Docker tidak normal, sila periksa status perkhidmatan"
|
||||
ErrDockerComposeCmdNotFound: "Perintah Docker Compose tidak wujud, sila pasang perintah ini di mesin tuan terlebih dahulu"
|
||||
UseExistImage: 'Gagal menarik imej, menggunakan imej sedia ada'
|
||||
|
||||
#ssh
|
||||
ExportIP: "IP Log Masuk"
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ ErrCustomRuntimes: 'Há um ambiente de execução instalado, exclua-o primeiro'
|
|||
ErrAppVersionDeprecated: "O aplicativo {{ .name }} não é compatível com a versão atual do 1Panel, ignorado"
|
||||
ErrDockerFailed: "O estado do Docker está anormal, verifique o status do serviço"
|
||||
ErrDockerComposeCmdNotFound: "O comando Docker Compose não existe, por favor, instale este comando na máquina host primeiro"
|
||||
UseExistImage: 'Falha ao puxar a imagem, usando imagem existente'
|
||||
|
||||
#ssh
|
||||
ExportIP: "IP de Login"
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ ErrCustomRuntimes: 'Установлена среда выполнения. Сн
|
|||
ErrAppVersionDeprecated: "Приложение {{ .name }} несовместимо с текущей версией 1Panel, пропущено"
|
||||
ErrDockerFailed: "Состояние Docker аномально, проверьте состояние сервиса"
|
||||
ErrDockerComposeCmdNotFound: "Команда Docker Compose отсутствует, пожалуйста, установите эту команду на хост-машине сначала"
|
||||
UseExistImage: 'Не удалось загрузить образ, используется существующий образ'
|
||||
|
||||
#ssh
|
||||
ExportIP: "IP входа"
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ ErrCustomRuntimes: 'Yüklü bir çalışma ortamı var, lütfen önce silin'
|
|||
ErrAppVersionDeprecated: "{{ .name }} uygulaması mevcut 1Panel sürümü ile uyumlu değil, atlandı"
|
||||
ErrDockerFailed: "Docker durumu anormal, lütfen servis durumunu kontrol edin"
|
||||
ErrDockerComposeCmdNotFound: "Docker Compose komutu mevcut değil, lütfen önce bu komutu host makinesine yükleyin"
|
||||
UseExistImage: 'Görüntü çekme başarısız, mevcut görüntü kullanılıyor'
|
||||
|
||||
#ssh
|
||||
ExportIP: "Giriş IP"
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ ErrCustomRuntimes: '存在已安裝的運作環境,請先刪除'
|
|||
ErrAppVersionDeprecated: "{{ .name }} 應用不適配目前 1Panel 版本,跳過"
|
||||
ErrDockerFailed: "Docker 狀態異常,請檢查服務狀態"
|
||||
ErrDockerComposeCmdNotFound: "Docker Compose 指令不存在,請先在宿主機安裝此指令"
|
||||
UseExistImage: '拉取映像失敗,使用存量映像'
|
||||
|
||||
#ssh
|
||||
ExportIP: "登入IP"
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ ErrCustomRuntimes: "存在已经安装的运行环境,请先删除"
|
|||
ErrAppVersionDeprecated: " {{ .name }} 应用不适配当前 1Panel 版本,跳过"
|
||||
ErrDockerFailed: "Docker 状态异常,请检查服务状态"
|
||||
ErrDockerComposeCmdNotFound: "Docker Compose 命令不存在,请先在宿主机安装此命令"
|
||||
UseExistImage: "拉取镜像失败,使用存量镜像"
|
||||
|
||||
#ssh
|
||||
ExportIP: "登录 IP"
|
||||
|
|
|
|||
|
|
@ -115,6 +115,13 @@ func (c Client) DeleteImage(imageID string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func (c Client) ImageExists(imageID string) (bool, error) {
|
||||
_, err := c.cli.ImageInspect(context.Background(), imageID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (c Client) GetImageIDByName(imageName string) (string, error) {
|
||||
filter := filters.NewArgs()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue