summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/DockerImage.cmake25
-rw-r--r--cmake/FindDocker.cmake20
2 files changed, 45 insertions, 0 deletions
diff --git a/cmake/DockerImage.cmake b/cmake/DockerImage.cmake
new file mode 100644
index 0000000..54751e4
--- /dev/null
+++ b/cmake/DockerImage.cmake
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
+#
+
+# macro to build a docker image based on a provided Dockerfile and an installation package
+macro(add_docker_image TARGET_NAME DOCKER_IMAGE DOCKER_FILE DOCKER_TAG PACKAGE_FILE BUILD_DIR)
+ get_filename_component(PACKAGE_FILE_PATH ${PACKAGE_FILE} PATH)
+ get_filename_component(PACKAGE_FILE_NAME ${PACKAGE_FILE} NAME)
+
+ # create a pseudo target to do packaging before docker image is built
+ add_custom_target(package_docker
+ COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target package
+ VERBATIM)
+
+ # commands and target to build docker image
+ add_custom_command(OUTPUT ${DOCKER_IMAGE}
+ COMMAND docker image build -t ${DOCKER_TAG} --file ${DOCKER_FILE} --build-arg DNBD3_PACKAGE_FILE_NAME=${PACKAGE_FILE_NAME} ${BUILD_DIR}
+ COMMAND docker image save -o ${DOCKER_IMAGE} ${DOCKER_TAG}
+ COMMAND docker image rm ${DOCKER_TAG}
+ DEPENDS ${DOCKER_FILE}
+ package_docker)
+ add_custom_target(${TARGET_NAME}
+ DEPENDS ${DOCKER_IMAGE})
+endmacro(add_docker_image TARGET_NAME DOCKER_IMAGE DOCKER_FILE PACKAGE_FILE)
diff --git a/cmake/FindDocker.cmake b/cmake/FindDocker.cmake
new file mode 100644
index 0000000..ef3046d
--- /dev/null
+++ b/cmake/FindDocker.cmake
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
+#
+
+find_program(Docker_EXECUTABLE NAMES docker)
+
+if(Docker_EXECUTABLE)
+ execute_process(COMMAND docker version --format "{{.Server.Version}}"
+ OUTPUT_VARIABLE Docker_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+endif(Docker_EXECUTABLE)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Docker
+ FOUND_VAR Docker_FOUND
+ REQUIRED_VARS Docker_EXECUTABLE
+ VERSION_VAR Docker_VERSION
+ FAIL_MESSAGE "Docker is not available! Please install docker to build and run containers!")
+