summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Bentele2020-11-02 09:44:34 +0100
committerManuel Bentele2020-11-02 09:44:34 +0100
commit2ac947f4ec8a34a6c302a76260f646b36a2078b1 (patch)
tree8c2c053e55f8edafbdf292d34ef8d3bec80b3174
parent[CLIENT] format output of program help text (diff)
downloaddnbd3-2ac947f4ec8a34a6c302a76260f646b36a2078b1.tar.gz
dnbd3-2ac947f4ec8a34a6c302a76260f646b36a2078b1.tar.xz
dnbd3-2ac947f4ec8a34a6c302a76260f646b36a2078b1.zip
[BUILD] add CMake support to build docker images based on Archlinux
-rw-r--r--CMakeLists.txt17
-rw-r--r--cmake/DockerImage.cmake10
-rw-r--r--pkg/docker/archlinux_dockerfile28
-rw-r--r--pkg/docker/ubuntu-20-04_dockerfile (renamed from pkg/docker/Dockerfile)0
4 files changed, 46 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 42f259c..219ec00 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -197,11 +197,20 @@ if(CMAKE_BUILD_TYPE MATCHES Release)
if(NOT DNBD3_KERNEL_MODULE AND DNBD3_PACKAGE_DOCKER)
find_package(Docker REQUIRED)
include(DockerImage)
- set(DOCKER_FILE ${CMAKE_SOURCE_DIR}/pkg/docker/Dockerfile)
+
set(DOCKER_TAG ${CPACK_PACKAGE_NAME}:${REPOSITORY_VERSION_FULL})
- set(PACKAGE_FILE ${CPACK_PACKAGE_NAME}_${REPOSITORY_VERSION_FULL}_${CMAKE_SYSTEM_PROCESSOR}.deb)
- set(DOCKER_IMAGE ${CPACK_PACKAGE_NAME}_${REPOSITORY_VERSION_FULL}_${CMAKE_SYSTEM_PROCESSOR}_ubuntu-20-04_docker.tar)
- add_docker_image(docker-ubuntu-20-04 ${DOCKER_IMAGE} ${DOCKER_FILE} ${DOCKER_TAG} ${PACKAGE_FILE} ${CMAKE_BINARY_DIR})
+
+ # define Ubuntu docker image
+ set(DOCKER_FILE_UBUNTU ${CMAKE_SOURCE_DIR}/pkg/docker/ubuntu-20-04_dockerfile)
+ set(PACKAGE_FILE_UBUNTU ${CPACK_PACKAGE_NAME}_${REPOSITORY_VERSION_FULL}_${CMAKE_SYSTEM_PROCESSOR}.deb)
+ set(DOCKER_IMAGE_UBUNTU ${CPACK_PACKAGE_NAME}_${REPOSITORY_VERSION_FULL}_${CMAKE_SYSTEM_PROCESSOR}_ubuntu-20-04_docker.tar)
+ add_docker_image(docker-ubuntu-20-04 ${DOCKER_IMAGE_UBUNTU} ${DOCKER_FILE_UBUNTU} ${DOCKER_TAG} ${PACKAGE_FILE_UBUNTU} ${CMAKE_BINARY_DIR})
+
+ # define Archlinux docker image
+ set(DOCKER_FILE_ARCHLINUX ${CMAKE_SOURCE_DIR}/pkg/docker/archlinux_dockerfile)
+ set(PACKAGE_FILE_ARCHLINUX ${CPACK_PACKAGE_NAME}_${REPOSITORY_VERSION_FULL}_${CMAKE_SYSTEM_PROCESSOR}.tar.gz)
+ set(DOCKER_IMAGE_ARCHLINUX ${CPACK_PACKAGE_NAME}_${REPOSITORY_VERSION_FULL}_${CMAKE_SYSTEM_PROCESSOR}_archlinux_docker.tar)
+ add_docker_image(docker-archlinux ${DOCKER_IMAGE_ARCHLINUX} ${DOCKER_FILE_ARCHLINUX} ${DOCKER_TAG} ${PACKAGE_FILE_ARCHLINUX} ${CMAKE_BINARY_DIR})
endif(NOT DNBD3_KERNEL_MODULE AND DNBD3_PACKAGE_DOCKER)
endif(CMAKE_BUILD_TYPE MATCHES Release)
diff --git a/cmake/DockerImage.cmake b/cmake/DockerImage.cmake
index 54751e4..83f4b9d 100644
--- a/cmake/DockerImage.cmake
+++ b/cmake/DockerImage.cmake
@@ -3,16 +3,16 @@
# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
#
+# 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)
+
# 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}
diff --git a/pkg/docker/archlinux_dockerfile b/pkg/docker/archlinux_dockerfile
new file mode 100644
index 0000000..ea6145b
--- /dev/null
+++ b/pkg/docker/archlinux_dockerfile
@@ -0,0 +1,28 @@
+# use Archlinux as base image
+FROM archlinux:latest
+
+# declare arguments that should be set by 'docker build --build-arg ...'
+ARG DNBD3_PACKAGE_FILE_NAME
+
+# copy built package file from host to docker image
+COPY ${DNBD3_PACKAGE_FILE_NAME} /tmp
+
+# install required dependencies
+RUN pacman --noconfirm -Sy
+RUN pacman --noconfirm -S fuse2 jansson
+
+# install installation package
+RUN tar -xf /tmp/${DNBD3_PACKAGE_FILE_NAME} --strip-components=1 -C /
+
+# use default config for dnbd3-server
+RUN ln -s /etc/dnbd3-server/sample/server.conf /etc/dnbd3-server
+RUN ln -s /etc/dnbd3-server/sample/alt-servers /etc/dnbd3-server
+
+# make default storage point for dnbd3-server
+RUN mkdir -p /mnt/storage
+
+# expose the port of the dnbd3-server to the host
+EXPOSE 5003
+
+# run dnbd3-server
+CMD [ "dnbd3-server", "-n" ]
diff --git a/pkg/docker/Dockerfile b/pkg/docker/ubuntu-20-04_dockerfile
index ad2adcb..ad2adcb 100644
--- a/pkg/docker/Dockerfile
+++ b/pkg/docker/ubuntu-20-04_dockerfile