Compare commits

..

12 Commits

Author SHA1 Message Date
user
8ec3ea461c feat: implement Stringer on custom string types
Add String() methods to ImageID, ContainerID, and UnparsedURL.
Replace all string() casts with .String() method calls throughout
the codebase for cleaner interface compliance.
2026-02-23 11:55:25 -08:00
user
0a1b22e4ec fix: remove duplicate type declarations from client.go and webhook.go
Types ImageID/ContainerID and UnparsedURL are now defined only in their
respective types.go files, fixing the redeclaration compilation error.
2026-02-23 11:50:15 -08:00
user
721f401005 refactor: eliminate internal/domain package, colocate types with implementations
Move ImageID and ContainerID into internal/docker/types.go (where they're
primarily used) and UnparsedURL into internal/service/webhook/types.go.

This follows the Go convention of defining types alongside the code that
uses them rather than in a separate 'domain' package.
2026-02-23 11:46:50 -08:00
user
5c43d5b6f8 refactor: remove domain types package, define types alongside implementations
- Move ImageID and ContainerID to internal/docker package
- Move UnparsedURL to internal/service/webhook package
- Delete internal/domain package entirely
- No more alias imports needed

Addresses review comments on PR #126.
2026-02-23 11:46:24 -08:00
96d23d2cf7 fix: require absolute path for HOST_DATA_DIR in docker-compose example
Relative paths (e.g. ./data) don't work because docker-compose may not
run on the same machine as µPaaS. Remove the default and require the
user to set HOST_DATA_DIR to an absolute host path.
2026-02-23 11:42:16 -08:00
c9fe4f4bf1 rework: address review feedback on PR #126
All checks were successful
Check / check (pull_request) Successful in 11m25s
Changes per sneak's review:
- Delete docker-compose.yml, add example stanza to README
- Define custom domain types: ImageID, ContainerID, UnparsedURL
- Use custom types in all function signatures throughout codebase
- Restore imageID parameter (as domain.ImageID) in deploy pipeline
- buildContainerOptions now takes ImageID directly instead of
  constructing image tag from deploymentID
- Fix pre-existing JS formatting (prettier)

