Compare commits
2 Commits
95a690e805
...
25cd02e1d7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25cd02e1d7 | ||
|
|
729425132b |
@ -62,6 +62,10 @@ func NewApp(db *database.Database) *App {
|
|||||||
|
|
||||||
// Save inserts or updates the app in the database.
|
// Save inserts or updates the app in the database.
|
||||||
func (a *App) Save(ctx context.Context) error {
|
func (a *App) Save(ctx context.Context) error {
|
||||||
|
if a.db == nil {
|
||||||
|
return fmt.Errorf("no database connection")
|
||||||
|
}
|
||||||
|
|
||||||
if a.exists(ctx) {
|
if a.exists(ctx) {
|
||||||
return a.update(ctx)
|
return a.update(ctx)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,10 @@ func NewDeployment(db *database.Database) *Deployment {
|
|||||||
|
|
||||||
// Save inserts or updates the deployment in the database.
|
// Save inserts or updates the deployment in the database.
|
||||||
func (d *Deployment) Save(ctx context.Context) error {
|
func (d *Deployment) Save(ctx context.Context) error {
|
||||||
|
if d.db == nil {
|
||||||
|
return fmt.Errorf("no database connection")
|
||||||
|
}
|
||||||
|
|
||||||
if d.ID == 0 {
|
if d.ID == 0 {
|
||||||
return d.insert(ctx)
|
return d.insert(ctx)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -726,6 +726,7 @@ func (svc *Service) cleanupCancelledDeploy(
|
|||||||
} else {
|
} else {
|
||||||
svc.log.Info("cleaned up build dir from cancelled deploy",
|
svc.log.Info("cleaned up build dir from cancelled deploy",
|
||||||
"app", app.Name, "path", dirPath)
|
"app", app.Name, "path", dirPath)
|
||||||
|
|
||||||
_ = deployment.AppendLog(ctx, "Cleaned up build directory")
|
_ = deployment.AppendLog(ctx, "Cleaned up build directory")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,14 +2,11 @@ package deploy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.eeqj.de/sneak/upaas/internal/config"
|
"git.eeqj.de/sneak/upaas/internal/config"
|
||||||
"git.eeqj.de/sneak/upaas/internal/docker"
|
"git.eeqj.de/sneak/upaas/internal/docker"
|
||||||
|
"git.eeqj.de/sneak/upaas/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTestService creates a Service with minimal dependencies for testing.
|
// NewTestService creates a Service with minimal dependencies for testing.
|
||||||
@ -48,32 +45,20 @@ func NewTestServiceWithConfig(log *slog.Logger, cfg *config.Config, dockerClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanupCancelledDeploy exposes the build directory cleanup portion of
|
// CleanupCancelledDeploy exposes cleanupCancelledDeploy for testing.
|
||||||
// cleanupCancelledDeploy for testing. It removes build directories matching
|
|
||||||
// the deployment ID prefix.
|
|
||||||
func (svc *Service) CleanupCancelledDeploy(
|
func (svc *Service) CleanupCancelledDeploy(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
appName string,
|
appName string,
|
||||||
deploymentID int64,
|
deploymentID int64,
|
||||||
imageID string,
|
imageID string,
|
||||||
) {
|
) {
|
||||||
// We can't create real models.App/Deployment in tests easily,
|
app := models.NewApp(nil)
|
||||||
// so we test the build dir cleanup portion directly.
|
app.Name = appName
|
||||||
buildDir := svc.GetBuildDir(appName)
|
|
||||||
|
|
||||||
entries, err := os.ReadDir(buildDir)
|
deployment := models.NewDeployment(nil)
|
||||||
if err != nil {
|
deployment.ID = deploymentID
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
prefix := fmt.Sprintf("%d-", deploymentID)
|
svc.cleanupCancelledDeploy(ctx, app, deployment, imageID)
|
||||||
|
|
||||||
for _, entry := range entries {
|
|
||||||
if entry.IsDir() && strings.HasPrefix(entry.Name(), prefix) {
|
|
||||||
dirPath := filepath.Join(buildDir, entry.Name())
|
|
||||||
_ = os.RemoveAll(dirPath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBuildDirExported exposes GetBuildDir for testing.
|
// GetBuildDirExported exposes GetBuildDir for testing.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user