3

I have a Go project, which is a private repo on GitHub. I want to build this project from source. I've tried running go get -d -v ./... && go install -v ./... to install all dependencies, but this is the error I got fatal: could not read Username for 'https://github.com': terminal prompts disabled which means that it tried to clone my project from GitHub rather than building it from source.

I can really use some help in properly building a Go project from source, with all the dependencies installed. I am using Docker and this is how my Dockerfile looks:

#build stage
FROM golang:alpine AS builder
WORKDIR /go/src/app
COPY . .
RUN apk add --no-cache git
RUN go get -d -v ./...
RUN go install -v ./...

#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /go/bin/app /app
ENTRYPOINT ./app
EXPOSE 8080

Only my project's code is private, all other dependencies I have are publically available e.g. mux. I have no problem if Go pulls those files from GitHub, but I want to compile my project's code from source.

saranshabd
  • 55
  • 1
  • 8
  • Are you using gomod ? What the structure of your project? – Roman Kiselenko Mar 08 '20 at 09:12
  • No, I'm not using `gomod`. It's a very simple REST API. I've just started the project. The problem is that when I'm importing my project's own packages, `go compiler` thinks that these are dependencies and tries to fetch them from GitHub. It is a monolithic codebase, with code divided into packages. – saranshabd Mar 08 '20 at 09:21
  • 1
    I assume you should use `go build` instead of `go install`. – Roman Kiselenko Mar 08 '20 at 10:25
  • The problem isn't with `go install`. The problem is with `go get ./...`, which gets all the dependencies automatically. I think an alternative to this is installing each and every dependency individually. – saranshabd Mar 08 '20 at 11:08
  • 1
    If you vendor your dependencies, as you should, you can omit the `go get` step of your build. – mkopriva Mar 08 '20 at 11:17

0 Answers0