douzhiba6873 2019-03-27 13:40
浏览 87

如果代码不在Internet上托管,如何导入软件包

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)

  • 写回答

2条回答 默认 最新

  • doujiu1447 2019-03-27 13:56
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序