1eb2164a5370d3e3410c2f5bbb5bc01ec580b8ce

Author
TheEdgeOfRage <git@theedgeofrage.com>
Committer
TheEdgeOfRage <git@theedgeofrage.com>
Date

Message

fix worker image naming and command logs

Diff

 1diff --git a/main.go b/main.go
 2index f670878f0ac565f7acab4788487cc491cdb4dabb..7f751496922c81d4b3b753e98462c4a1082233a4 100644
 3--- a/main.go
 4+++ b/main.go
 5@@ -13,6 +13,7 @@ import (
 6 	"os/exec"
 7 	"path/filepath"
 8 	"regexp"
 9+	"strings"
10 )
11 
12 const maxRequestBodySize = 1024
13@@ -159,7 +160,7 @@ func ensureSingleJSONValue(decoder *json.Decoder) error {
14 
15 func runWorker(config config, jobs <-chan buildRequest) {
16 	for request := range jobs {
17-		image := config.registry + "/" + request.Repository
18+		image := imageName(config.registry, request.Repository)
19 		slog.Info("build started", "repository", request.Repository, "sha", request.SHA, "image", image)
20 		if err := build(context.Background(), config, request); err != nil {
21 			slog.Error("build failed", "repository", request.Repository, "sha", request.SHA, "image", image, "error", err)
22@@ -189,7 +190,7 @@ func build(ctx context.Context, config config, request buildRequest) error {
23 		return err
24 	}
25 
26-	image := config.registry + "/" + request.Repository
27+	image := imageName(config.registry, request.Repository)
28 	output := fmt.Sprintf("type=image,name=%s:%s,%s:main,push=true", image, request.SHA, image)
29 	if err := run(
30 		ctx,
31@@ -230,9 +231,19 @@ func extractArchive(ctx context.Context, repositoryPath, sha, contextPath string
32 	return nil
33 }
34 
35+func imageName(registry, repository string) string {
36+	return registry + "/" + filepath.Base(repository)
37+}
38+
39 func run(ctx context.Context, name string, arguments ...string) error {
40-	command := exec.CommandContext(ctx, name, arguments...)
41-	command.Stdout = os.Stdout
42-	command.Stderr = os.Stderr
43-	return command.Run()
44+	output, err := exec.CommandContext(ctx, name, arguments...).CombinedOutput()
45+	if err == nil {
46+		return nil
47+	}
48+
49+	message := strings.TrimSpace(string(output))
50+	if message == "" {
51+		return err
52+	}
53+	return fmt.Errorf("%w: %s", err, message)
54 }