Set password, ssh keys and tech in single step during create
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Adam Štrauch 2023-02-04 10:33:47 +01:00
parent d469c813a1
commit 779d9ba95a
Signed by: cx
GPG Key ID: 018304FFA8988F8D
2 changed files with 44 additions and 10 deletions

View File

@ -101,6 +101,14 @@ type App struct {
// This is not store in the database but used in create request when the app suppose to be created from an existing snapshot
Snapshot string `json:"snapshot" gorm:"-"`
// Fields to setup during creating of the app, this is not stored in the database
Setup struct {
SSHKeys string `json:"ssh_keys"`
Tech string `json:"tech"`
TechVersion string `json:"tech_version"`
Password string `json:"password"`
} `json:"setup,omitempty" gorm:"-"`
}
// Validate do basic checks of the struct values

View File

@ -227,30 +227,56 @@ func (p *Processor) Create(appTemplate apps.App) error {
// Restore the data
err = p.SnapshotProcessor.RestoreSnapshot(appTemplate.Snapshot, appTemplate.Name)
if err != nil {
return err
return fmt.Errorf("failed to restore snapshot: %v", err)
}
}
// Wait for the app to be created
err = p.waitForApp()
if err != nil {
return fmt.Errorf("failed to wait for app: %v", err)
}
time.Sleep(5 * time.Second) // We wait for a little bit longer to make sure the container is fully started
// Setup SSH keys if it's noted in the request
if len(appTemplate.Setup.SSHKeys) > 0 && len(appTemplate.Snapshot) == 0 {
err = p.UpdateKeys(appTemplate.Setup.SSHKeys)
if err != nil {
return fmt.Errorf("failed to update keys: %v", err)
}
}
// Setup technology if it's noted in the request
if len(appTemplate.Setup.Tech) > 0 && len(appTemplate.Snapshot) == 0 {
err = p.EnableTech(appTemplate.Setup.Tech, appTemplate.Setup.TechVersion)
if err != nil {
return fmt.Errorf("failed to enable tech: %v", err)
}
}
// Set password if it's noted in the request
if len(appTemplate.Setup.Password) > 0 && len(appTemplate.Snapshot) == 0 {
err = p.SetPassword(appTemplate.Setup.Password)
if err != nil {
return fmt.Errorf("failed to set password: %v", err)
}
}
// Changes port of the app hosted inside the container
if appTemplate.AppPort != 0 {
err = p.waitForApp()
if err != nil {
return err
}
if appTemplate.AppPort != 0 && len(appTemplate.Snapshot) == 0 {
err = container.SetAppPort(appTemplate.AppPort)
if err != nil {
return err
return fmt.Errorf("failed to change app port to %d: %v", appTemplate.AppPort, err)
}
err = container.RestartProcess("nginx")
if err != nil {
return err
return fmt.Errorf("failed to restart nginx: %v", err)
}
}
err = container.Start()
return err
return fmt.Errorf("failed to start container: %v", err)
}
// Register registers app without creating a container for it