Skip to content

Commit

Permalink
support docker
Browse files Browse the repository at this point in the history
  • Loading branch information
lkpworkspace committed Dec 25, 2023
1 parent 9b4e793 commit 122da69
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 2 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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})
Expand Down
29 changes: 29 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# myframe docker
主要用于创建myframe docker容器镜像;
包含编译好的myframe,可以运行example,benchmark和创建运行组件工程。

## 目录
myframe安装目录:`/usr/local`

## 构建docker镜像
```sh
bash docker_build.bash <myframe_version>
```

## 创建运行docker容器
```sh
docker run -itd \
--name "myframe_run" \
myframe:${<myframe_version>} \
/bin/bash
```

## 进入docker容器
```sh
docker exec -it \
-it "myframe_run" \
/bin/bash
```

## 在docker中开发
[开发手册](../doc/development_guide.md)
49 changes: 49 additions & 0 deletions docker/docker_build.bash
Original file line number Diff line number Diff line change
@@ -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 "$@"
45 changes: 45 additions & 0 deletions docker/ubuntu2004.dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions docker/ubuntu2004.sourcelist
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 122da69

Please sign in to comment.