Skip to content

Commit f19daf1

Browse files
packaging: add git commit info (#5049)
* packaging: generate git commit info Signed-off-by: Patrick Stephens <pat@calyptia.com> * packaging: print git commit info Signed-off-by: Patrick Stephens <pat@calyptia.com> * packaging: print git commit info Signed-off-by: Patrick Stephens <pat@calyptia.com> * packaging: tidy up comments Signed-off-by: Patrick Stephens <pat@calyptia.com>
1 parent 30a54ef commit f19daf1

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
.git
1+
# We need the git commit info
2+
# .git
23
build/**
34
dockerfiles/**

CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,18 @@ if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
317317
endif()
318318
endif()
319319

320+
# Extract Git commit information for debug output.
321+
# Note that this is only set when cmake is run, the intent here is to use in CI for verification of releases so is acceptable.
322+
# For a better solution see https://jonathanhamberg.com/post/cmake-embedding-git-hash/ but this is simple and easy.
323+
find_package(Git)
324+
# If we do not have Git or this is not a Git repo or another error this just is ignored and we have no output at runtime.
325+
execute_process(COMMAND
326+
"${GIT_EXECUTABLE}" log -1 --format=%H
327+
WORKING_DIRECTORY "${FLB_ROOT}"
328+
OUTPUT_VARIABLE FLB_GIT_HASH
329+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
330+
message(STATUS "Git hash: ${FLB_GIT_HASH}")
331+
320332
# Optional features like Stream Processor and Record Accessor needs Flex
321333
# and Bison to generate it parsers.
322334
find_package(FLEX 2)

dockerfiles/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ RUN apt-get update && \
3838
curl \
3939
ca-certificates \
4040
cmake \
41+
git \
4142
make \
4243
tar \
4344
libssl-dev \

include/fluent-bit/flb_version.h.in

+2
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@
3333
FLB_VERSION_PATCH)
3434
#define FLB_VERSION_STR "@FLB_VERSION_STR@"
3535

36+
#define FLB_GIT_HASH "@FLB_GIT_HASH@"
37+
3638
#endif

src/fluent-bit.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static void flb_version()
9797
#else
9898
printf("Fluent Bit v%s\n", FLB_VERSION_STR);
9999
#endif
100+
printf("Git commit: %s\n", FLB_GIT_HASH);
100101

101102
exit(EXIT_SUCCESS);
102103
}
@@ -111,7 +112,7 @@ static void flb_banner()
111112
fprintf(stderr,
112113
"%sFluent Bit v%s%s\n", ANSI_BOLD, FLB_VERSION_STR, ANSI_RESET);
113114
#endif
114-
115+
fprintf(stderr, "* Git commit: %s\n", FLB_GIT_HASH);
115116
fprintf(stderr, "* %sCopyright (C) 2015-2021 The Fluent Bit Authors%s\n",
116117
ANSI_BOLD ANSI_YELLOW, ANSI_RESET);
117118
fprintf(stderr, "* Fluent Bit is a CNCF sub-project under the "

0 commit comments

Comments
 (0)