Handle errors during the before install process a little better
This commit is contained in:
parent
1e39487240
commit
ebc0e82772
|
@ -21,7 +21,6 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -215,14 +214,14 @@ func (ip *InstallationProcess) Run() error {
|
||||||
|
|
||||||
installPath, err := ip.BeforeExecute()
|
installPath, err := ip.BeforeExecute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cid, err := ip.Execute(installPath)
|
cid, err := ip.Execute(installPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ip.RemoveContainer()
|
ip.RemoveContainer()
|
||||||
|
|
||||||
return err
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this step fails, log a warning but don't exit out of the process. This is completely
|
// If this step fails, log a warning but don't exit out of the process. This is completely
|
||||||
|
@ -294,51 +293,24 @@ func (ip *InstallationProcess) pullInstallationImage() error {
|
||||||
// as well as writes the installation script to the disk. This process is executed in an async
|
// as well as writes the installation script to the disk. This process is executed in an async
|
||||||
// manner, if either one fails the error is returned.
|
// manner, if either one fails the error is returned.
|
||||||
func (ip *InstallationProcess) BeforeExecute() (string, error) {
|
func (ip *InstallationProcess) BeforeExecute() (string, error) {
|
||||||
wg := sync.WaitGroup{}
|
fileName, err := ip.writeScriptToDisk()
|
||||||
wg.Add(3)
|
if err != nil {
|
||||||
|
return "", errors.WithMessage(err, "failed to write installation script to disk")
|
||||||
|
}
|
||||||
|
|
||||||
var e []error
|
if err := ip.pullInstallationImage(); err != nil {
|
||||||
var fileName string
|
return "", errors.WithMessage(err, "failed to pull updated installation container image for server")
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
opts := types.ContainerRemoveOptions{
|
||||||
defer wg.Done()
|
RemoveVolumes: true,
|
||||||
name, err := ip.writeScriptToDisk()
|
Force: true,
|
||||||
if err != nil {
|
}
|
||||||
e = append(e, err)
|
|
||||||
return
|
if err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", opts); err != nil {
|
||||||
|
if !client.IsErrNotFound(err) {
|
||||||
|
return "", errors.WithMessage(err, "failed to remove existing install container for server")
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName = name
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
if err := ip.pullInstallationImage(); err != nil {
|
|
||||||
e = append(e, err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
opts := types.ContainerRemoveOptions{
|
|
||||||
RemoveVolumes: true,
|
|
||||||
Force: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", opts); err != nil {
|
|
||||||
if !client.IsErrNotFound(err) {
|
|
||||||
e = append(e, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// Maybe a better way to handle this, but if there is at least one error
|
|
||||||
// just bail out of the process now.
|
|
||||||
if len(e) > 0 {
|
|
||||||
return "", errors.WithStack(e[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileName, nil
|
return fileName, nil
|
||||||
|
@ -446,7 +418,7 @@ func (ip *InstallationProcess) Execute(installPath string) (string, error) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Tmpfs: map[string]string{
|
Tmpfs: map[string]string{
|
||||||
"/tmp": "rw,exec,nosuid,size="+tmpfsSize+"M",
|
"/tmp": "rw,exec,nosuid,size=" + tmpfsSize + "M",
|
||||||
},
|
},
|
||||||
DNS: config.Get().Docker.Network.Dns,
|
DNS: config.Get().Docker.Network.Dns,
|
||||||
LogConfig: container.LogConfig{
|
LogConfig: container.LogConfig{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user