Skip to content

Commit

Permalink
feat: add docker support
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Jul 31, 2024
1 parent 08a067f commit 607bcab
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 80 deletions.
76 changes: 0 additions & 76 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ boot branch

## 快速开始

1. 需要 Ubuntu 环境
1. 需要 Ubuntu 环境或使用 docker(见 tools/docker.md)

2. 安装依赖

Expand Down
15 changes: 12 additions & 3 deletions doc/docker.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@

# 构建 Docker 并通过 ssh 使用
# Docker

## 使用构建好的镜像

```shell
cd SimpleKernel
docker pull ptrnull233/simple_kernel:latest
docker run --name SimpleKernel-container -itd -p 233:22 -v ./:/root/SimpleKernel ptrnull233/simple_kernel:latest
docker exec -it SimpleKernel-container /bin/zsh
```

## 构建 Docker image

构建 image

```
cd SimpleKernel
docker build -t SimpleKernel-docker .
docker buildx build -t simple_kernel-docker-image ./tools
```

## 启动容器,并配置 ssh

运行以下命令启动容器:

```
docker run --name SimpleKernel-container -itd -p 233:22 -v ./:/home/zone/SimpleKernel SimpleKernel-docker
docker run --name SimpleKernel-container -itd -p 233:22 -v ./:/root/SimpleKernel simple_kernel-docker-image
```

进入 docker container ubuntu 命令行环境
Expand Down
16 changes: 16 additions & 0 deletions docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# This file is a part of Simple-XX/SimpleKernel
# (https://github.com/Simple-XX/SimpleKernel).
#
# docker.sh for Simple-XX/SimpleKernel.
# 运行预制了工具链的 docker

# shell 执行出错时终止运行
set -e
# 输出实际执行内容
set -x

docker pull ptrnull233/simple_kernel:latest
docker run --name SimpleKernel-container -itd -p 233:22 -v ./:/root/SimpleKernel ptrnull233/simple_kernel:latest
docker exec -it SimpleKernel-container /bin/zsh
78 changes: 78 additions & 0 deletions tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

# This file is a part of Simple-XX/SimpleKernel
# (https://github.com/Simple-XX/SimpleKernel).
#
# Dockerfile for Simple-XX/SimpleKernel.

FROM ubuntu:latest AS basic_os
RUN export DEBIAN_FRONTEND=noninteractive && apt update && apt upgrade -y
ENV LANG=C.UTF-8
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

FROM basic_os AS basic_tools
RUN apt install --no-install-recommends --fix-missing -y \
locales \
ca-certificates \
git \
curl \
wget \
openssh-server \
rsync \
sudo \
zsh \
zip \
tar
RUN apt install --no-install-recommends --fix-missing -y \
vim \
doxygen \
valgrind \
graphviz \
clang-format \
clang-tidy \
cppcheck \
lcov
RUN locale-gen en_US.UTF-8 && locale-gen zh_CN.UTF-8 \
&& mkdir -p /var/run/sshd \
&& echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config \
&& echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config \
&& echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config \
&& ssh-keygen -A \
&& service ssh restart \
&& git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh \
&& cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc \
&& cp -r ~/.oh-my-zsh /home/ubuntu/ \
&& cp ~/.oh-my-zsh/templates/zshrc.zsh-template /home/ubuntu/.zshrc \
&& chsh -s /bin/zsh root \
&& usermod -s /bin/zsh root \
&& chsh -s /bin/zsh ubuntu \
&& usermod -s /bin/zsh ubuntu

FROM basic_tools AS dev_tools
RUN apt install --no-install-recommends --fix-missing -y \
build-essential \
binutils \
make \
cmake \
git \
qemu-system \
gdb-multiarch \
libgtest-dev
RUN apt install --no-install-recommends --fix-missing -y \
gcc \
g++ \
gcc-riscv64-linux-gnu \
g++-riscv64-linux-gnu \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
gcc-riscv64-linux-gnu \
g++-riscv64-linux-gnu \
gcc-x86-64-linux-gnu \
g++-x86-64-linux-gnu

FROM dev_tools AS simple_kernel
EXPOSE 22
USER root
WORKDIR /root
RUN apt autoremove -y && apt clean -y && rm -rf /var/lib/apt/lists/* \
&& git config --global --add safe.directory /root/SimpleKernel
ENTRYPOINT ["/bin/zsh"]

0 comments on commit 607bcab

Please sign in to comment.