Skip to content

Commit

Permalink
docker: save image space by excluding .git/
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Lars Gierth <[email protected]>
  • Loading branch information
Lars Gierth committed Feb 5, 2016
1 parent c103efc commit ce0d62d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.git/
!.git/HEAD
!.git/refs/
cmd/ipfs/ipfs
vendor/gx/
test/
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \
# Invoke gx
&& cd $SRC_PATH \
&& gx --verbose install --global \
# We get the current commit using this hack,
# so that we don't have to copy all of .git/ into the build context.
# This saves us quite a bit of image size.
&& ref="$(cat .git/HEAD | cut -d' ' -f2)" \
&& commit="$(cat .git/$ref | head -c 7)" \
&& echo "ldflags=-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
# Build and install IPFS and entrypoint script
&& cd $SRC_PATH/cmd/ipfs \
&& go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$(git rev-parse --short HEAD 2> /dev/null)" \
&& go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
&& cp ipfs /usr/local/bin/ipfs \
&& cp $SRC_PATH/bin/container_daemon /usr/local/bin/start_ipfs \
&& chmod 755 /usr/local/bin/start_ipfs \
Expand Down
8 changes: 6 additions & 2 deletions test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \

COPY . $SRC_PATH

RUN cd $SRC_PATH/cmd/ipfs \
&& go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$(git rev-parse --short HEAD 2> /dev/null)" \
RUN cd $SRC_PATH \
&& ref="$(cat .git/HEAD | cut -d' ' -f2)" \
&& commit="$(cat .git/$ref | head -c 7)" \
&& echo "ldflags=-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
&& cd $SRC_PATH/cmd/ipfs \
&& go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
&& cp ipfs /usr/local/bin/ipfs \
&& cp $SRC_PATH/bin/container_daemon /usr/local/bin/start_ipfs \
&& chmod 755 /usr/local/bin/start_ipfs \
Expand Down

0 comments on commit ce0d62d

Please sign in to comment.