Skip to content

Commit

Permalink
Update: add dockerfile and .github workflow for build docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
musnows committed Jan 30, 2025
1 parent 42803bf commit a7068b5
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: gcnv2slam-latest
#触发器设置
on:
push:
branches: [ "cpu" ]

# 项目任务,任务之间可以并行调度
jobs:
build:
# 选择云端运行的环境
runs-on: ubuntu-latest
steps:
#u ses代表使用一个模块,此处使用的是checkout模块,将github项目文件导入到当前环境中
- uses: actions/checkout@v3
# 使用with跟在后面来为前面的模块输入参数
with:
submodules: 'true'
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
# 这里用到了github的secrets功能,避免账户和密码随仓库泄露
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
# 设置当前的发行版本tag
- name: Release version
id: release_version
run: |
app_version=$(cat docker/version.py | sed -ne "s/APP_VERSION[[:space:]]*=[[:space:]]*'v\(.*\)'/\1/p")
echo "app_version=$app_version"
echo "app_version=$app_version" >> $GITHUB_ENV
# 开始构建镜像
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: dockerfile
build-args: |
GITHUB_TOKEN=${{ secrets.RELEASE_TOKEN }}
platforms: |
linux/amd64
linux/arm64
linux/arm
push: true
# 指定用户/仓库名
tags: |
${{ secrets.DOCKER_USERNAME }}/gcnv2slam:latest
${{ secrets.DOCKER_USERNAME }}/gcnv2slam:${{ env.app_version }}
22 changes: 22 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

## GCNV2_SLAM的安装环境docker镜像

Use the following command to build an image

```bash
docker build --network host -f dockerfile -t gcnv2slam:latest .
```

Note that this image only contains the necessary runtime environment and does not include the GCNv2 project itself. The project ontology needs to be mapped to a directory for use

```bash
# docker run to create a docker container
./docker_run.sh
# docker into for enter docker container
./docker_into.sh
# in container `cd /work` to compile code
cd /work
# before run this scripts
# modify TORCH_PATH to /tmp/install/pytorch/torch/lib/tmp_install/share/cmake/Torch
./build.sh
```
8 changes: 8 additions & 0 deletions docker/docker_into.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 gcnv2 \
/bin/bash
xhost -local:root 1>/dev/null 2>&1
37 changes: 37 additions & 0 deletions docker/docker_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

GCN_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 gcnv2 > /dev/null
docker rm -v -f gcnv2 > /dev/null

echo "start docker"
docker run -it -d \
--name gcnv2 \
-e DISPLAY=$display \
--privileged=true \
-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 ${GCN_HOME_DIR}:/work \
-v ${XDG_RUNTIME_DIR}:${XDG_RUNTIME_DIR} \
--net host \
gcnv2slam:latest
86 changes: 86 additions & 0 deletions docker/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
FROM ubuntu:18.04

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai

SHELL ["/bin/bash", "-c"]

# 工具组
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y \
apt-utils \
curl wget \
cmake make automake \
openssh-server \
net-tools \
vim \
git \
gcc g++ \
unzip

# x11依赖项
RUN apt-get install -y \
libx11-xcb1 \
libfreetype6 \
libdbus-1-3 \
libfontconfig1 \
libxkbcommon0 \
libxkbcommon-x11-0

# python
RUN apt-get install -y \
python-dev \
python-pip \
python3-dev \
python3-pip \
python-all-dev

# opencv 需要
RUN echo -e "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe\n\
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe\n\
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe\n\
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe\n\
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe\n\
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe\n\
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe" >> /etc/apt/sources.list && \
apt-get -y update && \
apt-get install -y libjasper1 libjasper-dev

# opencv需要
RUN apt-get install -y \
libc-ares-dev \
libssl-dev \
build-essential \
libboost-all-dev \
libgtk2.0-dev \
libavcodec-dev \
libavformat-dev \
libjpeg.dev \
libtiff5.dev \
libswscale-dev

# pangolin需要
RUN apt-get install -y \
libgl1-mesa-dev \
libglew-dev \
libboost-dev \
libboost-thread-dev \
libboost-filesystem-dev \
libpython2.7-dev \
libglu1-mesa-dev freeglut3-dev

COPY install/pangolin /tmp/install/pangolin
RUN chmod 777 /tmp/install/pangolin/install_pangolin.sh && \
/tmp/install/pangolin/install_pangolin.sh

COPY install/opencv /tmp/install/opencv
RUN chmod 777 /tmp/install/opencv/install_opencv.sh && \
/tmp/install/opencv/install_opencv.sh

