Creating new apps from snapshots support
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adam Štrauch 2021-10-31 02:29:58 +02:00
parent 7616eef12b
commit 1a107e2a28
Signed by: cx
GPG Key ID: 018304FFA8988F8D
2 changed files with 28 additions and 0 deletions

View File

@ -83,6 +83,9 @@ type App struct {
DiskUsageBytes int `json:"disk_usage_bytes"` DiskUsageBytes int `json:"disk_usage_bytes"`
// Disk usage in inodes // Disk usage in inodes
DiskUsageInodes int `json:"disk_usage_inodes"` DiskUsageInodes int `json:"disk_usage_inodes"`
// 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:"-"`
} }
// Validate do basic checks of the struct values // Validate do basic checks of the struct values

View File

@ -195,6 +195,31 @@ func createEventHandler(m *nats.Msg, message *RequestMessage) error {
return err return err
} }
// Restore from snapshot if it's noted in the request
if len(appTemplate.Snapshot) > 0 {
// Setup processors
snapshotProcessor := apps.SnapshotProcessor{
AppsPath: config.AppsPath,
TmpSnapshotPath: config.SnapshotsPath,
Driver: drivers.S3Driver{
S3AccessKey: config.SnapshotsS3AccessKey,
S3SecretKey: config.SnapshotsS3SecretKey,
S3Endpoint: config.SnapshotsS3Endpoint,
S3SSL: config.SnapshotsS3SSL,
Bucket: config.SnapshotsS3Bucket,
},
}
// Restore the data
err = snapshotProcessor.RestoreSnapshot(appTemplate.Snapshot, message.AppName)
if err != nil {
log.Println("ERROR restore snapshot error: " + err.Error())
publish(message.AppName, "backend problem", true)
return err
}
}
err = container.Start() err = container.Start()
if err != nil { if err != nil {
log.Println("ERROR create application problem: " + err.Error()) log.Println("ERROR create application problem: " + err.Error())