plandex-ai / plandex

AI driven development in your terminal. Designed for large, real-world tasks.
https://plandex.ai
GNU Affero General Public License v3.0
10.72k stars 748 forks source link

Segmentation Fault During `go build` in Docker Compose #203

Closed vanillechai closed 1 day ago

vanillechai commented 1 week ago

Description: While attempting to build the Plandex server component with docker-compose on an M1 Mac using Colima, a segmentation fault occurs during the execution of the go build command. This appears consistently despite multiple attempts.

Relevant Logs:

 > [plandex-server 12/12] RUN rm -f plandex-server && go build -o plandex-server .:
2.425 go: error obtaining buildID for go tool compile: signal: segmentation fault (core dumped)
------
failed to solve: process "/bin/sh -c rm -f plandex-server && go build -o plandex-server ." did not complete successfully: exit code: 1
 > [plandex-server 12/12] RUN rm -f plandex-server && go build -o plandex-server .:
45.35 # runtime/cgo
45.35 gcc: internal compiler error: Segmentation fault signal terminated program cc1
45.35 Please submit a full bug report, with preprocessed source (by using -freport-bug).
 > [plandex-server 12/12] RUN rm -f plandex-server && go build -o plandex-server .:
34.24 syscall: /usr/local/go/pkg/tool/linux_amd64/compile: signal: segmentation fault (core dumped)

Environment Details:

Dechef274 commented 6 days ago

Environment Details:

  1. Possible Causes: a) Architecture mismatch b) Go version incompatibility c) Dependency issues d) Memory constraints e) Colima configuration

  2. Troubleshooting Steps:

    a) Check Go version: Ensure you're using a Go version that's compatible with your project and supports ARM64. You can check this in your Dockerfile or docker-compose file.

    b) Verify Docker image architecture: Make sure you're using an ARM64-compatible base image. You can check this in your Dockerfile.

    c) Increase resource allocation: Colima might be constrained on resources. Try increasing memory and CPU allocation:

      colima stop
      colima start --cpu 4 --memory 8

    d) Enable BuildKit: BuildKit can sometimes help with cross-platform builds. Set this environment variable:

      export DOCKER_BUILDKIT=1

    e) Check for problematic dependencies: Review your Go dependencies. Some might not be compatible with ARM64.

    f) Build with verbose output: Modify your docker-compose file to include verbose output for the go build command:

      command: go build -v ./...

    g) Try building without Docker: As a test, try building the Go project directly on your Mac to isolate if it's a Docker/Colima issue or a project issue.

  3. Next steps:

    1. Could you share the relevant parts of your Dockerfile and docker-compose.yml?
    2. What's the exact Go version you're using?
    3. Can you provide the full error message from the segmentation fault?

It works

Dechef

vanillechai commented 6 days ago
  • Plandex server component (Go-based, I assume)

Since this repository is Go-based, I assume the same applies to the server component. Um. Are you a bot?

  1. Troubleshooting Steps:

a) and b) see below. Note that I followed https://docs.plandex.ai/hosting/self-hosting. I did not change anything in this repository when I followed these steps.

c) Increase resource allocation:

4 CPU and 8 mem match exactly the resources I have already allocated to Colima.

d) Enable BuildKit: BuildKit can sometimes help with cross-platform builds. Set this environment variable:

   export DOCKER_BUILDKIT=1

This did not help.

e) Check for problematic dependencies: Review your Go dependencies. Some might not be compatible with ARM64.

How would I know that? As far as I can see, these are the dependencies.

g) Try building without Docker: As a test, try building the Go project directly on your Mac to isolate if it's a Docker/Colima issue or a project issue.

I might consider it, but I just wanted to play around with Plandex.

  1. Next steps:

    1. Could you share the relevant parts of your Dockerfile and docker-compose.yml?

Using the project's Dockerfile and docker-compose.yml from the main branch.

  1. What's the exact Go version you're using?

From the Dockerfile above:

FROM --platform=linux/amd64 golang:1.21.3
  1. Can you provide the full error message from the segmentation fault?

There was no output to this step 12 other than what I provided. However, as you can see above, the error message is slightly different each time, with the "segmentation error" in common.

It works

Not here.

danenania commented 6 days ago

@Dechef274 Hey, thanks for your help, but please don’t post AI generated responses like that in this repo. It’s maybe ok to link to an AI chat or quote some parts of it if it’s relevant and helpful, but I see it as bad etiquette to post a wall of AI-generated text with minimal additional comment.

Let’s keep the discussion human-to-human. Thanks!! 🙏

Dechef274 commented 6 days ago

