Skip to content

Commit 591bbce

Browse files
committed
Add vagrant and docker scripts
* Initilze vagrant configuration * Initilze docker container * fix `IPConfig` and `NetInfo` conflictions
1 parent 7e54017 commit 591bbce

File tree

11 files changed

+139
-8
lines changed

11 files changed

+139
-8
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,21 @@ cscope.out
1919
cscope.in.out
2020
cscope.po.out
2121

22+
### Vagrant ###
23+
# General
24+
.vagrant/
2225

26+
# Log files (if you are creating logs in debug mode, uncomment this)
27+
# *.logs
28+
29+
### Rust ###
30+
# Generated by Cargo
31+
# will have compiled files and executables
32+
/target/
33+
34+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
35+
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
36+
Cargo.lock
37+
38+
# These are backup files generated by rustfmt
39+
**/*.rs.bk

Vagrantfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Vagrant.configure("2") do |config|
2+
config.vm.box = "rockylinux/9"
3+
config.vm.synced_folder ".", "/vagrant", disabled: true
4+
config.vm.synced_folder "./", "/home/vagrant/workspace", type: "nfs", nfs_udp: false, nfs_version: "4.2"
5+
config.vm.synced_folder ENV["HOME"] + "/.cargo", "/home/vagrant/.cargo", type: "nfs", nfs_udp: false, nfs_version: "4.2"
6+
config.vm.network "private_network", type: "dhcp"
7+
config.vm.network "private_network", ip: "192.168.50.4"
8+
config.vm.provision "shell", inline: "bash /home/vagrant/workspace/scripts/vagrant/init.sh"
9+
config.vm.provider :libvirt do |libvirt|
10+
# CPU 核心数
11+
libvirt.cpus = 16
12+
# 内存大小
13+
libvirt.memory = 16384
14+
# 存储池名称
15+
libvirt.storage_pool_name = "virtual"
16+
# 使用系统接口
17+
libvirt.uri = "qemu:///system"
18+
# 默认网络修改
19+
libvirt.management_network_name = "vagrant-virbr2"
20+
# 阻止自定义网络被删除
21+
libvirt.management_network_keep = true
22+
end
23+
config.trigger.after :provision do |trigger|
24+
trigger.info = "Adding kitty terminfo.."
25+
trigger.run = {inline: "bash -c 'infocmp -a xterm-kitty | vagrant ssh -c \"tic -x -o \~/.terminfo /dev/stdin\" 2>/dev/null || true'"}
26+
end
27+
end

network/src/dispatch/ipconfigs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ipnet::IpNet;
88
use libc::{AF_INET, AF_INET6};
99
use nm::{ConnectionExt, IPAddress, SettingIPConfig, SettingIPConfigExt, SettingIP4Config, SettingIP6Config};
1010
use std::boxed::Box;
11-
use crate::utils::IPConfig;
11+
use crate::net::NetInfo;
1212

1313
fn ipnet2ipaddr(ipnet: IpNet) -> Result<IPAddress> {
1414
let ipaddress: IPAddress;
@@ -30,13 +30,13 @@ pub async fn get_ip_config(conn_name: String, family: i32) -> Result<NetworkResp
3030
// Parser configuration
3131
if family == 4 {
3232
if let Some(setting_ip4_config) = connection.setting_ip4_config().map(|x| <SettingIP4Config as Into<SettingIPConfig>>::into(x)) {
33-
IPConfig::try_from(setting_ip4_config)
33+
NetInfo::try_from(setting_ip4_config)
3434
} else {
3535
bail!("Failed to get ipv4 config")
3636
}
3737
} else {
3838
if let Some(setting_ip6_config) = connection.setting_ip6_config().map(|x| <SettingIP6Config as Into<SettingIPConfig>>::into(x)) {
39-
IPConfig::try_from(setting_ip6_config)
39+
NetInfo::try_from(setting_ip6_config)
4040
} else {
4141
bail!("Failed to get ipv6 config")
4242
}
@@ -52,7 +52,7 @@ pub async fn get_ip_config(conn_name: String, family: i32) -> Result<NetworkResp
5252
pub async fn update_ip_config(
5353
conn_name: String,
5454
family: i32,
55-
config: IPConfig,
55+
config: NetInfo,
5656
) -> Result<NetworkResponse> {
5757
let client = create_client().await?;
5858
let _conn: Option<nm::RemoteConnection> = try {

network/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern crate eyre;
1919

2020
mod dispatch;
2121
mod net;
22-
mod tokio;
22+
mod tokio_client;
2323

2424
use std::sync::Arc;
2525

File renamed without changes.

network/tests/test_configuration.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod fixture;
22

33
use fixture::start_instance;
44
use ipnet::IpNet;
5-
use network::{send_command, IPConfig, NetworkCommand, NetworkResponse, Route, State};
5+
use network::{send_command, NetInfo, NetworkCommand, NetworkResponse, State};
66
use rstest::rstest;
77
use std::net::IpAddr;
88
use std::sync::Arc;
@@ -50,7 +50,7 @@ async fn test_modify_ip_configuration(start_instance: &Arc<State>) {
5050
}
5151
let gw: IpAddr = "192.168.101.1".parse().unwrap();
5252
let addresses: Vec<IpNet> = vec!["192.168.101.38/24".parse().unwrap()];
53-
let ip4_config = IPConfig {
53+
let ip4_config = NetInfo {
5454
method: String::from("manual"),
5555
addresses,
5656
gateway: Some(gw),
@@ -75,7 +75,7 @@ async fn test_modify_ip_configuration(start_instance: &Arc<State>) {
7575
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
7676
let gw: IpAddr = "fe80::5c51:8df8:ee41:d98a".parse().unwrap();
7777
let addresses: Vec<IpNet> = vec!["fe80::5c51:8df8:ee41:d98a/64".parse().unwrap()];
78-
let ip6_config = IPConfig {
78+
let ip6_config = NetInfo {
7979
method: String::from("manual"),
8080
addresses,
8181
gateway: Some(gw),

scripts/build-dev-container.nu

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/nu
2+
let container = (buildah from docker.io/library/rockylinux:9)
3+
buildah add $container inner /
4+
buildah run --network=host $container -- bash /docker-init/localize.sh
5+
buildah run --network=host $container -- bash -c "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly -y"
6+
buildah run --network=host $container -- dnf install -y NetworkManager-libnm-devel systemd-devel git protobuf-devel gcc
7+
buildah run --network=host $container -- dnf clean all
8+
buildah run --network=host $container -- cp /docker-init/config /root/.cargo/config
9+
buildah config --env PATH=/root/.cargo/bin:$PATH $container
10+
buildah commit $container docker.io/ssfdust/orbuculum-dev:latest
11+
buildah rm $container

scripts/cargo

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/nu
2+
alias xcargo = podman run --network=host --rm --name test -v $"(pwd | str trim):/work" -v $"($env.HOME)/.cargo:/root/.cargo" --workdir /work --replace -ti docker.io/ssfdust/orbuculum-dev cargo
3+
alias xbash = podman run --network=host --rm --name test -v $"(pwd | str trim):/work" -v $"($env.HOME)/.cargo:/root/.cargo" --workdir /work --replace -ti docker.io/ssfdust/orbuculum-dev

scripts/inner/docker-init/config

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[source.crates-io]
2+
# To use sparse index, change 'rsproxy' to 'rsproxy-sparse'
3+
replace-with = 'rsproxy'
4+
5+
[source.rsproxy]
6+
registry = "https://rsproxy.cn/crates.io-index"
7+
[source.rsproxy-sparse]
8+
registry = "sparse+https://rsproxy.cn/index/"
9+
10+
[registries.rsproxy]
11+
index = "https://rsproxy.cn/crates.io-index"
12+
13+
[net]
14+
git-fetch-with-cli = true

scripts/inner/docker-init/localize.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
sed -i '/\[crb\]/,/enabled/s/enabled=0/enabled=1/' /etc/yum.repos.d/rocky.repo
3+
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
4+
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.nju.edu.cn/rocky|g' \
5+
-i.bak \
6+
/etc/yum.repos.d/*.repo
7+
dnf makecache
8+
dnf update -y

scripts/vagrant/init.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
3+
[ -f /etc/.initilized ] && exit 0
4+
5+
# Prepare environment
6+
sed -i '/\[crb\]/,/enabled/s/enabled=0/enabled=1/' /etc/yum.repos.d/rocky.repo
7+
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
8+
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.nju.edu.cn/rocky|g' \
9+
-i.bak \
10+
/etc/yum.repos.d/*.repo
11+
dnf makecache
12+
dnf update -y
13+
dnf install -y NetworkManager-libnm-devel systemd-devel git protobuf-devel gcc
14+
15+
# Install rust
16+
runuser -u vagrant -- /home/vagrant/.cargo/bin/rustup default nightly
17+
echo "source ~/.cargo/env" | tee -a /home/vagrant/.bashrc
18+
19+
# Install starship
20+
dnf copr enable -y atim/starship
21+
dnf install -y starship
22+
echo 'eval "$(starship init bash)"' | tee -a /home/vagrant/.bashrc
23+
24+
# create startship configuration
25+
install -d -o vagrant -g vagrant /home/vagrant/.config
26+
cat > /home/vagrant/.config/starship.toml <<EOF
27+
format = """[\uE0B6](fg:#1C4961)[\$directory](bg:#1C4961)[\uE0B0](fg:#1C4961 bg:#2F79A1)\$git_branch[\uE0B0](fg:#2F79A1 bg:#3A95C7)\$git_status[\uE0B0](#3A95C7 bg:#40A9E0)\$cmd_duration[\uE0B0](#40A9E0 bg:none) \$all\$character"""
28+
29+
right_format = ""
30+
31+
add_newline = false
32+
33+
[directory]
34+
style = "bg:#1C4961 fg:white"
35+
36+
[git_branch]
37+
format = "[ \$symbol\$branch ](\$style)"
38+
style = "bg:#2F79A1 fg:white"
39+
40+
[git_status]
41+
format = "[ \$all_status\$ahead_behind ](\$style)"
42+
style = "bg:#3A95C7 fg:white"
43+
44+
[cmd_duration]
45+
disabled = false
46+
format = "[ took \$duration ](\$style)"
47+
show_milliseconds = true
48+
style = "bg:#40A9E0 fg:white"
49+
EOF
50+
51+
touch /etc/.initilized

0 commit comments

Comments
 (0)