From 122da6901e2a29d0748c6ac423f8f7532af01141 Mon Sep 17 00:00:00 2001 From: likepeng Date: Mon, 25 Dec 2023 16:42:36 +0800 Subject: [PATCH] support docker --- CMakeLists.txt | 7 ++++-- docker/README.md | 29 +++++++++++++++++++++ docker/docker_build.bash | 49 ++++++++++++++++++++++++++++++++++++ docker/ubuntu2004.dockerfile | 45 +++++++++++++++++++++++++++++++++ docker/ubuntu2004.sourcelist | 4 +++ 5 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 docker/README.md create mode 100644 docker/docker_build.bash create mode 100644 docker/ubuntu2004.dockerfile create mode 100644 docker/ubuntu2004.sourcelist diff --git a/CMakeLists.txt b/CMakeLists.txt index e959c79..a5f0e5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(myframe VERSION 0.9.1) +project(myframe VERSION 0.9.2) ### option option(MYFRAME_USE_CV "Using conditional variables for thread communication" OFF) @@ -72,8 +72,11 @@ install(FILES PERMISSIONS OWNER_READ GROUP_READ WORLD_READ DESTINATION . ) +INSTALL(PROGRAMS + "tools/gen_mod_proj.py" + DESTINATION ${MYFRAME_BIN_DIR} +) install(DIRECTORY templates DESTINATION .) -install(DIRECTORY tools DESTINATION .) install(DIRECTORY conf DESTINATION .) install(DIRECTORY DESTINATION ${MYFRAME_LOG_DIR}) install(DIRECTORY DESTINATION ${MYFRAME_SERVICE_DIR}) diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..6c1c545 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,29 @@ +# myframe docker +主要用于创建myframe docker容器镜像; +包含编译好的myframe,可以运行example,benchmark和创建运行组件工程。 + +## 目录 +myframe安装目录:`/usr/local` + +## 构建docker镜像 +```sh +bash docker_build.bash +``` + +## 创建运行docker容器 +```sh +docker run -itd \ + --name "myframe_run" \ + myframe:${} \ + /bin/bash +``` + +## 进入docker容器 +```sh +docker exec -it \ + -it "myframe_run" \ + /bin/bash +``` + +## 在docker中开发 +[开发手册](../doc/development_guide.md) diff --git a/docker/docker_build.bash b/docker/docker_build.bash new file mode 100644 index 0000000..65b8287 --- /dev/null +++ b/docker/docker_build.bash @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +readonly PWD0="$(dirname "$(readlink -fn "$0")")" +readonly MYFRAME_ROOT="$(dirname ${PWD0})" + +readonly IMAGE_NAME="myframe" + +set -e + +function main { + cd "${PWD0}" + + local -a cmd=() + if command -v docker; then + cmd+=("docker" "build") + else + echo "No docker existed!" + exit 1 + fi + + local arc="$(uname -m)" + case "${arc}" in + "aarch64" | "arm64") + arc="aarch64" + ;; + "x86_64" | "amd64") + arc="amd64" + ;; + *) + echo "Unknown arch: ${arc}" + exit 1 + ;; + esac + + local tag="${arc}-$1" + + "${cmd[@]}" \ + --build-arg myframe_version=$1 \ + --ulimit nofile=102400:102400 \ + -f "ubuntu2004.dockerfile" \ + -t "${IMAGE_NAME}:${tag}" \ + "${MYFRAME_ROOT}" +} + +if [ "$#" -ne 1 ]; then + echo "Error: No arguments provided. Usage: $0 \"myframe_version\"" + exit 1 +fi + +main "$@" diff --git a/docker/ubuntu2004.dockerfile b/docker/ubuntu2004.dockerfile new file mode 100644 index 0000000..0461929 --- /dev/null +++ b/docker/ubuntu2004.dockerfile @@ -0,0 +1,45 @@ +FROM docker.io/library/ubuntu:20.04 +SHELL ["/bin/bash", "-c"] + +ENV DEBIAN_FRONTEND noninteractive +COPY docker/ubuntu2004.sourcelist /etc/apt/sources.list +RUN yes | unminimize +RUN apt update \ + && apt install -y --no-install-recommends \ + build-essential cmake \ + wget python3 vim \ + libunwind-dev libgflags-dev + +WORKDIR /tmp +RUN wget -q --content-disposition --no-check-certificate \ + https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/1.9.5.tar.gz +RUN tar -xf jsoncpp-1.9.5.tar.gz \ + && cmake -S jsoncpp-1.9.5 -B build-jsoncpp \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DBUILD_OBJECT_LIBS=OFF \ + -DJSONCPP_WITH_TESTS=OFF \ + -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF \ + -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF \ + && cmake --build build-jsoncpp --target install \ + && rm -rf jsoncpp-1.9.5.tar.gz jsoncpp-1.9.5 build-jsoncpp + +RUN wget -q --content-disposition --no-check-certificate \ + https://github.com/google/glog/archive/refs/tags/v0.6.0.tar.gz +RUN tar -xf glog-0.6.0.tar.gz \ + && cmake -S glog-0.6.0 -B build-glog \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DWITH_PKGCONFIG=OFF \ + -DWITH_GTEST=OFF \ + && cmake --build build-glog --target install \ + && rm -rf glog-0.6.0.tar.gz glog-0.6.0 build-glog + +ARG myframe_version=latest +RUN wget -q --content-disposition --no-check-certificate \ + https://github.com/lkpworkspace/myframe/archive/refs/tags/v${myframe_version}.tar.gz +RUN tar -xf myframe-${myframe_version}.tar.gz +RUN cmake -S myframe-${myframe_version} -B build-myframe \ + -DCMAKE_CXX_STANDARD=17 \ + -DCMAKE_CXX_STANDARD_REQUIRED=ON \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + && cmake --build build-myframe --target install \ + && rm -rf myframe-${myframe_version}.tar.gz myframe-${myframe_version} build-myframe diff --git a/docker/ubuntu2004.sourcelist b/docker/ubuntu2004.sourcelist new file mode 100644 index 0000000..6840a5a --- /dev/null +++ b/docker/ubuntu2004.sourcelist @@ -0,0 +1,4 @@ +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse