Compare commits
2 Commits
edc06aa181
...
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.
|
||||
func (a *App) Save(ctx context.Context) error {
|
||||
if a.db == nil {
|
||||
return fmt.Errorf("no database connection")
|
||||
}
|
||||
|
||||
if a.exists(ctx) {
|
||||
return a.update(ctx)
|
||||
}
|
||||
|
||||
@ -57,6 +57,10 @@ func NewDeployment(db *database.Database) *Deployment {
|
||||
|
||||
// Save inserts or updates the deployment in the database.
|
||||
func (d *Deployment) Save(ctx context.Context) error {
|
||||
if d.db == nil {
|
||||
return fmt.Errorf("no database connection")
|
||||
}
|
||||
|
||||
if d.ID == 0 {
|
||||
return d.insert(ctx)
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -715,7 +716,7 @@ func (svc *Service) cleanupCancelledDeploy(
|
||||
prefix := fmt.Sprintf("%d-", deployment.ID)
|
||||
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() && len(entry.Name()) > len(prefix) && entry.Name()[:len(prefix)] == prefix {
|
||||
if entry.IsDir() && strings.HasPrefix(entry.Name(), prefix) {
|
||||
dirPath := filepath.Join(buildDir, entry.Name())
|
||||
|
||||
removeErr := os.RemoveAll(dirPath)
|
||||
@ -725,6 +726,7 @@ func (svc *Service) cleanupCancelledDeploy(
|
||||
} else {
|
||||
svc.log.Info("cleaned up build dir from cancelled deploy",
|
||||
"app", app.Name, "path", dirPath)
|
||||
|
||||
_ = deployment.AppendLog(ctx, "Cleaned up build directory")
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,13 +2,11 @@ package deploy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.eeqj.de/sneak/upaas/internal/config"
|
||||
"git.eeqj.de/sneak/upaas/internal/docker"
|
||||
"git.eeqj.de/sneak/upaas/internal/models"
|
||||
)
|
||||
|
||||
// NewTestService creates a Service with minimal dependencies for testing.
|
||||
@ -54,23 +52,13 @@ func (svc *Service) CleanupCancelledDeploy(
|
||||
deploymentID int64,
|
||||
imageID string,
|
||||
) {
|
||||
// We can't create real models.App/Deployment in tests easily,
|
||||
// so we test the build dir cleanup portion directly.
|
||||
buildDir := svc.GetBuildDir(appName)
|
||||
app := models.NewApp(nil)
|
||||
app.Name = appName
|
||||
|
||||
entries, err := os.ReadDir(buildDir)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
deployment := models.NewDeployment(nil)
|
||||
deployment.ID = deploymentID
|
||||
|
||||
prefix := fmt.Sprintf("%d-", deploymentID)
|
||||
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() && len(entry.Name()) > len(prefix) && entry.Name()[:len(prefix)] == prefix {
|
||||
dirPath := filepath.Join(buildDir, entry.Name())
|
||||
_ = os.RemoveAll(dirPath)
|
||||
}
|
||||
}
|
||||
svc.cleanupCancelledDeploy(ctx, app, deployment, imageID)
|
||||
}
|
||||
|
||||
// GetBuildDirExported exposes GetBuildDir for testing.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user