@cryptotaxi247 / kubo / commits / ce0d62dca

docker: save image space by excluding .git/

License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>

Lars Gierth committed Feb 5, 2016 at 04:03 UTC ce0d62dca3083939e78b6244c87c0cefadb9a621
3 files changed +16 -3
.dockerignore
+3
@@ -1,3 +1,6 @@
1 +.git/
2 +!.git/HEAD
3 +!.git/refs/
4 cmd/ipfs/ipfs
5 vendor/gx/
6 test/
Dockerfile
+7 -1
@@ -48,9 +48,15 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \
48 # Invoke gx
49 && cd $SRC_PATH \
50 && gx --verbose install --global \
51 + # We get the current commit using this hack,
52 + # so that we don't have to copy all of .git/ into the build context.
53 + # This saves us quite a bit of image size.
54 + && ref="$(cat .git/HEAD | cut -d' ' -f2)" \
55 + && commit="$(cat .git/$ref | head -c 7)" \
56 + && echo "ldflags=-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
57 # Build and install IPFS and entrypoint script
58 && cd $SRC_PATH/cmd/ipfs \
53 - && go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$(git rev-parse --short HEAD 2> /dev/null)" \
59 + && go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
60 && cp ipfs /usr/local/bin/ipfs \
61 && cp $SRC_PATH/bin/container_daemon /usr/local/bin/start_ipfs \
62 && chmod 755 /usr/local/bin/start_ipfs \
test/Dockerfile
+6 -2
@@ -42,8 +42,12 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \
42
43 COPY . $SRC_PATH
44
45 -RUN cd $SRC_PATH/cmd/ipfs \
46 - && go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$(git rev-parse --short HEAD 2> /dev/null)" \
45 +RUN cd $SRC_PATH \
46 + && ref="$(cat .git/HEAD | cut -d' ' -f2)" \
47 + && commit="$(cat .git/$ref | head -c 7)" \
48 + && echo "ldflags=-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
49 + && cd $SRC_PATH/cmd/ipfs \
50 + && go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
51 && cp ipfs /usr/local/bin/ipfs \
52 && cp $SRC_PATH/bin/container_daemon /usr/local/bin/start_ipfs \
53 && chmod 755 /usr/local/bin/start_ipfs \