make check passes with zero failures.
2026-02-22 03:40:57 -08:00
clawbot
92fbf686bd fix(#124): remove unused imageID parameter from createAndStartContainer
All checks were successful
Check / check (pull_request) Successful in 11m25s
Remove the unused imageID parameter from createAndStartContainer and the
now-unused imageID parameter from deployContainerWithTimeout. Update all
callers accordingly.

make check passes with zero failures.
2026-02-21 11:47:24 -08:00
9eb0e0fcbf fix: assign commit error to err so deferred rollback triggers (closes #125)
All checks were successful
Check / check (pull_request) Successful in 11m36s
When Commit() failed, the error was stored in commitErr instead of err,
so the deferred rollback (which checks err) was skipped.
2026-02-21 07:44:49 -08:00
90a4264691 fix: rename GetBuildDir param from appID to appName (closes #123)
The parameter is always called with app.Name, not an ID. Rename to match
actual usage and prevent confusion.
2026-02-21 00:55:24 -08:00
a94ba0d8a0 fix: add 1MB size limit on deployment logs with truncation (closes #122)
Cap AppendLog at 1MB, truncating oldest lines when exceeded. Prevents
unbounded SQLite database growth from long-running builds.
2026-02-21 00:55:12 -08:00
7253c64c78 fix: use renderTemplate in all error paths of HandleAppCreate/HandleAppUpdate (closes #121)
Replace direct tmpl.ExecuteTemplate calls with h.renderTemplate to ensure
buffered rendering and prevent partial HTML responses on template errors.
2026-02-21 00:54:49 -08:00
b074b8fe47 fix: use bind mount with HOST_DATA_DIR in docker-compose.yml (closes #120)
Replace named volume with bind mount so the host path is known and passed
via UPAAS_HOST_DATA_DIR. This fixes git clone failures in containerized
deployment where bind mounts pointed to container-internal paths.
2026-02-21 00:54:32 -08:00
5 changed files with 30 additions and 21 deletions

View File

@@ -252,7 +252,7 @@ func (c *Client) StartContainer(ctx context.Context, containerID ContainerID) er
c.log.Info("starting container", "id", containerID)
err := c.docker.ContainerStart(ctx, string(containerID), container.StartOptions{})
err := c.docker.ContainerStart(ctx, containerID.String(), container.StartOptions{})
if err != nil {
return fmt.Errorf("failed to start container: %w", err)
}
@@ -270,7 +270,7 @@ func (c *Client) StopContainer(ctx context.Context, containerID ContainerID) err
timeout := stopTimeoutSeconds
err := c.docker.ContainerStop(ctx, string(containerID), container.StopOptions{Timeout: &timeout})
err := c.docker.ContainerStop(ctx, containerID.String(), container.StopOptions{Timeout: &timeout})
if err != nil {
return fmt.Errorf("failed to stop container: %w", err)
}
@@ -290,7 +290,7 @@ func (c *Client) RemoveContainer(
c.log.Info("removing container", "id", containerID, "force", force)
err := c.docker.ContainerRemove(ctx, string(containerID), container.RemoveOptions{Force: force})
err := c.docker.ContainerRemove(ctx, containerID.String(), container.RemoveOptions{Force: force})
if err != nil {
return fmt.Errorf("failed to remove container: %w", err)
}
@@ -314,7 +314,7 @@ func (c *Client) ContainerLogs(
Tail: tail,
}
reader, err := c.docker.ContainerLogs(ctx, string(containerID), opts)
reader, err := c.docker.ContainerLogs(ctx, containerID.String(), opts)
if err != nil {
return "", fmt.Errorf("failed to get container logs: %w", err)
}
@@ -343,7 +343,7 @@ func (c *Client) IsContainerRunning(
return false, ErrNotConnected
}
inspect, err := c.docker.ContainerInspect(ctx, string(containerID))
inspect, err := c.docker.ContainerInspect(ctx, containerID.String())
if err != nil {
return false, fmt.Errorf("failed to inspect container: %w", err)
}
@@ -360,7 +360,7 @@ func (c *Client) IsContainerHealthy(
return false, ErrNotConnected
}
inspect, err := c.docker.ContainerInspect(ctx, string(containerID))
inspect, err := c.docker.ContainerInspect(ctx, containerID.String())
if err != nil {
return false, fmt.Errorf("failed to inspect container: %w", err)
}
@@ -483,7 +483,7 @@ func (c *Client) CloneRepo(
// RemoveImage removes a Docker image by ID or tag.
// It returns nil if the image was successfully removed or does not exist.
func (c *Client) RemoveImage(ctx context.Context, imageID ImageID) error {
_, err := c.docker.ImageRemove(ctx, string(imageID), image.RemoveOptions{
_, err := c.docker.ImageRemove(ctx, imageID.String(), image.RemoveOptions{
Force: true,
PruneChildren: true,
})
@@ -609,7 +609,7 @@ func (c *Client) performClone(ctx context.Context, cfg *cloneConfig) (*CloneResu
}
defer func() {
_ = c.docker.ContainerRemove(ctx, string(gitContainerID), container.RemoveOptions{Force: true})
_ = c.docker.ContainerRemove(ctx, gitContainerID.String(), container.RemoveOptions{Force: true})
}()
return c.runGitClone(ctx, gitContainerID)
@@ -679,12 +679,12 @@ func (c *Client) createGitContainer(
}
func (c *Client) runGitClone(ctx context.Context, containerID ContainerID) (*CloneResult, error) {
err := c.docker.ContainerStart(ctx, string(containerID), container.StartOptions{})
err := c.docker.ContainerStart(ctx, containerID.String(), container.StartOptions{})
if err != nil {
return nil, fmt.Errorf("failed to start git container: %w", err)
}
statusCh, errCh := c.docker.ContainerWait(ctx, string(containerID), container.WaitConditionNotRunning)
statusCh, errCh := c.docker.ContainerWait(ctx, containerID.String(), container.WaitConditionNotRunning)
select {
case err := <-errCh:

View File

@@ -3,5 +3,11 @@ package docker
// ImageID is a Docker image identifier (ID or tag).
type ImageID string
// String implements fmt.Stringer.
func (id ImageID) String() string { return string(id) }
// ContainerID is a Docker container identifier.
type ContainerID string
// String implements fmt.Stringer.
func (id ContainerID) String() string { return string(id) }

View File

@@ -431,8 +431,8 @@ func (svc *Service) executeRollback(
return fmt.Errorf("failed to create rollback container: %w", err)
}
deployment.ContainerID = sql.NullString{String: string(containerID), Valid: true}
_ = deployment.AppendLog(bgCtx, "Rollback container created: "+string(containerID))
deployment.ContainerID = sql.NullString{String: containerID.String(), Valid: true}
_ = deployment.AppendLog(bgCtx, "Rollback container created: "+containerID.String())
startErr := svc.docker.StartContainer(ctx, containerID)
if startErr != nil {
@@ -695,11 +695,11 @@ func (svc *Service) cleanupCancelledDeploy(
if removeErr != nil {
svc.log.Error("failed to remove image from cancelled deploy",
"error", removeErr, "app", app.Name, "image", imageID)
_ = deployment.AppendLog(ctx, "WARNING: failed to clean up image "+string(imageID)+": "+removeErr.Error())
_ = deployment.AppendLog(ctx, "WARNING: failed to clean up image "+imageID.String()+": "+removeErr.Error())
} else {
svc.log.Info("cleaned up image from cancelled deploy",
"app", app.Name, "image", imageID)
_ = deployment.AppendLog(ctx, "Cleaned up intermediate image: "+string(imageID))
_ = deployment.AppendLog(ctx, "Cleaned up intermediate image: "+imageID.String())
}
}
@@ -850,8 +850,8 @@ func (svc *Service) buildImage(
return "", fmt.Errorf("failed to build image: %w", err)
}
deployment.ImageID = sql.NullString{String: string(imageID), Valid: true}
_ = deployment.AppendLog(ctx, "Image built: "+string(imageID))
deployment.ImageID = sql.NullString{String: imageID.String(), Valid: true}
_ = deployment.AppendLog(ctx, "Image built: "+imageID.String())
return imageID, nil
}
@@ -1038,8 +1038,8 @@ func (svc *Service) createAndStartContainer(
return "", fmt.Errorf("failed to create container: %w", err)
}
deployment.ContainerID = sql.NullString{String: string(containerID), Valid: true}
_ = deployment.AppendLog(ctx, "Container created: "+string(containerID))
deployment.ContainerID = sql.NullString{String: containerID.String(), Valid: true}
_ = deployment.AppendLog(ctx, "Container created: "+containerID.String())
startErr := svc.docker.StartContainer(ctx, containerID)
if startErr != nil {
@@ -1096,7 +1096,7 @@ func (svc *Service) buildContainerOptions(
return docker.CreateContainerOptions{
Name: "upaas-" + app.Name,
Image: string(imageID),
Image: imageID.String(),
Env: envMap,
Labels: buildLabelMap(app, labels),
Volumes: buildVolumeMounts(volumes),
@@ -1148,7 +1148,7 @@ func (svc *Service) updateAppRunning(
app *models.App,
imageID docker.ImageID,
) error {
app.ImageID = sql.NullString{String: string(imageID), Valid: true}
app.ImageID = sql.NullString{String: imageID.String(), Valid: true}
app.Status = models.AppStatusRunning
saveErr := app.Save(ctx)

View File

@@ -5,3 +5,6 @@ package webhook
// but should not be parsed into a net/url.URL (e.g. webhook URLs,
// compare URLs from external payloads).
type UnparsedURL string
// String implements fmt.Stringer.
func (u UnparsedURL) String() string { return string(u) }

View File

@@ -178,7 +178,7 @@ func extractCommitURL(payload GiteaPushPayload) UnparsedURL {
// Fall back to constructing URL from repo HTML URL
if payload.Repository.HTMLURL != "" && payload.After != "" {
return UnparsedURL(string(payload.Repository.HTMLURL) + "/commit/" + payload.After)
return UnparsedURL(payload.Repository.HTMLURL.String() + "/commit/" + payload.After)
}
return ""