Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Docker instructions and build scripts #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docker/build.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get clean && \
apt-get autoclean

RUN apt update && \
apt install -y \
build-essential gdb vim htop cmake \
apt-utils net-tools clang-format \
wget bzip2 file python3-dev \
python3-setuptools unzip zlib1g-dev


COPY install /tmp/install

RUN /tmp/install/build_boost.sh
# RUN /tmp/install/install_abseil.sh
RUN /tmp/install/build_protobuf.sh
RUN /tmp/install/build_muduo.sh

WORKDIR /work


19 changes: 19 additions & 0 deletions docker/install/build_boost.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

cd "$(dirname "${BASH_SOURCE[0]}")"

wget https://archives.boost.io/release/1.69.0/source/boost_1_69_0.tar.gz

VERSION="1_69_0"
PKG_NAME="boost_${VERSION}.tar.gz"

tar xzf "${PKG_NAME}"
pushd "boost_${VERSION}"
./bootstrap.sh
./b2 --prefix=/usr/local variant=release install -j$(nproc)
popd

ldconfig

# Clean up
rm -rf "boost_${VERSION}" "${PKG_NAME}"
29 changes: 29 additions & 0 deletions docker/install/build_muduo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "${BASH_SOURCE[0]}")"

# wget https://github.com/chenshuo/muduo/archive/refs/tags/v2.0.2.tar.gz

# Install muduo.
THREAD_NUM=$(nproc)
VERSION="2.0.2"
PKG_NAME="muduo-${VERSION}.tar.gz"

tar xzf "${PKG_NAME}"
pushd "muduo-${VERSION}"
mkdir build && cd build
cmake .. \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_INSTALL_PREFIX=/usr/local
make -j$(nproc)
make install
popd

ldconfig

# Clean up
rm -rf "muduo-${VERSION}" "${PKG_NAME}"
32 changes: 32 additions & 0 deletions docker/install/build_protobuf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "${BASH_SOURCE[0]}")"

THREAD_NUM=$(nproc)

# wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.4/protobuf-cpp-3.12.4.tar.gz

# Install proto.
VERSION="3.12.4"
PKG_NAME="protobuf-cpp-${VERSION}.tar.gz"

tar xzf "${PKG_NAME}"
pushd protobuf-${VERSION}
mkdir cmake/build && cd cmake/build

cmake .. \
-DBUILD_SHARED_LIBS=ON \
-Dprotobuf_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX:PATH="/usr/local" \
-DCMAKE_BUILD_TYPE=Release

make -j$(nproc)
make install
popd

ldconfig

# Clean up
rm -rf PKG_NAME protobuf-${VERSION}
Binary file added docker/install/muduo-2.0.2.tar.gz
Binary file not shown.
Binary file added docker/install/protobuf-cpp-3.12.4.tar.gz
Binary file not shown.
8 changes: 8 additions & 0 deletions docker/scripts/into_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

xhost +local:root 1>/dev/null 2>&1
docker exec \
-u root \
-it kv_raft \
/bin/bash
xhost -local:root 1>/dev/null 2>&1
37 changes: 37 additions & 0 deletions docker/scripts/run_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

MONITOR_HOME_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"

display=""
if [ -z ${DISPLAY} ];then
display=":1"
else
display="${DISPLAY}"
fi

local_host="$(hostname)"
user="${USER}"
uid="$(id -u)"
group="$(id -g -n)"
gid="$(id -g)"


echo "stop and rm docker"
docker stop kv_raft > /dev/null
docker rm -v -f kv_raft > /dev/null

echo "start docker"
docker run -it -d \
--privileged=true \
--name kv_raft \
-e DISPLAY=$display \
-e DOCKER_USER="${user}" \
-e USER="${user}" \
-e DOCKER_USER_ID="${uid}" \
-e DOCKER_GRP="${group}" \
-e DOCKER_GRP_ID="${gid}" \
-e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
-v ${MONITOR_HOME_DIR}:/work \
-v ${XDG_RUNTIME_DIR}:${XDG_RUNTIME_DIR} \
--network host \
kv_raft:22.04
33 changes: 33 additions & 0 deletions docs/Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## 1.通过项目中dockerfile文件,构建项目镜像

```bash
cd KVstorageBaseRaft-cpp/docker
docker build --network host -t kv_raft:22.04 -f build.dockerfile .
```

## 2.进入docker容器

```bash
cd KVstorageBaseRaft-cpp/docker/scripts
#启动容器
./run_docker.sh
#进入容器
./into_docker.sh
```

## 3.在docker容器内编译代码

```bash
mkdir build
cd build
cmake ..
make -j4
```

## 4.容器内启动程序

```bash
cd ../bin
./raftCoreRun -n 3 -f test.conf
```