No, I ask Claude, and tested the results it worked. 1st

edit``

Dechef274 commented 6 days ago

Thanks for the feedback. Will improve

Dechef274 commented 6 days ago

Thanks

On Sun, Oct 20, 2024, 12:17 AM Dane Schneider @.***> wrote:

@Dechef274 https://github.com/Dechef274 Hey, thanks for your help, but please don’t post AI generated responses like that in this repo. It’s maybe ok to link to an AI chat or quote some parts of it if it’s relevant and helpful, but I see it as bad etiquette to post a wall of AI-generated text with no additional comment.

Let’s keep the discussion human-to-human. Thanks!! 🙏

— Reply to this email directly, view it on GitHub https://github.com/plandex-ai/plandex/issues/203#issuecomment-2424563870, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGABLLJKCSKIMXO5M2OA2PTZ4MVE5AVCNFSM6AAAAABQHXIYBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRUGU3DGOBXGA . You are receiving this because you were mentioned.Message ID: @.***>

vanillechai commented 6 days ago

So I just tried it on another Mac, this time an M1 Pro, using exactly the commands from https://docs.plandex.ai/hosting/self-hosting/#docker-compose:

git clone https://github.com/plandex-ai/plandex.git
cd plandex/app
cp _env .env
docker compose build

And the result is the same: segmentation fault in build step 12. Which makes me wonder:

Has anyone ever successfully built the Plandex server Docker image on a Mac?

danenania commented 6 days ago

@vanillechai I'm using a Mac (M1) so I can definitely confirm that it builds on a Mac. I just rebuilt with main to be sure there are no regressions and it's building without issues.

I'm using Docker Desktop, so my first guess is that your issue is somehow related to Colima.

corrosive4354 commented 5 days ago

Segmentation faults are usually caused by accessing invalid memory addresses, which may be related to the Go compiler, Docker configuration, or the underlying architecture (such as ARM). Docker does not support ARM You can try using Servbay instead of docker, which works better than docker on mac and has fewer bugs

vanillechai commented 2 days ago

Colima (Colima: "Containers on lima" - lima: "Linux machines") is just the CLI interface to a VM with a Docker runtime, which in my case is containerd. But neither of these were an issue. The solution was obvious once I looked into the Dockerfile.server:

--- a/app/Dockerfile.server
+++ b/app/Dockerfile.server
@@ -1,4 +1,4 @@
-FROM --platform=linux/amd64 golang:1.21.3
+FROM golang:1.21.3

 # Update and install necessary packages including build tools for Tree-sitter
 RUN apt-get update && \
@@ -23,14 +23,24 @@ WORKDIR /app/server

 # Set environment variables for Go
 ENV GOOS=linux
-ENV GOARCH=amd64

 # Build the application
 RUN rm -f plandex-server && go build -o plandex-server .

+FROM debian:bookworm-slim
+
+RUN apt-get update && apt-get install -y git
+
+WORKDIR /app/server
+
+COPY --from=0 /app /app
+COPY ./scripts /scripts

I simply removed all references to amd64 and it built like a charm. I've added another stage to reduce the size of the image (almost 2GB for a 60MB Go executable - srlsy?!) to ~250MB and it's running fine - the server component, at least.

I have some doubts about the docker-compose.yml. Some of the mounts are not available on my machine (and I find them really questionable - why do you mount the host timezone?). Why not use a simple condition: service_healthy with a healthcheck: [...] pg_isready instead of adding the bloated wait_for_it.sh?

And then I had the volume mount clash with file permissions and PG refused to start. I'd definitely recommend avoiding host mounts - how would you run this on Kubernetes or ECS?

At that point I gave up. I just wanted to give this project a quick try, not spend hours debugging it, and what I saw made me doubt the overall quality of this project (which is one of 1000s of fabulous new AI tools). I just wanted to leave my feedback here, in the hope that it might help someone. The next thing I'd have tried was to use a Docker volume instead of a mount.

danenania commented 1 day ago

@vanillechai Appreciate the feedback, could do without the obnoxious attitude though.

Some of this can definitely be improved, but it might surprise you to learn that building on your specific machine is not the only requirement. I've already tried this approach for reducing container size (spent hours on it), and it unfortunately fails to cross-compile correctly for Amazon Linux. This is necessary for the cloud service, which runs on ECS.

Fyi, no open source project wants annoying entitled users who complain about the imperfections of something offered for free rather than contributing. It's actually considered one of the main negatives of open sourcing. So you will in fact be doing me a favor by taking your bad attitude to one of those 1000 other tools. Happy trails 🫡