diff --git a/.gitignore b/.gitignore index ea8c4bf7f35f6f77f75d92ad8ce8349f6e81ddba..c8e9e486009018095282f4ff49b9e3b1e74d17b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/target +target +Cargo.lock +.vscode diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index fbab3a400c7d2d36d3713f00376ecc9523364c71..0000000000000000000000000000000000000000 --- a/Cargo.lock +++ /dev/null @@ -1,40 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "cc" -version = "1.0.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" - -[[package]] -name = "libc" -version = "0.2.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7" - -[[package]] -name = "process1" -version = "0.1.0" -dependencies = [ - "signal-hook", -] - -[[package]] -name = "signal-hook" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aa894ef3fade0ee7243422f4fbbd6c2b48e6de767e621d37ef65f2310f53cea" -dependencies = [ - "cc", - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-registry" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" -dependencies = [ - "libc", -] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06bf30adeaa9ece3217661fc323d8a76144964df --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ + +FROM scratch +#ADD target/x86_64-unknown-linux-musl/debug/process1 /sbin/init +COPY target/x86_64-unknown-linux-musl/debug/process1 /sbin/init +CMD ["/sbin/init"] diff --git a/docker-run.sh b/docker-run.sh new file mode 100755 index 0000000000000000000000000000000000000000..1fd24a28252f080e20e762a7eab1fe32bbce6320 --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +#1.check cargo musl build +#echo -e "---!!!CHECK CARGO AND DOCKER!!!---" +rustup show | grep -i x86_64-unknown-linux-musl > /dev/null 2>&1 +if [ $? -ne 0 ]; then + cat << EOF +你的环境缺少rust构建工具, 你可以: + +1.安装rust环境... +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + +2.安装x86_64-unknown-linux-musl... +rustup target add x86_64-unknown-linux-musl + +3.安装musl-gcc... +dnf install musl-gcc -y +EOF +exit 1 +fi + +#!.check docker +docker -v > /dev/null 2>&1 +if [ $? -ne 0 ]; then + cat << EOF +你的环境缺少docker工具, 你可以: + +1.安装docker环境... +dnf install docker +或 +curl -sSL https://get.docker.com | sh + +2.开启docker服务 +systemctl start docker; systemctl enable docker + +3.如果不支持cgroupv2, 修改后重启系统 +sudo dnf install -y grubby && sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0" + +EOF +exit 1 +fi + +#!.build +echo -e "---!!!CARGO BUILD!!!---" +cargo build --target x86_64-unknown-linux-musl || exit 1 + + +#!.docker build +echo -e "\n\n\n---!!!DOCKER BUILD!!!---" +docker build --no-cache --tag process1 `pwd` || exit 1 + +#!.docker run +echo -e "\n\n\n---!!!RUN PROCESS1 IN DOCKER!!!---" +docker run process1 || exit 1