user6248190
user6248190

Reputation: 1269

Go build: build output "api" already exists and is a directory

I am trying to use CompileDaemon to hot reload a go project using Docker.

My folder structure looks like the below

my-api
 - server
   - main.go
 - Dockerfile
 - docker-compose.yml
 - Makefile

This is the error I am getting:

go build github.com/firstApi/test-platform/lib/my-api/server: build output "server" already exists and is a directory

This is what my dockerfile looks like

FROM golang:1.12-stretch

ENV GO111MODULE=on
WORKDIR /go/src

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .

RUN ["go", "get", "github.com/githubnemo/CompileDaemon"]

RUN go test ./... \
&& CGO_ENABLED=0 go build -v -a -installsuffix cgo -o /main server/main.go

ENTRYPOINT CompileDaemon -log-prefix=false -build="go build ./server" -command="./main"

any ideas what I am doing wrong and what I need to change in order to fix this issue?

UPDATE*****

I tried the solution as suggested by the only answer but I now get the following error:

Could not start command:%!(EXTRA *errors.errorString=can't start command: fork/exec ./server: permission denied)

Upvotes: 5

Views: 7382

Answers (1)

grant
grant

Reputation: 872

Your default go build is attempting to output the same name as the directory. You could change your build and ENTRYPOINT line to refer to "go build -o apiserver".

Upvotes: 5

Related Questions