Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Commit bada37d

Browse files
committed
Pass Git hash to docker build in CI script
1 parent 940a24b commit bada37d

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

ci/linux-package.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ if [[ ! -f "$BASE/linux/Dockerfile.package-$1" ]]; then
1212
exit 1
1313
fi
1414

15-
docker image build --build-arg SEABOLT_VERSION=$SEABOLT_VERSION -t seabolt-package -f $BASE/linux/Dockerfile.package-$1 $BASE/..
15+
GIT_HASH=$(git log -1 --pretty=format:%h $BASE 2>/dev/null || echo "unknown")
16+
17+
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/..
1618
if [[ "$?" -ne "0" ]]; then
1719
echo "FATAL: docker image build failed, possible compilation failure."
1820
exit 1

ci/linux/Dockerfile.package-alpine-3.8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
FROM alpine:3.8
22
RUN apk add --no-cache ca-certificates cmake make g++ openssl-dev git
33
ARG SEABOLT_VERSION
4+
ARG SEABOLT_VERSION_HASH
45
ENV SEABOLT_VERSION=$SEABOLT_VERSION
6+
ENV SEABOLT_VERSION_HASH=$SEABOLT_VERSION_HASH
57
ADD . /tmp/seabolt
68
WORKDIR /tmp/seabolt/build-docker
79
RUN cmake -D CMAKE_BUILD_TYPE=Release /tmp/seabolt \

ci/linux/Dockerfile.package-centos-7

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ RUN yum -y install openssl-devel openssl-static wget pkg-config ca-certificates
33
&& (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) \
44
&& yum -y clean all
55
ARG SEABOLT_VERSION
6+
ARG SEABOLT_VERSION_HASH
67
ENV SEABOLT_VERSION=$SEABOLT_VERSION
8+
ENV SEABOLT_VERSION_HASH=$SEABOLT_VERSION_HASH
79
ADD . /tmp/seabolt
810
WORKDIR /tmp/seabolt/build-docker
911
RUN /cmake/bin/cmake -D CMAKE_BUILD_TYPE=Release /tmp/seabolt \

ci/linux/Dockerfile.package-ubuntu-16.04

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ RUN apt-get update \
44
&& (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) \
55
&& rm -rf /var/lib/apt/lists/*
66
ARG SEABOLT_VERSION
7+
ARG SEABOLT_VERSION_HASH
78
ENV SEABOLT_VERSION=$SEABOLT_VERSION
9+
ENV SEABOLT_VERSION_HASH=$SEABOLT_VERSION_HASH
810
ADD . /tmp/seabolt
911
WORKDIR /tmp/seabolt/build-docker
1012
RUN /cmake/bin/cmake -D CMAKE_BUILD_TYPE=Release /tmp/seabolt \

ci/linux/Dockerfile.package-ubuntu-18.04

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ RUN apt-get update \
44
&& (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) \
55
&& rm -rf /var/lib/apt/lists/*
66
ARG SEABOLT_VERSION
7+
ARG SEABOLT_VERSION_HASH
78
ENV SEABOLT_VERSION=$SEABOLT_VERSION
9+
ENV SEABOLT_VERSION_HASH=$SEABOLT_VERSION_HASH
810
ADD . /tmp/seabolt
911
WORKDIR /tmp/seabolt/build-docker
1012
RUN /cmake/bin/cmake -D CMAKE_BUILD_TYPE=Release /tmp/seabolt \

cmake/GitHash.cmake

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# in case Git is not available, we default to "unknown"
22
set(VERSION_HASH "unknown")
33

4-
# find Git and if available set GIT_HASH variable
5-
find_package(Git QUIET)
6-
if (GIT_FOUND)
7-
execute_process(
8-
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h
9-
OUTPUT_VARIABLE VERSION_HASH
10-
OUTPUT_STRIP_TRAILING_WHITESPACE
11-
ERROR_QUIET
12-
)
13-
endif ()
4+
if (DEFINED ENV{SEABOLT_VERSION_HASH})
5+
set(VERSION_HASH $ENV{SEABOLT_VERSION_HASH})
6+
message(STATUS "Using Git hash from environment: ${VERSION_HASH}")
7+
else ()
8+
# find Git and if available set GIT_HASH variable
9+
find_package(Git QUIET)
10+
if (GIT_FOUND)
11+
execute_process(
12+
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h
13+
OUTPUT_VARIABLE VERSION_HASH
14+
OUTPUT_STRIP_TRAILING_WHITESPACE
15+
ERROR_QUIET
16+
)
17+
endif ()
1418

15-
message(STATUS "Git hash is ${VERSION_HASH}")
19+
message(STATUS "Using Git hash from git command: ${VERSION_HASH}")
20+
endif ()
1621

1722
# generate file version.hpp based on version.hpp.in
1823
configure_file(

0 commit comments

Comments
 (0)