douguyi3903
2018-01-30 11:38
浏览 25
已采纳

如何冻结具有依赖项的微型版本?

I want to build a docker image with a fixed version of micro and go dependencies. I plan to do it with dep:

git checkout git@github.com:micro/micro.git
dep ensure
git add Gopkg.toml
git add Gopkg.lock

# Build micro
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' -i -o micro ./main.go 

# Build docker image
...

So, my question is does it the best solution to build consistent micro docker image?

图片转代码服务由CSDN问答提供 功能建议

我想使用固定版本的 micro 构建docker映像并进行依赖。 我计划使用 dep

  git checkout git@github.com:micro / micro.git 
dep确保
git添加Gopkg。  toml 
git add Gopkg.lock 
 
#构建micro 
CGO_ENABLED = 0 GOOS = linux go build -a -installsuffix cgo -ldflags'-w'-i -o micro ./main.go 
 
#构建 docker image 
 ... 
   
 
 

所以,我的问题是构建一致的 micro docker image是最好的解决方案吗?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsg24156 2018-02-06 04:45
    已采纳

    In my case, dep looks great and fast enough, moreover, it's official dependency manager in go so I think it's a right choice.

    已采纳该答案
    打赏 评论
  • douruocai4111 2018-01-30 13:27

    An example of a Dockerfile can be:

    FROM golang:1.9-alpine3.6 as builder
    
    # Install package manager
    RUN apk add --no-cache --virtual .go-dependencies git curl \
      && curl https://glide.sh/get | sh
    
    # Copy files from context
    WORKDIR /go/src/github.com/foo/bar
    COPY . .
    
    # Install project dependencies, test and build
    RUN glide install \
      && go test ./... \
      && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' -i -o ./entry ./main.go ./plugins.go
    
    # Build final image with binary
    FROM alpine:3.6
    RUN apk add --update ca-certificates && \
        rm -rf /var/cache/apk/* /tmp/*
    WORKDIR /
    COPY --from=builder /go/src/github.com/foo/bar/entry .
    ENTRYPOINT [ "/entry" ]
    

    And the glide.yaml would look like this:

    package: .
    import:
    - package: github.com/micro/go-micro
      version: ^0.3.0
      subpackages:
      - client
      - server
    - package: github.com/micro/go-plugins
      version: ^0.6.1
      subpackages:
      - wrapper/trace/opentracing
      - broker/nats
      - transport/nats
    - package: github.com/opentracing/opentracing-go
      version: ^1
    - package: github.com/openzipkin/zipkin-go-opentracing
      version: ^0.3
    testImport:
    - package: github.com/golang/mock
      subpackages:
      - gomock
    - package: github.com/smartystreets/goconvey
      subpackages:
      - convey
    
    打赏 评论

相关推荐 更多相似问题