Reputation: 29
I have a package structure
$GOPATH/src/io.sure/api/proto/vi/party.pb.go
.../io.sure/party/party.go
../io.sure/Dockerfile
import of party.go are
import (
"context"
"google.golang.org/grpc"
"io.sure/api/proto/v1"
"log"
"net"
)
FROM golang:1.12.1-alpine AS builder
RUN apk update && apk add --no-cache git
WORKDIR /go/src/app
COPY ./party/ .
COPY ./api/ .
RUN go get -d -v
RUN CGO_ENABLED=0 go install
FROM scratch
WORKDIR /opt
COPY --from=builder /go/bin/app .
ENTRYPOINT ["/opt/app"]
The code compiles and runs from a command line. But when I build a docker image, go get tries to download io.sure/api/proto/v1 even when i have a copied the api folder in the docker image. How can i stop/skip downloading the package, as I do not have the code on github or any other public repo.
Is vendoring a right thing to do, since its my own package which may not be exported or exported to outside world.
I tried go modules but i am facing issues and still want to work with GOPATH.
ried both the combinations but still the same error. code does get copied in image gopath.
FROM golang:1.12.1-alpine AS builder RUN apk update && apk add --no-cache git WORKDIR $GOPATH/src/io.sure COPY ./party/ . COPY ./api/ . RUN go get -d -v RUN CGO_ENABLED=0 go install
FROM scratch WORKDIR /opt COPY --from=builder /go/bin/app . ENTRYPOINT ["/opt/app"]
FROM golang:1.12.1-alpine AS builder RUN apk update && apk add --no-cache git WORKDIR $GOPATH/src RUN mkdir -p $GOPATH/src/io.sure COPY ./party/ . COPY ./api/ . RUN go get -d -v RUN CGO_ENABLED=0 go install
FROM scratch WORKDIR /opt COPY --from=builder /go/bin/app . ENTRYPOINT ["/opt/app"] Fetching https://io.sure/api/proto/v1/party?go-get=1 https fetch failed: Get https://io.sure/api/proto/v1/party?go-get=1: dial tcp: lookup io.sure on xxx.xx.0.2:53: no such host package io.sure/api/proto/v1/party: unrecognized import path "io.sure/api/proto/v1/party" (https fetch: Get https://io.sure/api/proto/v1/party?go-get=1: dial tcp: lookup io.sure on xxx.31.0.2:53: no such host)
Upvotes: 1
Views: 878
Reputation: 29
found the solution. modified Dockerfile. All dependencies are managed with Godep
changed workdir to /go/src/github.com/kubesure/party
added RUN echo "[url \"[email protected]:\"]\n\tinsteadOf = https://github.com/" >>
RUN echo "[url \"[email protected]:\"]\n\tinsteadOf = https://github.com/" >> /root/.gitconfig
RUN apk update && apk add --no-cache git
WORKDIR /go/src/github.com/kubesure/party
COPY . .
RUN CGO_ENABLED=0 go install
FROM scratch
WORKDIR /opt
COPY --from=builder /go/bin/party .
EXPOSE 50051
CMD ["/opt/party"]
Upvotes: 0
Reputation: 860
The content of your $GOPATH
differs between cli and Dockerimage in that your packages are not in the right place.
You need to RUN mkdir -p $GOPATH/src/io.sure
and COPY ./party $GOPATH/src/io.sure/
to achieve the same layout in the Dockerimage like on the cli.
You probably need to adapt the Paths but I hope you get the idea
Upvotes: 2