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

Commit

Permalink
Pass Git hash to docker build in CI script
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ince committed Dec 5, 2018
1 parent 940a24b commit bada37d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
4 changes: 3 additions & 1 deletion ci/linux-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ci/linux/Dockerfile.package-alpine-3.8
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions ci/linux/Dockerfile.package-centos-7
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions ci/linux/Dockerfile.package-ubuntu-16.04
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions ci/linux/Dockerfile.package-ubuntu-18.04
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
27 changes: 16 additions & 11 deletions cmake/GitHash.cmake
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit bada37d

Please sign in to comment.