Creating new apps from snapshots support
continuous-integration/drone/push Build is passing Details

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"`
// Disk usage in 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

View File

@ -195,6 +195,31 @@ func createEventHandler(m *nats.Msg, message *RequestMessage) error {
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()
if err != nil {
log.Println("ERROR create application problem: " + err.Error())