From 985ccaef6f6c9b6deda4bce8baa889b5b59119b8 Mon Sep 17 00:00:00 2001 From: Matt Luongo Date: Wed, 14 Feb 2018 23:13:32 -0800 Subject: [PATCH] Multi-stage builds, take two --- Dockerfile | 37 +++++++++++++++++++++++---------- build-keep-client-docker-img.sh | 31 --------------------------- 2 files changed, 26 insertions(+), 42 deletions(-) delete mode 100755 build-keep-client-docker-img.sh diff --git a/Dockerfile b/Dockerfile index 491e396d36..4487805de6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ + +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 . -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"] diff --git a/build-keep-client-docker-img.sh b/build-keep-client-docker-img.sh deleted file mode 100755 index 606c867a6e..0000000000 --- a/build-keep-client-docker-img.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -# Build vendor directory from latest source -if [ "$(basename $(pwd))" != "keep-core" ] || [ ! -d ./go ]; then - echo "You should run $(basename $0) from the github.com/keep-net/keep-core directory" - exit 2 -fi - -if [ $(git status | grep "On branch master" | wc | awk '{print $1}') == "0" ]; then - echo "WARNING: You are not on the master branch! Are you sure you want to continue? (CTRL+C to abort)" - read x -fi -if [ $(git status | grep "Your branch is up to date with 'origin/master'." | wc | awk '{print $1}') == "0" ]; then - echo "Your branch (local file system) is NOT up-to-date with the master branch." - exit 2 -fi -if [ $(git status | grep "nothing to commit, working tree clean" | wc | awk '{print $1}') == "0" ]; then - echo "Have you committed all of your changes?" - exit 2 -fi - -# Go to source directory -cd go -# Build vendor from current source -dep ensure -# Back to the keep-core directory that has the Dockerfile. -cd .. - -IMG=keep-client -DOCKERFILE=Dockerfile - -docker build -t "$IMG" -f "$DOCKERFILE" .