-
Notifications
You must be signed in to change notification settings - Fork 88
Multi-stage Docker builds #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,26 @@ ENV GOPATH=/go \ | |
| APP_REPO_DIR=/go/src/keep-network/keep-client \ | ||
| APP_NAME=keep-client | ||
|
|
||
| COPY ./go $APP_REPO_DIR | ||
| WORKDIR $APP_REPO_DIR | ||
|
|
||
| RUN apk add --update --no-cache \ | ||
| git && \ | ||
| mkdir -p /go/src && \ | ||
| rm -rf /var/cache/apk && mkdir /var/cache/apk && \ | ||
| rm -rf /usr/share/man | ||
|
|
||
| RUN go get -u github.com/golang/dep/cmd/dep | ||
| COPY ./go/Gopkg.toml ./go/Gopkg.lock ./ | ||
| RUN dep ensure --vendor-only | ||
|
|
||
| RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o $APP_NAME . && \ | ||
| mv $APP_NAME /usr/local/bin/ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. So this will build without Out of curiosity, what's the benefit of doing this before we do all the updates below, vs after? It feels like the right flow organizationally (to me!) to handle dependencies from furthest away (non-Go) to closest (Go) and then conclude by building our own executable, rather than building the executable up top and pulling in additional dependencies further down, but it's entirely possible we gain something I missed :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to get it statically linked- that way the client could work standalone. I spent a ton of time on it early on but couldn't figure it out.
This is where we're getting a benefit. This Dockerfile builds two images, and in the second we have way less stuff, but take the static build artifact from the first. If the library could be statically built and easily moved, we'd build the lib and client in the first and copy both to the new image. Basically, takeaway- this pattern is two different containers with different base images, installs, etc
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha! So basically if we built the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly |
||
|
|
||
| FROM alpine:3.7 | ||
|
|
||
| ENV BN_VERSION=d1a44d2f242692601b3e150b59044ab82f265b65 | ||
|
|
||
| RUN apk add --update --no-cache \ | ||
| bash \ | ||
| clang \ | ||
|
|
@@ -18,24 +38,19 @@ RUN apk add --update --no-cache \ | |
| make \ | ||
| openssl \ | ||
| openssl-dev && \ | ||
| git clone https://github.com/dfinity/bn /bn && \ | ||
| mkdir -p /go/src && \ | ||
| git clone https://github.com/dfinity/bn /bn && \ | ||
| cd /bn && \ | ||
| git reset --hard $BN_VERSION && \ | ||
| make install && make && \ | ||
| rm -rf /bn && \ | ||
| mkdir -p /go/src && \ | ||
| rm -rf /var/cache/apk && mkdir /var/cache/apk && \ | ||
| rm -rf /usr/share/man && \ | ||
| apk del git make clang llvm && \ | ||
| mkdir -p $APP_REPO_DIR | ||
| apk del git make clang llvm | ||
|
|
||
| ENV BN_VERSION=d1a44d2f242692601b3e150b59044ab82f265b65 | ||
| COPY --from=0 /usr/local/bin/keep-client /usr/local/bin/ | ||
|
|
||
| COPY ./go $APP_REPO_DIR | ||
| WORKDIR $APP_REPO_DIR | ||
|
|
||
| RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o $APP_NAME . && \ | ||
| mv $APP_NAME /usr/local/bin && \ | ||
| rm -rf $APP_REPO_DIR | ||
| ENV LD_LIBRARY_PATH=/usr/local/lib/ | ||
|
|
||
| ENTRYPOINT ["keep-client"] | ||
|
|
||
|
|
||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to happen after the
dep ensureor a*.gofile change will rerun the wholeapk+dep ensureflow.