xref: /DragonOS/tools/Dockerfile (revision 5ed4cd460200cb19aae8c3c67dfd77e1e9f0e105)
1*5ed4cd46SguanjinquanFROM debian:bullseye
2*5ed4cd46Sguanjinquan
3*5ed4cd46Sguanjinquan# 设置工作目录
4*5ed4cd46SguanjinquanWORKDIR /build-image
5*5ed4cd46Sguanjinquan
6*5ed4cd46Sguanjinquan# 将本地的脚本复制到工作目录
7*5ed4cd46SguanjinquanCOPY *.sh ./
8*5ed4cd46Sguanjinquan
9*5ed4cd46Sguanjinquan# 设置用来存放rust缓存的卷
10*5ed4cd46SguanjinquanVOLUME [ "/root/.cargo/registry" ]
11*5ed4cd46Sguanjinquan
12*5ed4cd46Sguanjinquan# 设置rust源的环境变量
13*5ed4cd46SguanjinquanENV RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
14*5ed4cd46SguanjinquanENV RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
15*5ed4cd46Sguanjinquan
16*5ed4cd46SguanjinquanRUN sed -i "s@http://\(deb\|security\).debian.org@http://mirrors.ustc.edu.cn@g" /etc/apt/sources.list && apt update && apt install -y \
17*5ed4cd46Sguanjinquan    ca-certificates \
18*5ed4cd46Sguanjinquan    curl \
19*5ed4cd46Sguanjinquan    gnupg \
20*5ed4cd46Sguanjinquan    lsb-release \
21*5ed4cd46Sguanjinquan    llvm-dev libclang-dev clang gcc-multilib \
22*5ed4cd46Sguanjinquan    gcc build-essential fdisk dosfstools qemu-kvm \
23*5ed4cd46Sguanjinquan    sudo wget
24*5ed4cd46Sguanjinquan
25*5ed4cd46Sguanjinquan# 安装Rust
26*5ed4cd46SguanjinquanRUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly -y && \
27*5ed4cd46Sguanjinquan    # You have to add the rustup variables to the $PATH
28*5ed4cd46Sguanjinquan    echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> ~/.bashrc && \
29*5ed4cd46Sguanjinquan    bash -c "source $HOME/.cargo/env && \
30*5ed4cd46Sguanjinquan    # 更换cargo的索引源
31*5ed4cd46Sguanjinquan    touch $HOME/.cargo/config && \
32*5ed4cd46Sguanjinquan    bash change_rust_src.sh && \
33*5ed4cd46Sguanjinquan    # 安装rust的编译工具
34*5ed4cd46Sguanjinquan    echo "正在安装DragonOS所需的rust组件...首次安装需要一些时间来更新索引,请耐心等待..." && \
35*5ed4cd46Sguanjinquan    cargo install cargo-binutils && \
36*5ed4cd46Sguanjinquan    rustup toolchain install nightly && \
37*5ed4cd46Sguanjinquan    rustup default nightly && \
38*5ed4cd46Sguanjinquan    rustup component add rust-src && \
39*5ed4cd46Sguanjinquan    rustup component add llvm-tools-preview && \
40*5ed4cd46Sguanjinquan    rustup target add x86_64-unknown-none"
41*5ed4cd46Sguanjinquan
42*5ed4cd46Sguanjinquan# 编译安装GCC交叉编译工具链
43*5ed4cd46SguanjinquanRUN bash build_gcc_toolchain.sh -f
44*5ed4cd46Sguanjinquan
45*5ed4cd46Sguanjinquan# 清除缓存
46*5ed4cd46SguanjinquanWORKDIR /
47*5ed4cd46SguanjinquanRUN apt-get autoremove -q -y && \
48*5ed4cd46Sguanjinquan    apt-get clean -q -y && \
49*5ed4cd46Sguanjinquan    rm -rf /build-image
50*5ed4cd46Sguanjinquan
51*5ed4cd46SguanjinquanENV DragonOS_GCC=/root/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin/
52*5ed4cd46Sguanjinquan# 设置容器启动后执行的命令
53*5ed4cd46SguanjinquanCMD ["/bin/bash"]
54