Xilinx FPGA_as_a_Service之Xilinx Base Runtime脚本分析 host_setup.sh运行会调用/utilities/docker_install.sh脚本安装docker。在该产品中有一个Dockerfiles文件夹。目录结构如下所示,针对不同的版本的XRT有不同的文件夹,文件夹下有针对不同操作系统的

Dockerfile文件,用于创建镜像。

FPGA云原生 Xilinx FPGA_as_a_Service之Xilinx Base Runtime脚本分析 /utilities/docker_install.sh_centos


FPGA云原生 Xilinx FPGA_as_a_Service之Xilinx Base Runtime脚本分析 /utilities/docker_install.sh_centos_02


首先是确认运行用户是root,然后确认系统是否已经安装docker了。如果已经安装,打印docker版本;如果没有安装,

if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. "
exit 1
fi

OSVERSION=`grep '^ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"'`

if [[ "$OSVERSION" == "ubuntu" ]]; then
DOCKER_INFO=`apt list --installed 2>/dev/null | grep docker-ce`
elif [[ "$OSVERSION" == "centos" ]]; then
DOCKER_INFO=`yum list installed 2>/dev/null | grep docker-ce`
else
echo "The script supports: Ubuntu 16.04, Ubuntu 18.04 and Centos 7. For other operating system, please install DockerCE manually following: https://docs.docker.com/engine/install/."
exit 1
fi

if [ $? == 0 ] ; then
echo "You have already installed docker."
DOCKER_INFO=`docker info 2>/dev/null`
if [ $? == 0 ] ; then
DOCKER_VERSION=`docker info 2>/dev/null |grep "Server Version"| awk -F: '{print $2}'`
echo "Docker Version:$DOCKER_VERSION"
else
docker info
fi
else
echo "Install docker on $OSVERSION..."
if [[ "$OSVERSION" == "ubuntu" ]]; then
apt-get -y update && apt-get install -y curl
fi
curl -fsSL https://get.docker.com | sh > /tmp/xxappstore_hostsetup_installdocker.log 2>&1
if [[ $? != 0 ]]; then
echo "[ERROR] Unable to install DockerCE using Docker automated script"
echo "Please install DockerCE manually following this documentation:"
if [[ "$OSVERSION" == "ubuntu" ]]; then
echo ' > [UBUNTU] https://docs.docker.com/install/linux/docker-ce/ubuntu/'
elif [[ "$OSVERSION" == "centos" ]]; then
echo ' > [CENTOS] https://docs.docker.com/install/linux/docker-ce/centos/'
fi
exit 1
fi
echo "Configure docker"
mkdir -p /etc/docker && echo '{"max-concurrent-downloads": 1}' | tee -a /etc/docker/daemon.json && systemctl restart docker && systemctl enable docker > /tmp/xxappstore_hostsetup_configuredocker.log 2>&1
if [[ $? != 0 ]]; then
echo "[ERROR] Docker Configuration. Check log file /tmp/xxappstore_hostsetup_configuredocker.log"
exit 1
fi
echo "Verify that Docker Engine is installed correctly by running the hello-world image."
echo ""
echo " docker run hello-world"
echo ""
echo "If you would like to use Docker as a non-root user, you should now consider adding your user to the “docker” group with something like:"
echo ""
echo " usermod -aG docker your-user"
echo ""
echo "Install docker completed"
fi

分析一下如下命令
mkdir -p /etc/docker && echo ‘{“max-concurrent-downloads”: 1}’ | tee -a /etc/docker/daemon.json && systemctl restart docker && systemctl enable docker > /tmp/xxappstore_hostsetup_configuredocker.log 2>&1

Dockerfile文件,以201902 centos举例

FROM centos:7

#Install dependencies
RUN yum install -y epel-release; yum install -y boost-devel boost-filesystem dkms libboost_filesystem-mt.so.1.53.0 libboost_filesystem.so.1.53.0 libboost_system-mt.so.1.53.0 libboost_system.so.1.53.0 libprotobuf.so.8 libuuid-devel libxml2-devel libyaml-0.1.4-11.el7_0.x86_64 libyaml-devel ncurses-devel ocl-icd-devel openssl-devel protobuf-compiler protobuf-devel python-pip redhat-lsb-core libxml-2.0 yaml-0.1 wget

#Dowload XRT installation packages from Xilinx lounge page
RUN wget -cO - https://www.xilinx.com/bin/public/openDownload?filename=xrt_201920.2.3.1301_7.4.1708-xrt.rpm > /root/xrt_201920.2.3.1301_7.4.1708-xrt.rpm

#Install XRT
RUN rpm -i /root/xrt_201920.2.3.1301_7.4.1708-xrt.rpm

#Copy notice and disclaimer
ADD Xilinx_notice_and_disclaimer.txt /Xilinx_notice_and_disclaimer.txt