From bada37dcb1a066307b994e1e74fb4b1ee37f5144 Mon Sep 17 00:00:00 2001 From: Ali Ince Date: Wed, 5 Dec 2018 10:00:49 +0000 Subject: [PATCH] Pass Git hash to docker build in CI script --- ci/linux-package.sh | 4 +++- ci/linux/Dockerfile.package-alpine-3.8 | 2 ++ ci/linux/Dockerfile.package-centos-7 | 2 ++ ci/linux/Dockerfile.package-ubuntu-16.04 | 2 ++ ci/linux/Dockerfile.package-ubuntu-18.04 | 2 ++ cmake/GitHash.cmake | 27 ++++++++++++++---------- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ci/linux-package.sh b/ci/linux-package.sh index 06ea3ef7..157b129b 100755 --- a/ci/linux-package.sh +++ b/ci/linux-package.sh @@ -12,7 +12,9 @@ if [[ ! -f "$BASE/linux/Dockerfile.package-$1" ]]; then exit 1 fi -docker image build --build-arg SEABOLT_VERSION=$SEABOLT_VERSION -t seabolt-package -f $BASE/linux/Dockerfile.package-$1 $BASE/.. +GIT_HASH=$(git log -1 --pretty=format:%h $BASE 2>/dev/null || echo "unknown") + +docker image build --build-arg SEABOLT_VERSION=$SEABOLT_VERSION --build-arg SEABOLT_VERSION_HASH=$GIT_HASH -t seabolt-package -f $BASE/linux/Dockerfile.package-$1 $BASE/.. if [[ "$?" -ne "0" ]]; then echo "FATAL: docker image build failed, possible compilation failure." exit 1 diff --git a/ci/linux/Dockerfile.package-alpine-3.8 b/ci/linux/Dockerfile.package-alpine-3.8 index 6d3a5de1..02355603 100644 --- a/ci/linux/Dockerfile.package-alpine-3.8 +++ b/ci/linux/Dockerfile.package-alpine-3.8 @@ -1,7 +1,9 @@ FROM alpine:3.8 RUN apk add --no-cache ca-certificates cmake make g++ openssl-dev git ARG SEABOLT_VERSION +ARG SEABOLT_VERSION_HASH ENV SEABOLT_VERSION=$SEABOLT_VERSION +ENV SEABOLT_VERSION_HASH=$SEABOLT_VERSION_HASH ADD . /tmp/seabolt WORKDIR /tmp/seabolt/build-docker RUN cmake -D CMAKE_BUILD_TYPE=Release /tmp/seabolt \ diff --git a/ci/linux/Dockerfile.package-centos-7 b/ci/linux/Dockerfile.package-centos-7 index f18d0f69..2f3f9c2d 100644 --- a/ci/linux/Dockerfile.package-centos-7 +++ b/ci/linux/Dockerfile.package-centos-7 @@ -3,7 +3,9 @@ RUN yum -y install openssl-devel openssl-static wget pkg-config ca-certificates && (mkdir -p /cmake && wget --no-verbose --output-document=- https://cmake.org/files/v3.12/cmake-3.12.3-Linux-x86_64.tar.gz | tar xvz -C /cmake --strip 1) \ && yum -y clean all ARG SEABOLT_VERSION +ARG SEABOLT_VERSION_HASH ENV SEABOLT_VERSION=$SEABOLT_VERSION +ENV SEABOLT_VERSION_HASH=$SEABOLT_VERSION_HASH ADD . /tmp/seabolt WORKDIR /tmp/seabolt/build-docker RUN /cmake/bin/cmake -D CMAKE_BUILD_TYPE=Release /tmp/seabolt \ diff --git a/ci/linux/Dockerfile.package-ubuntu-16.04 b/ci/linux/Dockerfile.package-ubuntu-16.04 index a6e14cca..bd2f4b36 100644 --- a/ci/linux/Dockerfile.package-ubuntu-16.04 +++ b/ci/linux/Dockerfile.package-ubuntu-16.04 @@ -4,7 +4,9 @@ RUN apt-get update \ && (mkdir -p /cmake && wget --no-verbose --output-document=- https://cmake.org/files/v3.12/cmake-3.12.3-Linux-x86_64.tar.gz | tar xvz -C /cmake --strip 1) \ && rm -rf /var/lib/apt/lists/* ARG SEABOLT_VERSION +ARG SEABOLT_VERSION_HASH ENV SEABOLT_VERSION=$SEABOLT_VERSION +ENV SEABOLT_VERSION_HASH=$SEABOLT_VERSION_HASH ADD . /tmp/seabolt WORKDIR /tmp/seabolt/build-docker RUN /cmake/bin/cmake -D CMAKE_BUILD_TYPE=Release /tmp/seabolt \ diff --git a/ci/linux/Dockerfile.package-ubuntu-18.04 b/ci/linux/Dockerfile.package-ubuntu-18.04 index 9137d202..fb4b68c2 100644 --- a/ci/linux/Dockerfile.package-ubuntu-18.04 +++ b/ci/linux/Dockerfile.package-ubuntu-18.04 @@ -4,7 +4,9 @@ RUN apt-get update \ && (mkdir -p /cmake && wget --no-verbose --output-document=- https://cmake.org/files/v3.12/cmake-3.12.3-Linux-x86_64.tar.gz | tar xvz -C /cmake --strip 1) \ && rm -rf /var/lib/apt/lists/* ARG SEABOLT_VERSION +ARG SEABOLT_VERSION_HASH ENV SEABOLT_VERSION=$SEABOLT_VERSION +ENV SEABOLT_VERSION_HASH=$SEABOLT_VERSION_HASH ADD . /tmp/seabolt WORKDIR /tmp/seabolt/build-docker RUN /cmake/bin/cmake -D CMAKE_BUILD_TYPE=Release /tmp/seabolt \ diff --git a/cmake/GitHash.cmake b/cmake/GitHash.cmake index aa9c1c82..40dc659e 100644 --- a/cmake/GitHash.cmake +++ b/cmake/GitHash.cmake @@ -1,18 +1,23 @@ # in case Git is not available, we default to "unknown" set(VERSION_HASH "unknown") -# find Git and if available set GIT_HASH variable -find_package(Git QUIET) -if (GIT_FOUND) - execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h - OUTPUT_VARIABLE VERSION_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET - ) -endif () +if (DEFINED ENV{SEABOLT_VERSION_HASH}) + set(VERSION_HASH $ENV{SEABOLT_VERSION_HASH}) + message(STATUS "Using Git hash from environment: ${VERSION_HASH}") +else () + # find Git and if available set GIT_HASH variable + find_package(Git QUIET) + if (GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h + OUTPUT_VARIABLE VERSION_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + endif () -message(STATUS "Git hash is ${VERSION_HASH}") + message(STATUS "Using Git hash from git command: ${VERSION_HASH}") +endif () # generate file version.hpp based on version.hpp.in configure_file(