-2

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?

pprishchepa
  • 997
  • 1
  • 9
  • 21
  • What have you tried? What problems did you encounter? – Jonathan Hall Jan 30 '18 at 11:40
  • I want to have a consistent docker image with _micro_, each time I build it. – pprishchepa Jan 30 '18 at 12:03
  • 1
    Okay, but what have you tried? And what problems did you encounter? – Jonathan Hall Jan 30 '18 at 12:04
  • 1
    In our first approach to lock the vendors we have used dep as well but the main set back was its speed. It took ages to build download everything. We have since then switched to Glide and it has been working in production quite reliably. You just have to take the time to define in your glide.yaml each vendor and the version you want to lock. – ealves Jan 30 '18 at 12:39
  • @Flimzy I described in my question the way I'm trying to build docker image with _micro_. I just what to confirm or refuse does it a correct way to build docker image with frozen _micro_ version with dependencies or not. – pprishchepa Jan 31 '18 at 06:00
  • @ealves thank you for what you shared your experience with dep and glide – pprishchepa Jan 31 '18 at 06:04
  • Your question skips the entire "build docker image" step, which is the essential one for answering your question. In particular, your Dockerfile is essential to answer your question. – Jonathan Hall Jan 31 '18 at 07:30
  • @Flimzy hm, I don't see how it can help but OK I build docker image using a docker file like that https://github.com/micro/micro/blob/master/Dockerfile. – pprishchepa Feb 01 '18 at 07:52

2 Answers2

1

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
ealves
  • 131
  • 1
  • 10
0

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.

pprishchepa
  • 997
  • 1
  • 9
  • 21