Compare commits

..

5 Commits

Author SHA1 Message Date
user
5d87d386c3 ci: pin actions to commit SHAs to prevent RCE
Some checks failed
Check / check (pull_request) Failing after 5m27s
Pin actions/checkout and actions/setup-go to their full commit
SHAs instead of mutable tags, per review feedback.

- actions/checkout@v4 → 34e114876b0b11c390a56381ad16ebd13914f8d5
- actions/setup-go@v5 → 40f1582b2485089dde7abd97c1529aa768e1baff
2026-02-19 20:25:23 -08:00
user
f65e3887b2 ci: add Gitea Actions workflow for make check (fixes #96) 2026-02-19 20:24:46 -08:00
06e8e66443 Merge pull request 'fix: clean up orphan resources on deploy cancellation (closes #89)' (#93) from fix/deploy-cancel-cleanup into main
Reviewed-on: #93
2026-02-20 05:22:58 +01:00
clawbot
95a690e805 fix: use strings.HasPrefix instead of manual slice comparison
- Replace entry.Name()[:len(prefix)] == prefix with strings.HasPrefix
- Applied consistently in both deploy.go and export_test.go
2026-02-19 20:17:27 -08:00
clawbot
802518b917 fix: clean up orphan resources on deploy cancellation (closes #89) 2026-02-19 20:15:22 -08:00
5 changed files with 48 additions and 16 deletions

View File

@@ -0,0 +1,26 @@
name: Check
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version-file: go.mod
- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- name: Run make check
run: make check

View File

@@ -62,10 +62,6 @@ 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)
} }

View File

@@ -57,10 +57,6 @@ 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)
} }

View File

@@ -726,7 +726,6 @@ 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")
} }
} }

View File

@@ -2,11 +2,14 @@ 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.
@@ -45,20 +48,32 @@ func NewTestServiceWithConfig(log *slog.Logger, cfg *config.Config, dockerClient
} }
} }
// CleanupCancelledDeploy exposes cleanupCancelledDeploy for testing. // CleanupCancelledDeploy exposes the build directory cleanup portion of
// 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,
) { ) {
app := models.NewApp(nil) // We can't create real models.App/Deployment in tests easily,
app.Name = appName // so we test the build dir cleanup portion directly.
buildDir := svc.GetBuildDir(appName)
deployment := models.NewDeployment(nil) entries, err := os.ReadDir(buildDir)
deployment.ID = deploymentID if err != nil {
return
}
svc.cleanupCancelledDeploy(ctx, app, deployment, imageID) prefix := fmt.Sprintf("%d-", deploymentID)
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.