@cryptotaxi247 / kubo / commits / 0eed330ec

docker: simplify git ref resolution, thanks @chriscool

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

Lars Gierth committed May 23, 2016 at 20:51 UTC 0eed330ec2f23cc92e6c5fe04f177d889781870b
4 files changed +4 -8
.dockerignore
+1
@@ -1,6 +1,7 @@
1 .git/
2 !.git/HEAD
3 !.git/refs/
4 +!.git/packed-refs
5 cmd/ipfs/ipfs
6 vendor/gx/
7 test/
Dockerfile
+1 -5
@@ -50,11 +50,7 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \
50 # Invoke gx
51 && cd $SRC_PATH \
52 && gx --verbose install --global \
53 - # We get the current commit using this hack,
54 - # so that we don't have to copy all of .git/ into the build context.
55 - # This saves us quite a bit of image size.
56 - && ref=$(cat .git/HEAD | grep ref | cut -d' ' -f2) \
57 - && commit=$(if [ -z "$ref" ]; then cat .git/HEAD; else cat ".git/$ref"; fi | head -c 7) \
53 + && mkdir .git/objects && commit=$(git rev-parse --short HEAD) \
54 && echo "ldflags=-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
55 # Build and install IPFS and entrypoint script
56 && cd $SRC_PATH/cmd/ipfs \
test/Dockerfile
+1 -2
@@ -44,8 +44,7 @@ RUN apk add --update musl go=$GO_VERSION git bash wget ca-certificates \
44 COPY . $SRC_PATH
45
46 RUN cd $SRC_PATH \
47 - && ref=$(cat .git/HEAD | grep ref | cut -d' ' -f2) \
48 - && commit=$(if [ -z "$ref" ]; then cat .git/HEAD; else cat ".git/$ref"; fi | head -c 7) \
47 + && mkdir .git/objects && commit=$(git rev-parse --short HEAD) \
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" \
test/sharness/t0300-docker-image.sh
+1 -1
@@ -70,7 +70,7 @@ test_expect_success "version CurrentCommit is set" '
70 docker_exec "$DOC_ID" "wget --retry-connrefused --waitretry=1 --timeout=30 -t 30 \
71 -q -O - http://localhost:8080/version" | grep Commit | cut -d" " -f2 >actual &&
72 docker_exec "$DOC_ID" "ipfs version --commit" | cut -d- -f2 >expected &&
73 - [ "$(cat expected | wc -c)" -gt "1" ] && # check there actually is a commit set
73 + test -s expected && # check there actually is a commit set
74 test_cmp expected actual
75 '
76