COPY install/eigen /tmp/install/eigen
RUN chmod 777 /tmp/install/eigen/install_eigen.sh && \
/tmp/install/eigen/install_eigen.sh

COPY install/pytorch /tmp/install/pytorch
RUN chmod 777 /tmp/install/pytorch/install_pytorch.sh && \
/tmp/install/pytorch/install_pytorch.sh
Binary file added docker/install/eigen/eigen-3.3.7.tar.gz
Binary file not shown.
27 changes: 27 additions & 0 deletions docker/install/eigen/install_eigen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -e

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

# wget -O eigen-3.3.7.tar.gz https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz
tar -zxvf eigen-3.3.7.tar.gz

pushd eigen-3.3.7
rm -rf build
mkdir build && cd build
cmake ..
make -j$(nproc)
make install
# 拷贝头文件
cp -r /usr/local/include/eigen3/Eigen /usr/local/include
# 刷新动态库
ldconfig
popd

# 编译检测
TEST_FILE=test_eigen
g++ test_eigen.cpp -o $TEST_FILE
./$TEST_FILE

rm -rf eigen-3.3.7.tar.gz eigen-3.3.7 $TEST_FILE
27 changes: 27 additions & 0 deletions docker/install/eigen/test_eigen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
//需要将头文件从 /usr/local/include/eigen3/ 复制到 /usr/local/include
#include <Eigen/Dense>
//using Eigen::MatrixXd;
using namespace Eigen;
using namespace Eigen::internal;
using namespace Eigen::Architecture;
using namespace std;
int main()
{
cout<<"*******************1D-object****************"<<endl;
Vector4d v1;
v1<< 1,2,3,4;
cout<<"v1=\n"<<v1<<endl;

VectorXd v2(3);
v2<<1,2,3;
cout<<"v2=\n"<<v2<<endl;

Array4i v3;
v3<<1,2,3,4;
cout<<"v3=\n"<<v3<<endl;

ArrayXf v4(3);
v4<<1,2,3;
cout<<"v4=\n"<<v4<<endl;
}
28 changes: 28 additions & 0 deletions docker/install/opencv/install_opencv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "${BASH_SOURCE[0]}")"
apt-get install -y libcanberra-gtk-module

# 下载和解压
wget -O opencv-3.4.5.tar.gz https://github.com/opencv/opencv/archive/refs/tags/3.4.5.tar.gz
tar -zxvf opencv-3.4.5.tar.gz
# 开始编译和安装
pushd opencv-3.4.5
rm -rf build
mkdir build && cd build
# 构建和编译安装,-j4代表4线程并发
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j$(nproc)
make install
# 刷新动态库
ldconfig
# 检测是否安装成功
cd ../samples/cpp/example_cmake
mkdir build && cd build
cmake ..
make
popd

rm -rf opencv-3.4.5 opencv-3.4.5.tar.gz
Binary file added docker/install/pangolin/Pangolin-0.6.tar.gz
Binary file not shown.
26 changes: 26 additions & 0 deletions docker/install/pangolin/install_pangolin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -e

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

# wget -O Pangolin-0.6.tar.gz https://github.com/stevenlovegrove/Pangolin/archive/refs/tags/v0.6.tar.gz
tar -zxvf Pangolin-0.6.tar.gz

pushd Pangolin-0.6
rm -rf build
mkdir build && cd build
# 编译安装
cmake -DCPP11_NO_BOOST=1 ..
make -j$(nproc)
make install
# 刷新动态库
ldconfig
# 检查安装成功(能不能编译demo)
cd ../examples/HelloPangolin
mkdir build && cd build
cmake ..
make
popd

rm -rf Pangolin-0.6 Pangolin-0.6.tar.gz
19 changes: 19 additions & 0 deletions docker/install/pytorch/install_pytorch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "${BASH_SOURCE[0]}")"
# 编译运行需要
pip3 install pyyaml

git clone --recursive -b v1.0.1 https://github.com/pytorch/pytorch
pushd pytorch
rm -rf build
mkdir build && cd build
# 修改不兼容的pyyaml代码
sed -i "s|yaml.load('\n'.join(declaration_lines))|yaml.load('\n'.join(declaration_lines),Loader=yaml.FullLoader)|" aten/src/ATen/cwrap_parser.py
sed -i "s|yaml.load('\n'.join(declaration_lines))|yaml.load('\n'.join(declaration_lines),Loader=yaml.FullLoader)|" tools/cwrap/cwrap.py
# 开始编译libtorch
python3 ../tools/build_libtorch.py
ldconfig
popd
1 change: 1 addition & 0 deletions docker/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_VERSION = 'v0.0.1'

0 comments on commit a7068b5

Please sign in to comment.