add docker support
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2025-01-05 05:15:14 +01:00
parent c689ee87d4
commit 633a0ef410
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 65 additions and 15 deletions

View file

@ -58,6 +58,9 @@ password = "testpass"
# Allow user to use `doas` as root # Allow user to use `doas` as root
doas_root= true doas_root= true
# Add user to Docker group
docker = true
# SSH Configuration # SSH Configuration
# If `[ssh]` is set, openssh will be installed and enabled. # If `[ssh]` is set, openssh will be installed and enabled.
[ssh] [ssh]

View file

@ -3,7 +3,7 @@ use std::fmt::Display;
use serde::Deserialize; use serde::Deserialize;
/// Declarative install configuration /// Declarative install configuration
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct InstallConfig { pub struct InstallConfig {
/// Drive Configuration /// Drive Configuration
pub drive: DriveConfig, pub drive: DriveConfig,
@ -19,32 +19,33 @@ pub struct InstallConfig {
pub ai: Option<OllamaConfig>, pub ai: Option<OllamaConfig>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct OllamaConfig { pub struct OllamaConfig {
pub models: Option<Vec<String>>, pub models: Option<Vec<String>>,
pub gpu: bool, pub gpu: bool,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct SSHConfig { pub struct SSHConfig {
pub sshd_config: Option<String>, pub sshd_config: Option<String>,
pub key: Option<Vec<SSHKey>>, pub key: Option<Vec<SSHKey>>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct SSHKey { pub struct SSHKey {
pub key: String, pub key: String,
pub users: Vec<String>, pub users: Vec<String>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct UserConfig { pub struct UserConfig {
pub name: String, pub name: String,
pub password: String, pub password: String,
pub doas_root: bool, pub doas_root: Option<bool>,
pub docker: Option<bool>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct PackageConfig { pub struct PackageConfig {
/// Packages to install /// Packages to install
pub pkg: Vec<String>, pub pkg: Vec<String>,
@ -54,7 +55,7 @@ pub struct PackageConfig {
pub docker: Option<bool>, pub docker: Option<bool>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct DriveConfig { pub struct DriveConfig {
/// Boot Drive Path /// Boot Drive Path
pub boot: String, pub boot: String,
@ -64,7 +65,7 @@ pub struct DriveConfig {
pub encryption: Option<String>, pub encryption: Option<String>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct GeneralConfig { pub struct GeneralConfig {
/// Presets /// Presets
pub mode: InstallMode, pub mode: InstallMode,
@ -82,7 +83,7 @@ pub struct GeneralConfig {
pub root_password: Option<String>, pub root_password: Option<String>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub enum InstallMode { pub enum InstallMode {
/// Basic Arch Linux Installation /// Basic Arch Linux Installation
Base, Base,

24
src/install/docker.rs Normal file
View file

@ -0,0 +1,24 @@
use crate::{
config::UserConfig,
linux::{arch_chroot, systemd_service_enable},
pkg::install_pkgs,
print_status,
};
/// Setup docker on the system
pub fn setup_docker(conf: &[UserConfig]) {
print_status("Setting up Docker");
install_pkgs(&["docker", "docker-compose"]);
systemd_service_enable("docker.service");
for user in conf {
if user.docker.unwrap_or_default() {
arch_chroot(
&vec!["usermod", "-a", "-G", "docker", user.name.as_str()],
None,
false,
);
}
}
}

View file

@ -4,6 +4,7 @@
// DRIVE SELECTION // DRIVE SELECTION
use boot::setup_bootloader; use boot::setup_bootloader;
use docker::setup_docker;
use drives::{format_drives, mount_drives}; use drives::{format_drives, mount_drives};
use first_boot::{first_boot_values, genfstab}; use first_boot::{first_boot_values, genfstab};
use kernel::setup_mkinitcpio; use kernel::setup_mkinitcpio;
@ -17,6 +18,7 @@ use yansi::{Color, Paint};
use zram::setup_zram; use zram::setup_zram;
pub mod boot; pub mod boot;
pub mod docker;
pub mod drives; pub mod drives;
pub mod first_boot; pub mod first_boot;
pub mod kernel; pub mod kernel;
@ -85,7 +87,7 @@ pub fn install(conf: InstallConfig) {
// System Setup // System Setup
first_boot_values(&conf.general); first_boot_values(&conf.general);
setup_skel(&conf.general); setup_skel(&conf.general);
setup_users(&conf.user.unwrap_or_default()); setup_users(&conf.user.as_ref().unwrap_or(&Vec::new()));
setup_ssh(conf.ssh); setup_ssh(conf.ssh);
@ -118,7 +120,13 @@ pub fn install(conf: InstallConfig) {
} }
if conf.pkg.docker.unwrap_or_default() { if conf.pkg.docker.unwrap_or_default() {
// TODO : Enable docker let user_conf = if let Some(user_conf) = &conf.user {
user_conf.clone()
} else {
Vec::new()
};
setup_docker(&user_conf);
} }
if let Some(ai) = conf.ai { if let Some(ai) = conf.ai {

View file

@ -17,7 +17,7 @@ pub fn setup_users(conf: &[UserConfig]) {
change_passwd(&user.name, &user.password); change_passwd(&user.name, &user.password);
if user.doas_root { if user.doas_root.unwrap_or_default() {
print_status(&format!("Allowing root doas for {}", user.name)); print_status(&format!("Allowing root doas for {}", user.name));
doas_conf.push_str(&format!("permit {} as root\n", user.name)); doas_conf.push_str(&format!("permit {} as root\n", user.name));
} }

View file

@ -92,10 +92,24 @@ pub fn print_config(conf: &InstallConfig) {
let user_conf = conf.user.as_ref().unwrap_or(&empty); let user_conf = conf.user.as_ref().unwrap_or(&empty);
for user in user_conf { for user in user_conf {
let mut groups = Vec::new();
if user.doas_root.unwrap_or_default() {
groups.push("🔑");
}
if user.docker.unwrap_or_default() {
groups.push("🐋");
}
users_info.add_str(format!( users_info.add_str(format!(
"👤 {} {}", "👤 {}{}",
user.name, user.name,
if user.doas_root { "🔑" } else { "" } if !groups.is_empty() {
format!(" [ {} ]", groups.join(" "))
} else {
String::new()
}
)); ));
} }