|
|
@ -84,8 +84,11 @@ func (u *ImageRepoService) Create(req dto.ImageRepoCreate) error {
|
|
|
|
if imageRepo.ID != 0 {
|
|
|
|
if imageRepo.ID != 0 {
|
|
|
|
return constant.ErrRecordExist
|
|
|
|
return constant.ErrRecordExist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if req.Protocol == "http" {
|
|
|
|
if req.Protocol == "http" {
|
|
|
|
_ = u.handleRegistries(req.DownloadUrl, "", "create")
|
|
|
|
if err := u.handleRegistries(req.DownloadUrl, "", "create"); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("create registry %s failed, err: %v", req.DownloadUrl, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
if err := validateDockerConfig(); err != nil {
|
|
|
|
if err := validateDockerConfig(); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -114,23 +117,18 @@ func (u *ImageRepoService) Create(req dto.ImageRepoCreate) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := copier.Copy(&imageRepo, &req); err != nil {
|
|
|
|
|
|
|
|
return errors.WithMessage(constant.ErrStructTransform, err.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imageRepo.Status = constant.StatusSuccess
|
|
|
|
|
|
|
|
if req.Auth {
|
|
|
|
if req.Auth {
|
|
|
|
if err := u.CheckConn(req.DownloadUrl, req.Username, req.Password); err != nil {
|
|
|
|
if err := u.CheckConn(req.DownloadUrl, req.Username, req.Password); err != nil {
|
|
|
|
imageRepo.Status = constant.StatusFailed
|
|
|
|
return err
|
|
|
|
imageRepo.Message = err.Error()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := imageRepoRepo.Create(&imageRepo); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
if err := copier.Copy(&imageRepo, &req); err != nil {
|
|
|
|
|
|
|
|
return errors.WithMessage(constant.ErrStructTransform, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
imageRepo.Status = constant.StatusSuccess
|
|
|
|
|
|
|
|
return imageRepoRepo.Create(&imageRepo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (u *ImageRepoService) BatchDelete(req dto.ImageRepoDelete) error {
|
|
|
|
func (u *ImageRepoService) BatchDelete(req dto.ImageRepoDelete) error {
|
|
|
@ -156,33 +154,47 @@ func (u *ImageRepoService) Update(req dto.ImageRepoUpdate) error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if repo.DownloadUrl != req.DownloadUrl || (!repo.Auth && req.Auth) {
|
|
|
|
if repo.Protocol == "http" && req.Protocol == "https" {
|
|
|
|
_ = u.handleRegistries(req.DownloadUrl, repo.DownloadUrl, "update")
|
|
|
|
if err := u.handleRegistries("", repo.DownloadUrl, "delete"); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("delete registry %s failed, err: %v", repo.DownloadUrl, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if repo.Protocol == "http" && req.Protocol == "http" {
|
|
|
|
|
|
|
|
if err := u.handleRegistries(req.DownloadUrl, repo.DownloadUrl, "update"); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("update registry %s => %s failed, err: %v", repo.DownloadUrl, req.DownloadUrl, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if repo.Protocol == "https" && req.Protocol == "http" {
|
|
|
|
|
|
|
|
if err := u.handleRegistries(req.DownloadUrl, "", "create"); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("create registry %s failed, err: %v", req.DownloadUrl, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if repo.Auth != req.Auth || repo.DownloadUrl != req.DownloadUrl {
|
|
|
|
if repo.Auth {
|
|
|
|
if repo.Auth {
|
|
|
|
_, _ = cmd.ExecWithCheck("docker", "logout", repo.DownloadUrl)
|
|
|
|
_, _ = cmd.ExecWithCheck("docker", "logout", repo.DownloadUrl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := validateDockerConfig(); err != nil {
|
|
|
|
if req.Auth {
|
|
|
|
return err
|
|
|
|
if err := u.CheckConn(req.DownloadUrl, req.Username, req.Password); err != nil {
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
if err := restartDocker(); err != nil {
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := validateDockerConfig(); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := restartDocker(); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
upMap := make(map[string]interface{})
|
|
|
|
upMap := make(map[string]interface{})
|
|
|
|
upMap["download_url"] = req.DownloadUrl
|
|
|
|
upMap["download_url"] = req.DownloadUrl
|
|
|
|
upMap["protocol"] = req.Protocol
|
|
|
|
upMap["protocol"] = req.Protocol
|
|
|
|
upMap["username"] = req.Username
|
|
|
|
upMap["username"] = req.Username
|
|
|
|
upMap["password"] = req.Password
|
|
|
|
upMap["password"] = req.Password
|
|
|
|
upMap["auth"] = req.Auth
|
|
|
|
upMap["auth"] = req.Auth
|
|
|
|
|
|
|
|
|
|
|
|
upMap["status"] = constant.StatusSuccess
|
|
|
|
upMap["status"] = constant.StatusSuccess
|
|
|
|
upMap["message"] = ""
|
|
|
|
upMap["message"] = ""
|
|
|
|
if req.Auth {
|
|
|
|
|
|
|
|
if err := u.CheckConn(req.DownloadUrl, req.Username, req.Password); err != nil {
|
|
|
|
|
|
|
|
upMap["status"] = constant.StatusFailed
|
|
|
|
|
|
|
|
upMap["message"] = err.Error()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return imageRepoRepo.Update(req.ID, upMap)
|
|
|
|
return imageRepoRepo.Update(req.ID, upMap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|