Skip to content

Commit

Permalink
docker: simplify git ref resolution, thanks @chriscool
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Lars Gierth <larsg@systemli.org>
  • Loading branch information
Lars Gierth committed May 23, 2016
1 parent 518f7e0 commit 772b189
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions .dockerignore
@@ -1,6 +1,7 @@
.git/
!.git/HEAD
!.git/refs/
!.git/packed-refs
cmd/ipfs/ipfs
vendor/gx/
test/
6 changes: 1 addition & 5 deletions Dockerfile
Expand Up @@ -50,11 +50,7 @@ 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 | grep ref | cut -d' ' -f2) \
&& commit=$(if [ -z "$ref" ]; then cat .git/HEAD; else cat ".git/$ref"; fi | head -c 7) \
&& mkdir .git/objects && commit=$(git rev-parse HEAD | 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 \
Expand Down
3 changes: 1 addition & 2 deletions test/Dockerfile
Expand Up @@ -44,8 +44,7 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \
COPY . $SRC_PATH

RUN cd $SRC_PATH \
&& ref=$(cat .git/HEAD | grep ref | cut -d' ' -f2) \
&& commit=$(if [ -z "$ref" ]; then cat .git/HEAD; else cat ".git/$ref"; fi | head -c 7) \
&& mkdir .git/objects && commit=$(git rev-parse HEAD | 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" \
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0300-docker-image.sh
Expand Up @@ -70,7 +70,7 @@ test_expect_success "version CurrentCommit is set" '
docker_exec "$DOC_ID" "wget --retry-connrefused --waitretry=1 --timeout=30 -t 30 \
-q -O - http://localhost:8080/version" | grep Commit | cut -d" " -f2 >actual &&
docker_exec "$DOC_ID" "ipfs version --commit" | cut -d- -f2 >expected &&
[ "$(cat expected | wc -c)" -gt "1" ] && # check there actually is a commit set
test -s expected && # check there actually is a commit set
test_cmp expected actual
'

Expand Down

0 comments on commit 772b189

Please sign in to comment.