From d2d41b105e0b817ca266a8337d1b4b96f6f27c5e Mon Sep 17 00:00:00 2001 From: William Burton Date: Mon, 3 Jun 2024 11:24:47 -0400 Subject: [PATCH 1/7] Disable CGO when building binaries locally. --- build/binary/binary.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/binary/binary.go b/build/binary/binary.go index a0170128..a9e91b65 100644 --- a/build/binary/binary.go +++ b/build/binary/binary.go @@ -18,6 +18,7 @@ package binary import ( "context" "log" + "os" "os/exec" "path/filepath" ) @@ -25,6 +26,7 @@ import ( // Build constructs a binary for one of the project's microservices. func Build(ctx context.Context, name string) (path string, err error) { cmd := exec.CommandContext(ctx, "go", "build", "-o", name, "./cmd/"+name) + cmd.Env = append(os.Environ(), "CGO_ENABLED=0") cmd.Stdout = log.Writer() cmd.Stderr = log.Writer() log.Print(cmd.String()) From 4c8e529d594f8173d1bf58eb88b2bc7f2cf559b4 Mon Sep 17 00:00:00 2001 From: William Burton Date: Mon, 3 Jun 2024 11:27:00 -0400 Subject: [PATCH 2/7] Ignore the locally built rebuilder binary. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a7a18464..8edfd654 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Locally built binaries +rebuilder + # jj .jj/ From 2d6e78fb3b74611ddf3ce3b992da99607ca6e1ae Mon Sep 17 00:00:00 2001 From: William Burton Date: Tue, 4 Jun 2024 17:08:18 -0400 Subject: [PATCH 3/7] Put builds in a bin dir --- .gitignore | 2 +- build/binary/binary.go | 2 +- build/container/container.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8edfd654..7c66e429 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # Locally built binaries -rebuilder +bin/ # jj .jj/ diff --git a/build/binary/binary.go b/build/binary/binary.go index a9e91b65..86d639a3 100644 --- a/build/binary/binary.go +++ b/build/binary/binary.go @@ -25,7 +25,7 @@ import ( // Build constructs a binary for one of the project's microservices. func Build(ctx context.Context, name string) (path string, err error) { - cmd := exec.CommandContext(ctx, "go", "build", "-o", name, "./cmd/"+name) + cmd := exec.CommandContext(ctx, "go", "build", "-o", "./bin/"+name, "./cmd/"+name) cmd.Env = append(os.Environ(), "CGO_ENABLED=0") cmd.Stdout = log.Writer() cmd.Stderr = log.Writer() diff --git a/build/container/container.go b/build/container/container.go index 184909ab..1cc3f88c 100644 --- a/build/container/container.go +++ b/build/container/container.go @@ -32,7 +32,7 @@ func Build(ctx context.Context, name, binary string) error { } defer os.RemoveAll(tempDir) - err = copyFile(filepath.Join(tempDir, name), binary) + err = copyFile(filepath.Join(tempDir, name), filepath.Join("./bin/", name)) if err != nil { return err } From d5e0eb5d6996eb177de8730f6ef95ee4a4317700 Mon Sep 17 00:00:00 2001 From: William Burton Date: Tue, 4 Jun 2024 17:13:08 -0400 Subject: [PATCH 4/7] Fix the binary.Build() return, use that in container. --- build/binary/binary.go | 2 +- build/container/container.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/binary/binary.go b/build/binary/binary.go index 86d639a3..6329f16a 100644 --- a/build/binary/binary.go +++ b/build/binary/binary.go @@ -34,6 +34,6 @@ func Build(ctx context.Context, name string) (path string, err error) { if err != nil { return } - path, err = filepath.Abs(name) + path, err = filepath.Abs("./bin/" + name) return } diff --git a/build/container/container.go b/build/container/container.go index 1cc3f88c..184909ab 100644 --- a/build/container/container.go +++ b/build/container/container.go @@ -32,7 +32,7 @@ func Build(ctx context.Context, name, binary string) error { } defer os.RemoveAll(tempDir) - err = copyFile(filepath.Join(tempDir, name), filepath.Join("./bin/", name)) + err = copyFile(filepath.Join(tempDir, name), binary) if err != nil { return err } From 43f23fef85f8a6fc5140adfab3d6ab44dfc1359f Mon Sep 17 00:00:00 2001 From: William Burton Date: Tue, 4 Jun 2024 17:20:57 -0400 Subject: [PATCH 5/7] use filepath.Join --- build/binary/binary.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/binary/binary.go b/build/binary/binary.go index 6329f16a..c136ba8f 100644 --- a/build/binary/binary.go +++ b/build/binary/binary.go @@ -25,7 +25,7 @@ import ( // Build constructs a binary for one of the project's microservices. func Build(ctx context.Context, name string) (path string, err error) { - cmd := exec.CommandContext(ctx, "go", "build", "-o", "./bin/"+name, "./cmd/"+name) + cmd := exec.CommandContext(ctx, "go", "build", "-o", filepath.Join("./bin/", name), filepath.Join("./cmd/", name)) cmd.Env = append(os.Environ(), "CGO_ENABLED=0") cmd.Stdout = log.Writer() cmd.Stderr = log.Writer() @@ -34,6 +34,6 @@ func Build(ctx context.Context, name string) (path string, err error) { if err != nil { return } - path, err = filepath.Abs("./bin/" + name) + path, err = filepath.Abs(filepath.Join("./bin/", name)) return } From 6b34ed54cb952f695f706351484fec08aabb678a Mon Sep 17 00:00:00 2001 From: William Burton Date: Tue, 4 Jun 2024 17:31:17 -0400 Subject: [PATCH 6/7] remove slashes from Join --- build/binary/binary.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/binary/binary.go b/build/binary/binary.go index c136ba8f..7680d740 100644 --- a/build/binary/binary.go +++ b/build/binary/binary.go @@ -25,7 +25,7 @@ import ( // Build constructs a binary for one of the project's microservices. func Build(ctx context.Context, name string) (path string, err error) { - cmd := exec.CommandContext(ctx, "go", "build", "-o", filepath.Join("./bin/", name), filepath.Join("./cmd/", name)) + cmd := exec.CommandContext(ctx, "go", "build", "-o", filepath.Join(".", "bin", name), filepath.Join(".", "cmd", name)) cmd.Env = append(os.Environ(), "CGO_ENABLED=0") cmd.Stdout = log.Writer() cmd.Stderr = log.Writer() @@ -34,6 +34,6 @@ func Build(ctx context.Context, name string) (path string, err error) { if err != nil { return } - path, err = filepath.Abs(filepath.Join("./bin/", name)) + path, err = filepath.Abs(filepath.Join(".", "bin", name)) return } From 1287e3ce636a43f0a6a6c292c8c8a05c2f4e8793 Mon Sep 17 00:00:00 2001 From: William Burton Date: Tue, 4 Jun 2024 17:38:26 -0400 Subject: [PATCH 7/7] Use os.PathSeparator --- build/binary/binary.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/binary/binary.go b/build/binary/binary.go index 7680d740..94d54523 100644 --- a/build/binary/binary.go +++ b/build/binary/binary.go @@ -21,11 +21,12 @@ import ( "os" "os/exec" "path/filepath" + "strings" ) // Build constructs a binary for one of the project's microservices. func Build(ctx context.Context, name string) (path string, err error) { - cmd := exec.CommandContext(ctx, "go", "build", "-o", filepath.Join(".", "bin", name), filepath.Join(".", "cmd", name)) + cmd := exec.CommandContext(ctx, "go", "build", "-o", strings.Join([]string{".", "bin", name}, string(os.PathSeparator)), strings.Join([]string{".", "cmd", name}, string(os.PathSeparator))) cmd.Env = append(os.Environ(), "CGO_ENABLED=0") cmd.Stdout = log.Writer() cmd.Stderr = log.Writer()