配置 repo 编译环境

配置dockerfile

将以下内容写入到g351_dockerfile文件中

FROM ubuntu:24.04

ARG UID
ARG GID

# 避免 tzdata 等包卡住
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

# 设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone

# 使用官方主源(不包含 security)以避免 404
RUN echo "deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse" > /etc/apt/sources.list && \
    echo "deb http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse" >> /etc/apt/sources.list

# 安装常用工具 + 编译环境
RUN apt update && \
    apt install -y \
        dfu-util \
        genromfs \
        gettext \
        git \
        git-lfs \
        gperf \
        kconfig-frontends \
        libc++abi1 \
        libc++1 \
        mtools \
        nasm \
        net-tools \
        nodejs \
        npm \
        pkgconf \
        protobuf-c-compiler \
        protobuf-compiler \
        yasm \
        locales \
        curl \
        file \
        jq \
        mysql-client \
        openjdk-17-jdk \
        openssh-server \
        python3 \
        python3-pip \
        scons \
        unzip \
        vim \
        wget \
        zip && \
    locale-gen en_US.UTF-8 && \
    update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 && \
    mkdir -p /run/sshd && \
    apt clean && rm -rf /var/lib/apt/lists/*

# 安装 repo 工具(清华源)
RUN curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/git/git-repo \
        -o /usr/local/bin/repo && \
    chmod a+x /usr/local/bin/repo && \
    repo --version

# Git / repo 基础配置(避免 CI / repo warning)
RUN git config --global user.name "jenkins" && \
    git config --global user.email "jenkins@163.com" && \
    git config --global color.ui auto && \
    git config --global core.autocrlf false && \
    git config --global pull.rebase false

# 配置 SSH
RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && \
    echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config && \
    echo "UsePAM no" >> /etc/ssh/sshd_config

# 自动生成 Ed25519 密钥对
# 1. 创建 .ssh 目录并设置严格权限
# 2. 生成密钥:-t ed25519 (类型), -f (路径), -N "" (空密码), -q (静默), -C (注释)
# 3. 设置私钥权限为 600 (所有者读写),公钥为 644
RUN mkdir -p /root/.ssh && \
    chmod 700 /root/.ssh && \
    ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519 -N "" -q -C "root_g351" && \
    chmod 600 /root/.ssh/id_ed25519 && \
    chmod 644 /root/.ssh/id_ed25519.pub && \
    # 可选:将公钥添加到 authorized_keys 以便免密登录自己 (如果需要)
    cat /root/.ssh/id_ed25519.pub >> /root/.ssh/authorized_keys && \
    chmod 600 /root/.ssh/authorized_keys

# 设置 root 密码 & sudo 免密
RUN echo 'root:root@123' | chpasswd && \
    echo "root ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# 暴露 SSH 端口
EXPOSE 22

WORKDIR /home/workspace/g351
USER root

# 启动 SSH 服务
CMD ["/usr/sbin/sshd", "-D"]

生成镜像

# jenkins的名称可以换成自己当前的用户名
docker build \
--build-arg UID=$(id -u jenkins) \
--build-arg GID=$(id -g jenkins) \
-t g351:latest -f g351_dockerfile .

拉起容器

# -v 挂载的目录可以换成实际目录
docker run -it -d \
--privileged \
-v /data/docker_workspace/g351:/home/workspace/g351 \
-v /mnt/SystemPackages:/mnt/SystemPackages \
--dns=192.168.110.34 \
-p 2222:22 \
--restart=always \
--name g351 \
g351:latest

进入容器

docker exec -it -u jenkins g351 bash

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值