From 6b94fdecd689a8a017496b3d5cdf1298410a3c3d Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Wed, 18 May 2016 21:37:36 +0200 Subject: [PATCH 1/2] docker: fix CurrentCommit discovery License: MIT Signed-off-by: Lars Gierth --- Dockerfile | 4 ++-- test/Dockerfile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c72e274d6b3..e1c45ddc00c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,8 +53,8 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \ # 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)" \ + && 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) \ && echo "ldflags=-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \ # Build and install IPFS and entrypoint script && cd $SRC_PATH/cmd/ipfs \ diff --git a/test/Dockerfile b/test/Dockerfile index af8a5966138..8596454966c 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -44,8 +44,8 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \ COPY . $SRC_PATH RUN cd $SRC_PATH \ - && ref="$(cat .git/HEAD | cut -d' ' -f2)" \ - && commit="$(cat .git/$ref | head -c 7)" \ + && 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) \ && 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" \ From 7145d306b4882b673e52e9f75e623e9cfb579490 Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Wed, 18 May 2016 22:10:27 +0200 Subject: [PATCH 2/2] docker: add test for ipfs version --commit License: MIT Signed-off-by: Lars Gierth --- test/sharness/t0300-docker-image.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/sharness/t0300-docker-image.sh b/test/sharness/t0300-docker-image.sh index ec964cd0d7e..27024380903 100755 --- a/test/sharness/t0300-docker-image.sh +++ b/test/sharness/t0300-docker-image.sh @@ -66,6 +66,14 @@ test_expect_success "simple ipfs add/cat can be run in docker container" ' test_cmp expected actual ' +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_cmp expected actual +' + test_expect_success "stop docker container" ' docker_stop "$DOC_ID" '