diff --git a/EXAMPLES.md b/EXAMPLES.md new file mode 100644 index 0000000..a22da18 --- /dev/null +++ b/EXAMPLES.md @@ -0,0 +1,467 @@ +# Configuration Examples and Templates + +This document provides ready-to-use configuration templates for various deployment scenarios. Each example includes complete user-data configurations optimized for specific use cases. + +## πŸ–₯️ Development Environment + +Complete development setup with essential tools and services for software development teams. + +```yaml +#cloud-config +autoinstall: + version: 1 + early-commands: + - echo "Initializing development environment setup" + - systemctl stop unattended-upgrades + packages: + - build-essential + - git + - curl + - wget + - vim + - htop + - tree + - docker.io + - docker-compose + - nodejs + - npm + - python3 + - python3-pip + - openssh-server + late-commands: + - echo "Configuring development tools" + - usermod -aG docker ubuntu + - systemctl enable docker + - systemctl enable ssh + - pip3 install virtualenv + - npm install -g @angular/cli + - echo "Development environment ready" + keyboard: + layout: us + source: + id: ubuntu-server + updates: security + identity: + hostname: dev-server + username: developer + password: '$6$rounds=4096$saltsalt$...' + storage: + layout: + name: lvm + network: + network: + version: 2 + ethernets: + enp0s3: + dhcp4: true +``` + +## 🏭 Production Server + +Hardened server configuration with security optimizations and monitoring. + +```yaml +#cloud-config +autoinstall: + version: 1 + early-commands: + - echo "Setting up production server with security hardening" + - systemctl stop unattended-upgrades + packages: + - openssh-server + - ufw + - fail2ban + - logrotate + - rsyslog + - chrony + - unattended-upgrades + - apt-listchanges + late-commands: + - echo "Applying security hardening" + - ufw --force enable + - ufw default deny incoming + - ufw allow 22/tcp + - systemctl enable fail2ban + - systemctl enable chrony + - sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config + - systemctl restart ssh + - echo "Production server secured" + keyboard: + layout: us + source: + id: ubuntu-server-minimal + updates: all + identity: + hostname: prod-server + username: admin + password: '$6$rounds=4096$saltsalt$...' + storage: + layout: + name: lvm + config: + - type: disk + id: disk0 + size: largest + - type: partition + id: boot + device: disk0 + size: 1G + flag: boot + - type: partition + id: root + device: disk0 + size: -1 +``` + +## 🌐 IoT/Edge Device + +Minimal footprint configuration for resource-constrained environments. + +```yaml +#cloud-config +autoinstall: + version: 1 + early-commands: + - echo "Configuring minimal IoT/Edge system" + packages: + - openssh-server + - curl + - wget + - nano + late-commands: + - echo "Optimizing for edge deployment" + - systemctl disable snapd + - apt-get autoremove --purge -y snapd + - systemctl mask systemd-resolved + - echo "nameserver 8.8.8.8" > /etc/resolv.conf + - systemctl enable ssh + - echo "IoT system optimized" + keyboard: + layout: us + source: + id: ubuntu-server-minimal + updates: security + identity: + hostname: iot-device + username: iot + password: '$6$rounds=4096$saltsalt$...' + storage: + layout: + name: direct + config: + - type: disk + id: disk0 + size: largest + - type: partition + id: root + device: disk0 + size: -1 + format: ext4 + mount: / +``` + +## ☸️ Kubernetes Node + +Container orchestration node with Docker and Kubernetes components. + +```yaml +#cloud-config +autoinstall: + version: 1 + early-commands: + - echo "Preparing Kubernetes node setup" + - systemctl stop unattended-upgrades + packages: + - docker.io + - curl + - apt-transport-https + - ca-certificates + - gnupg + - lsb-release + - openssh-server + late-commands: + - echo "Installing Kubernetes components" + - usermod -aG docker ubuntu + - systemctl enable docker + - curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - + - echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list + - apt-get update + - apt-get install -y kubelet kubeadm kubectl + - apt-mark hold kubelet kubeadm kubectl + - systemctl enable kubelet + - echo "Kubernetes node ready for cluster join" + keyboard: + layout: us + source: + id: ubuntu-server + updates: security + identity: + hostname: k8s-node + username: kubernetes + password: '$6$rounds=4096$saltsalt$...' +``` + +## πŸ—„οΈ Database Server + +Optimized database server with backup automation and monitoring. + +```yaml +#cloud-config +autoinstall: + version: 1 + early-commands: + - echo "Setting up database server environment" + packages: + - mysql-server + - redis-server + - postgresql + - postgresql-contrib + - openssh-server + - cron + - logrotate + late-commands: + - echo "Configuring database services" + - systemctl enable mysql + - systemctl enable redis-server + - systemctl enable postgresql + - mysql_secure_installation + - echo "Setting up automated backups" + - mkdir -p /opt/backups + - echo "0 2 * * * root mysqldump --all-databases > /opt/backups/mysql-$(date +%Y%m%d).sql" >> /etc/crontab + - echo "Database server configured" + keyboard: + layout: us + source: + id: ubuntu-server + updates: security + identity: + hostname: db-server + username: dbadmin + password: '$6$rounds=4096$saltsalt$...' + storage: + layout: + name: lvm + config: + - type: disk + id: disk0 + size: largest + - type: partition + id: boot + device: disk0 + size: 1G + - type: partition + id: data + device: disk0 + size: 50G + format: ext4 + mount: /var/lib/mysql + - type: partition + id: backup + device: disk0 + size: -1 + format: ext4 + mount: /opt/backups +``` + +## 🌍 Web Server + +NGINX web server with SSL/TLS support and security hardening. + +```yaml +#cloud-config +autoinstall: + version: 1 + early-commands: + - echo "Configuring web server setup" + packages: + - nginx + - certbot + - python3-certbot-nginx + - ufw + - openssh-server + - php8.1-fpm + - php8.1-mysql + - php8.1-cli + late-commands: + - echo "Setting up web server" + - systemctl enable nginx + - systemctl enable php8.1-fpm + - ufw --force enable + - ufw allow 'Nginx Full' + - ufw allow 22/tcp + - mkdir -p /var/www/html + - chown -R www-data:www-data /var/www/html + - echo "Web server ready for deployment" + keyboard: + layout: us + source: + id: ubuntu-server + updates: security + identity: + hostname: web-server + username: webadmin + password: '$6$rounds=4096$saltsalt$...' +``` + +## πŸ“Š Monitoring Server + +Comprehensive monitoring stack with Prometheus, Grafana, and log aggregation. + +```yaml +#cloud-config +autoinstall: + version: 1 + early-commands: + - echo "Setting up monitoring infrastructure" + packages: + - docker.io + - docker-compose + - openssh-server + - curl + - wget + late-commands: + - echo "Installing monitoring stack" + - usermod -aG docker ubuntu + - systemctl enable docker + - mkdir -p /opt/monitoring + - cd /opt/monitoring + - wget https://raw.githubusercontent.com/prometheus/prometheus/main/docker-compose.yml + - echo "Creating Grafana configuration" + - mkdir -p grafana/provisioning/{dashboards,datasources} + - echo "Monitoring stack ready for configuration" + keyboard: + layout: us + source: + id: ubuntu-server + updates: security + identity: + hostname: monitoring-server + username: monitor + password: '$6$rounds=4096$saltsalt$...' +``` + +## πŸ”’ Security Best Practices + +### Password Generation + +Generate secure password hashes for user accounts: + +```bash +# For production systems +openssl passwd -6 -salt $(openssl rand -hex 16) "your_secure_password" + +# For development environments +openssl passwd -6 -salt $(openssl rand -hex 8) "dev_password" +``` + +### SSH Key Integration + +Add SSH public keys for key-based authentication: + +```yaml +ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAA... user@hostname + - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... admin@workstation +``` + +### Network Security + +Configure firewall rules in late-commands: + +```yaml +late-commands: + - ufw --force enable + - ufw default deny incoming + - ufw allow 22/tcp + - ufw allow 80/tcp + - ufw allow 443/tcp +``` + +## πŸš€ Advanced Configurations + +### Custom Package Repositories + +Add third-party repositories for specialized software: + +```yaml +late-commands: + - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - + - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + - apt-get update + - apt-get install -y docker-ce docker-ce-cli containerd.io +``` + +### Environment-Specific Configurations + +Customize based on deployment environment: + +```yaml +# Production +late-commands: + - echo "ENVIRONMENT=production" >> /etc/environment + - systemctl disable debug services + +# Development +late-commands: + - echo "ENVIRONMENT=development" >> /etc/environment + - systemctl enable debug services +``` + +## πŸ“š Configuration Reference + +### Storage Layouts + +**LVM Layout** (Recommended for servers): +```yaml +storage: + layout: + name: lvm +``` + +**Direct Layout** (For IoT/Edge devices): +```yaml +storage: + layout: + name: direct +``` + +### Network Configuration + +**DHCP Configuration**: +```yaml +network: + network: + version: 2 + ethernets: + enp0s3: + dhcp4: true +``` + +**Static IP Configuration**: +```yaml +network: + network: + version: 2 + ethernets: + enp0s3: + addresses: [192.168.1.100/24] + gateway4: 192.168.1.1 + nameservers: + addresses: [8.8.8.8, 8.8.4.4] +``` + +### Package Installation Sources + +**Standard Ubuntu Repository**: +```yaml +source: + id: ubuntu-server +``` + +**Minimal Installation**: +```yaml +source: + id: ubuntu-server-minimal +``` + +This comprehensive set of examples provides tested configurations for common deployment scenarios, enabling rapid customization for specific requirements. \ No newline at end of file diff --git a/README.md b/README.md index 2f8c83a..59756a2 100644 --- a/README.md +++ b/README.md @@ -1,115 +1,240 @@ -# Custom ISO Editor and Docker Server +# Custom ISO Builder for Ubuntu Server Automation -The main goal of this project is to provide faster `up2 squared` installations and support for rapid deployment. +## 🎯 Project Overview -Throughout this work, it is assumed that we have ```our own .iso file on USB```. -Our `grub.cfg` file determines which menu section we enter during the installation phase. -By default, we aim to connect through the docker server. This way, rather than using the one-time written ISO file, the server running on docker will be more active. +This project enables automated creation of customized Ubuntu 22.04 Server ISO images optimized for rapid deployment on embedded systems, particularly UP2 boards and APU/APU2 industrial computers. -### Installation by editing `pressed/user-data` through ISO file +### Key Features -The goal is to provide a quick installation by specifying the user-data path in the grub.cfg file found in Ubuntu 22.04 Server. By editing the Ubuntu 22.04 server `pressed/user-data` file, the installation of all files we expect to come by default is provided. +- **Automated Installation**: Pre-configured settings for fully automated server deployments +- **Dual Deployment Methods**: Choose between ISO-based or Docker server-based installation +- **APU/APU2 Optimization**: Specifically configured for industrial embedded systems +- **Network Boot Support**: HTTP-based configuration delivery for dynamic updates +- **Minimal User Intervention**: One-time setup for multiple deployments -### Installation by editing `user-data` through Docker Server +## πŸ—οΈ Architecture Overview -Since the ```grub.cfg``` inside our initially edited .iso file will remain fixed in any case, it is sufficient to just run the server during the installation phase. If new code is added to user-data, it needs to be built and the server needs to be restarted. +``` +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ CUSTOM ISO BUILDER β”‚ +β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ +β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ +β”‚ β”‚ ISO EDITOR β”‚ β”‚ DOCKER SERVER β”‚ β”‚ +β”‚ β”‚ - Ubuntu Base β”‚ β”‚ - HTTP Server β”‚ β”‚ +β”‚ β”‚ - GRUB Config β”‚ β”‚ - Network: 172.20.0.0 β”‚ β”‚ +β”‚ β”‚ - User Data β”‚ β”‚ - Port: 3003 β”‚ β”‚ +β”‚ β”‚ - Meta Data β”‚ β”‚ - Real-time Updates β”‚ β”‚ +β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` + +The system operates under the assumption that you have a customized ISO file on USB media. The `grub.cfg` file controls the boot menu selection during installation, defaulting to network-based configuration via the Docker server for maximum flexibility. + +## πŸ“– Installation Methods + +### Method 1: ISO-Based Installation + +**Direct installation using embedded `pressed/user-data` configuration** + +This method modifies the Ubuntu 22.04 Server ISO to include pre-configured installation parameters. The GRUB bootloader is configured to automatically locate and use the embedded user-data file, enabling completely automated installations. + +**Advantages:** +- Offline installation capability +- Self-contained deployment medium +- No network dependencies during installation +- Portable via USB media + +**Use Cases:** +- Remote locations without reliable network connectivity +- Security-sensitive environments requiring air-gapped installations +- Field deployments where network infrastructure is unavailable + +### Method 2: Docker Server-Based Installation + +**Dynamic configuration delivery via HTTP server** + +The initial ISO contains a fixed `grub.cfg` that points to a network-based configuration server. During installation, the target system downloads current configuration files from the Docker server, allowing for real-time updates without recreating ISO images. -The defined IP address for our docker server is `subnet=172.20.0.1` -Our docker server port is `port 3003` +**Advantages:** +- Dynamic configuration updates +- Centralized management of multiple deployments +- Real-time customization based on target system requirements +- Reduced ISO recreation overhead -#### NOTE +**Network Configuration:** +- Docker subnet: `172.20.0.0/24` +- Server IP: `172.20.0.2` +- Service port: `3003` -```user-data``` sample code is from github subiquity example. -`early-commands` - the first codes that will run at the beginning start from here in this code script. -`packages` - adding packages to be used in the written operating system. -`late-commands` - our final commands while writing the iso file. -`identity` - must be in every file. +**Use Cases:** +- Large-scale deployments requiring consistent updates +- Development environments with frequent configuration changes +- Centralized IT management scenarios -You can find more content in your own examples [example link](https://github.com/canonical/subiquity/tree/main/examples/autoinstall) +## πŸ”§ Configuration Reference + +### Cloud-Init User-Data Structure + +The configuration system uses Ubuntu's Subiquity autoinstall format, based on cloud-init user-data specifications. Below is the essential structure: ```yaml version: 1 early-commands: - - echo a + - echo "Starting pre-installation setup" - sleep 1 - - echo a -debconf-selections: eek + - echo "System initialization complete" packages: - - package1 - - package2 + - openssh-server + - curl + - wget + - git late-commands: - - echo a - - sleep 1 - - echo a + - echo "Finalizing installation" + - systemctl enable ssh + - echo "Post-installation tasks complete" keyboard: - layout: gb + layout: us source: id: ubuntu-server-minimal updates: security -user-data: - users: - - name: ubuntu - passwd: '$6$wdAcoXrU039hKYPd$508Qvbe7ObUnxoj15DRCkzC3qO7edjH0VV7BPNRDYK4QR8ofJaEEF2heacn0QgD.f8pO8SNp83XNdWG6tocBM1' +identity: + hostname: ubuntu-server + username: ubuntu + password: '$6$wdAcoXrU039hKYPd$508Qvbe7ObUnxoj15DRCkzC3qO7edjH0VV7BPNRDYK4QR8ofJaEEF2heacn0QgD.f8pO8SNp83XNdWG6tocBM1' +``` + +### Configuration Sections Explained + +- **early-commands**: Scripts executed at the start of installation, before partitioning +- **packages**: Additional software packages to install during system setup +- **late-commands**: Final scripts executed after system installation but before reboot +- **identity**: User account configuration (required in all configurations) +- **keyboard**: Input method and layout specifications +- **source**: Ubuntu installation source variant selection + +**Reference Documentation**: [Canonical Subiquity Examples](https://github.com/canonical/subiquity/tree/main/examples/autoinstall) + +### Password Generation + +Secure password hashes are required for user account creation. Use these commands to generate properly formatted passwords: + +```bash +# Generate password hash for string "ubuntu" +openssl passwd -6 -salt $(openssl rand -hex 8) "ubuntu" + +# Generate password hash for numeric password +openssl passwd -6 -salt $(openssl rand -hex 8) "1" ``` -#### NOTE: +## πŸš€ Automated ISO Creation Workflow -Password generation code required for creating passwords. +The build process is fully automated through Makefile targets, optimized for APU/APU2 system compatibility. These industrial-grade embedded systems feature high clock speeds and multi-core architectures, requiring specific bootloader configurations. + +### Build Commands Overview + +**System Preparation:** +- `make iso_depends` - Install required system dependencies and tools +- `make iso_download` - Download Ubuntu 22.04 Server ISO from official repository +- `make iso_init` - Extract ISO contents to working directory (`iso_root`) + +**Configuration Integration:** +- `make iso_setup` - Integrate custom configuration files from `config/` directory +- `make iso_setup-isolinux` - Apply APU/APU2-specific ISOLINUX bootloader configuration + +**ISO Generation:** +- `make iso_geniso` - Create standard GRUB-based ISO image +- `make iso_geniso-isolinux` - Generate APU/APU2-optimized ISO with ISOLINUX bootloader + +**Deployment:** +- `make iso_write_usb` - Automatically write latest ISO to connected USB devices + +**⚠️ WARNING**: `make iso_write_usb` will overwrite USB devices automatically. Ensure no important data is stored on connected USB drives. + +![USB Writing Process](./images/iso_write_usb_hub.jpg) + +### Complete Build Process + +For first-time setup, execute the following sequence: ```bash -openssl passwd -6 -salt $(openssl rand -hex 8) "ubuntu" #string -openssl passwd -6 -salt $(openssl rand -hex 8) 1 +# Initial system preparation +make iso_depends +make iso_download +make iso_init + +# Configuration and customization +make iso_setup +make iso_setup-isolinux + +# Generate final ISO image +make iso_geniso-isolinux ``` -# Automatic ISO Configuration +Upon successful completion without errors: -The codes in this section have been automated within the makefile. -Our commands: +```bash +# Deploy to USB media +make iso_write_usb +``` -Our code generics are written to be compatible with APU/APU2 systems for flight information. Since the APU system runs at high clock speeds, performance is quite good. To be compatible with this, call the codes named `isolinux` in your codes. -```Intel's APU systems tend to have higher clock speeds and more cores. These features enable Intel's APU systems to perform well on the CPU side. Secondly, AMD's APU systems have gained more popularity than Intel's.``` +### APU/APU2 System Optimization -`make iso_depends` downloads the missing files in the operating system. -`make iso_download` downloads ubuntu 22.04 server directly into the defined file structure. -`make iso_init` extracts the downloaded iso file into the defined `iso_root` folder. -`make iso_setup` integrates our codes in the config folder into the system. -`make iso_setup-isolinux` edits our codes according to apu/apu2. -`make iso_geniso` compresses the `iso_root` file in iso format. -`make iso_geniso-isolinux` produces the iso file according to apu/apu2 system from the `iso_root` file. +Intel APU systems typically feature higher clock speeds and more CPU cores compared to AMD alternatives, providing superior computational performance. The ISOLINUX bootloader configuration ensures optimal compatibility with these industrial embedded systems. -`make iso_write_usb` enables automatic loading of the latest produced iso file into connected USBs. `Be careful about this - don't have USB connected to your device` +Configuration automatically includes: +- High-performance CPU scheduling parameters +- Optimized memory management for embedded systems +- Hardware-specific driver selection +- Power management tuning for industrial environments -![iso_write_usb](./images/iso_write_usb_hub.jpg) +## 🌐 Docker Server Deployment -If the codes are being run for the first time, you should say `make iso_depends`. - - $ make iso_depends - $ make iso_download - $ make iso_init - - $ make iso_setup - $ make iso_setup-isolinux - - $ make iso_geniso-isolinux - -If no errors are received as a result of these operations: +The Docker server provides dynamic configuration delivery during installation, enabling centralized management of multiple system deployments. - $ make iso_write_usb -This provides direct automatic installation to USBs. +![Network Sharing Setup](./images/share_internet_for_up2.jpg) +*Network topology for Docker server deployment* -![share_internet_for_up2.jpg](./images/share_internet_for_up2.jpg) -Image taken from the internet. +### Server Setup Process -By connecting your computer to any router, we must build our docker server and then run it. +Connect your development machine to the network infrastructure (router/switch), then build and launch the configuration server: - $ make iso_server_build - $ make iso_server_run +```bash +# Build Docker server image +make iso_server_build -No settings are needed for the server. After the main computer is connected to the switch, it performs the automatic installation itself. +# Launch configuration server +make iso_server_run ``` -server ip address 172.20.0.2 -port: 3003 - there was no issue of conflict with the host computer's port. + +### Network Configuration + +The server automatically configures the following network parameters: + +- **Server IP Address**: `172.20.0.2` +- **Service Port**: `3003` (no conflicts with host system ports) +- **Network Subnet**: `172.20.0.0/24` + +No manual network configuration is required. Once the development machine connects to the switch/router, target systems will automatically locate and use the configuration server during installation. + +### Server Management + +**Access server shell for debugging or monitoring:** +```bash +make iso_server_shell ``` -To connect to the server shell: - $ make iso_server_shell \ No newline at end of file +**Server features:** +- Automatic service discovery for target systems +- Real-time configuration updates without ISO recreation +- Centralized logging of installation progress +- Support for multiple concurrent installations + +### Installation Flow + +1. Target system boots from custom ISO media +2. GRUB configuration automatically detects network server +3. Installation system downloads current configuration files +4. Automated installation proceeds with latest settings +5. Server logs installation progress and completion status + +This approach eliminates the need to recreate ISO images for configuration changes, significantly improving deployment efficiency in dynamic environments. \ No newline at end of file diff --git a/custom-iso-editor/Makefile b/custom-iso-editor/Makefile index 3258144..7e67051 100644 --- a/custom-iso-editor/Makefile +++ b/custom-iso-editor/Makefile @@ -1,39 +1,82 @@ -UBUNTU_VERSION = 22.04.3 -UBUNTU_RELEASE = 22.04 +# ================================================ +# CUSTOM ISO BUILDER - MAKEFILE CONFIGURATION +# ================================================ +# This Makefile automates the creation of customized Ubuntu 22.04 Server +# ISO images optimized for embedded systems, particularly APU/APU2 hardware. +# +# Features: +# - Automated ISO download and extraction +# - Configuration file integration +# - APU/APU2-specific optimizations +# - USB deployment automation +# - Docker server integration +# +# Usage: Run 'make help' for available commands +# ================================================ + +# ================================================ +# UBUNTU VERSION CONFIGURATION +# ================================================ +UBUNTU_VERSION = 22.04.3 # Ubuntu version to use +UBUNTU_RELEASE = 22.04 # Ubuntu release number ISO_URLBASE = https://releases.ubuntu.com/$(UBUNTU_RELEASE)/ ISO_FILENAME_DOWNLOAD = ubuntu-$(UBUNTU_VERSION)-live-server-amd64.iso ISO_FILENAME = $(PWD)/custom-iso-editor/ubuntu-$(UBUNTU_VERSION)-live-server-amd64.iso -ISO_MOUNTPOINT = /mnt/user_custom_iso -ISO_ROOT = $(PWD)/custom-iso-editor/iso_root -ISO_FILES = $(PWD)/custom-iso-editor/user_iso_files -## copy files +# ================================================ +# DIRECTORY STRUCTURE CONFIGURATION +# ================================================ +ISO_MOUNTPOINT = /mnt/user_custom_iso # Temporary mount point for ISO extraction +ISO_ROOT = $(PWD)/custom-iso-editor/iso_root # Extracted ISO contents directory +ISO_FILES = $(PWD)/custom-iso-editor/user_iso_files # Generated ISO output directory + +# ================================================ +# CONFIGURATION FILE MAPPING +# ================================================ +# Source and destination paths for custom configuration files + +## GRUB bootloader configuration GRUBCFG_SRC = $(PWD)/custom-iso-editor/config/boot/grub/grub.cfg GRUBCFG_DEST = $(PWD)/custom-iso-editor/iso_root/boot/grub/grub.cfg + +## Cloud-init autoinstall configuration USERDATA_SRC = $(PWD)/custom-iso-editor/config/user-data USERDATA_DEST =$(PWD)/custom-iso-editor/iso_root/pressed/user-data + +## System metadata configuration METADATA_SRC = $(PWD)/custom-iso-editor/config/meta-data METADATA_DEST = $(PWD)/custom-iso-editor/iso_root/pressed/meta-data + +## Additional custom files (scripts, certificates, etc.) EXTRAS_SRCDIR = $(PWD)/custom-iso-editor/config/extras/ EXTRAS_DESTDIR = $(PWD)/custom-iso-editor/iso_root/extras/ - -GENISO_LABEL = UserCustomISO +# ================================================ +# ISO GENERATION CONFIGURATION +# ================================================ +GENISO_LABEL = UserCustomISO # Volume label for generated ISO +# Timestamped filename for output ISO GENISO_FILENAME = $(PWD)/custom-iso-editor/user_iso_files/user-custom-autoinstaller.$(shell date +%Y%m%d.%H%M%S).iso -GENISO_BOOTIMG = boot/grub/i386-pc/eltorito.img -GENISO_BOOTCATALOG = /boot.catalog +GENISO_BOOTIMG = boot/grub/i386-pc/eltorito.img # GRUB boot image path +GENISO_BOOTCATALOG = /boot.catalog # Boot catalog file location +# Dynamic sector calculation from original ISO GENISO_START_SECTOR = $(shell sudo fdisk -l $(ISO_FILENAME) |grep iso2 | cut -d' ' -f2) GENISO_END_SECTOR = $(shell sudo fdisk -l $(ISO_FILENAME) |grep iso2 | cut -d' ' -f3) -GENISO_LANG = C +GENISO_LANG = C # Language setting (C = English/Universal) -## for APU/APU2 -GENISO_ISOLINUX = /usr/lib/ISOLINUX/isolinux.bin -GENISO_ISOLINUX_MODULEDIR = /usr/lib/syslinux/modules/bios/ -GENISO_HYBRIDMBR = /usr/lib/ISOLINUX/isohdpfx.bin -ISOLINUX_CONFIGDIR = $(PWD)/custom-iso-editor/config/isolinux -ISOLINUX_DIRNAME = isolinux +# ================================================ +# APU/APU2 SYSTEM OPTIMIZATION SETTINGS +# ================================================ +# APU systems use BIOS-based boot instead of UEFI, requiring ISOLINUX bootloader +GENISO_ISOLINUX = /usr/lib/ISOLINUX/isolinux.bin # ISOLINUX bootloader binary +GENISO_ISOLINUX_MODULEDIR = /usr/lib/syslinux/modules/bios/ # SYSLINUX modules directory +GENISO_HYBRIDMBR = /usr/lib/ISOLINUX/isohdpfx.bin # Hybrid MBR for USB compatibility +ISOLINUX_CONFIGDIR = $(PWD)/custom-iso-editor/config/isolinux # ISOLINUX configuration source +ISOLINUX_DIRNAME = isolinux # Directory name in ISO -## Colors +# ================================================ +# COLOR DEFINITIONS FOR OUTPUT FORMATTING +# ================================================ COLOR_RED = \033[5;31m COLOR_GREEN = \033[5;32m COLOR_ORANGE = \033[5;33m @@ -45,47 +88,146 @@ COLOR_RESET = \033[0m BLINK = \033[5m UNDERLINE = \033[4m +# ================================================ +# MAKEFILE TARGETS +# ================================================ +.PHONY: help +help: ## Show this help message + @echo "$(COLOR_BLUE)Custom ISO Builder - Available Commands$(COLOR_RESET)" + @echo "$(COLOR_GRAY)========================================$(COLOR_RESET)" + @echo "" + @echo "$(COLOR_GREEN)Setup Commands:$(COLOR_RESET)" + @echo " iso_depends - Install required system dependencies" + @echo " iso_download - Download Ubuntu 22.04 Server ISO" + @echo " iso_init - Extract ISO contents for modification" + @echo "" + @echo "$(COLOR_GREEN)Configuration Commands:$(COLOR_RESET)" + @echo " iso_setup - Apply custom configuration files" + @echo " iso_setup-isolinux - Apply APU/APU2-specific configuration" + @echo "" + @echo "$(COLOR_GREEN)ISO Generation Commands:$(COLOR_RESET)" + @echo " iso_geniso - Generate standard GRUB-based ISO" + @echo " iso_geniso-isolinux - Generate APU/APU2-optimized ISO" + @echo "" + @echo "$(COLOR_GREEN)Deployment Commands:$(COLOR_RESET)" + @echo " iso_write_usb - $(COLOR_RED)⚠️ WARNING: Write ISO to USB (destructive!)$(COLOR_RESET)" + @echo "" + @echo "$(COLOR_GREEN)Docker Server Commands:$(COLOR_RESET)" + @echo " iso_server_build - Build Docker configuration server" + @echo " iso_server_run - Run Docker configuration server" + @echo " iso_server_shell - Access server shell for debugging" + @echo "" + @echo "$(COLOR_GREEN)Utility Commands:$(COLOR_RESET)" + @echo " status - Show current build status" + @echo " clean - Clean up temporary files" + @echo "" + @echo "$(COLOR_ORANGE)Quick Start:$(COLOR_RESET)" + @echo " make iso_depends && make iso_download && make iso_init" + @echo " make iso_setup && make iso_setup-isolinux" + @echo " make iso_geniso-isolinux" + @echo "" + +.PHONY: status +status: ## Show current build status and file information + @echo "$(COLOR_BLUE)Custom ISO Builder - Current Status$(COLOR_RESET)" + @echo "$(COLOR_GRAY)====================================$(COLOR_RESET)" + @echo "" + @echo "$(COLOR_GREEN)Configuration:$(COLOR_RESET)" + @echo " Ubuntu Version: $(UBUNTU_VERSION)" + @echo " ISO Source: $(ISO_URLBASE)" + @echo "" + @echo "$(COLOR_GREEN)File Status:$(COLOR_RESET)" + @if [ -f "$(ISO_FILENAME)" ]; then \ + echo " βœ“ Ubuntu ISO: $(COLOR_GREEN)Downloaded$(COLOR_RESET) ($(shell du -h $(ISO_FILENAME) | cut -f1))"; \ + else \ + echo " βœ— Ubuntu ISO: $(COLOR_RED)Not found$(COLOR_RESET) - run 'make iso_download'"; \ + fi + @if [ -d "$(ISO_ROOT)" ]; then \ + echo " βœ“ ISO Contents: $(COLOR_GREEN)Extracted$(COLOR_RESET) ($(shell du -sh $(ISO_ROOT) | cut -f1))"; \ + else \ + echo " βœ— ISO Contents: $(COLOR_RED)Not extracted$(COLOR_RESET) - run 'make iso_init'"; \ + fi + @if [ -d "$(ISO_FILES)" ]; then \ + echo " βœ“ Output Directory: $(COLOR_GREEN)Ready$(COLOR_RESET)"; \ + @ls -la $(ISO_FILES)/*.iso 2>/dev/null | wc -l | xargs -I {} echo " Generated ISOs: {}" || echo " Generated ISOs: 0"; \ + else \ + echo " βœ— Output Directory: $(COLOR_RED)Not created$(COLOR_RESET)"; \ + fi + + + +.PHONY: iso_depends +iso_depends: ## Install required system dependencies + @echo "$(COLOR_BLUE)Installing system dependencies...$(COLOR_RESET)" + sudo apt update + sudo apt install -y xorriso rsync isolinux syslinux-utils genisoimage wget curl .PHONY: iso_download -iso_download: +iso_download: ## Download Ubuntu 22.04 Server ISO from official repository + @echo "$(COLOR_BLUE)Downloading Ubuntu $(UBUNTU_VERSION) Server ISO...$(COLOR_RESET)" + @echo "Source: $(ISO_URLBASE)$(ISO_FILENAME_DOWNLOAD)" wget -O ${ISO_FILENAME} -N $(ISO_URLBASE)/$(ISO_FILENAME_DOWNLOAD) + @echo "$(COLOR_GREEN)Download completed: $(ISO_FILENAME)$(COLOR_RESET)" .PHONY: iso_init -iso_init: +iso_init: ## Extract ISO contents and prepare working directory + @echo "$(COLOR_BLUE)Initializing ISO working environment...$(COLOR_RESET)" sudo apt install xorriso rsync + # Backup existing ISO_ROOT if present ( test -d $(ISO_ROOT) && mv -f $(ISO_ROOT) $(ISO_ROOT).$(shell date +%Y%m%d.%H%M%S) ) || true + # Create required directories mkdir -p $(ISO_ROOT) mkdir -p $(ISO_ROOT)/pressed mkdir -p $(ISO_ROOT)/extras mkdir -p $(ISO_FILES) sudo mkdir -p $(ISO_MOUNTPOINT) + # Mount and extract ISO contents (mountpoint $(ISO_MOUNTPOINT) && sudo umount -q $(ISO_MOUNTPOINT)) || true + @echo "$(COLOR_ORANGE)Mounting ISO and extracting contents...$(COLOR_RESET)" sudo mount -o ro,loop $(ISO_FILENAME) $(ISO_MOUNTPOINT) rsync -av $(ISO_MOUNTPOINT)/. $(ISO_ROOT)/. sudo umount $(ISO_MOUNTPOINT) + @echo "$(COLOR_GREEN)ISO extraction completed$(COLOR_RESET)" .PHONY: iso_setup -iso_setup: +iso_setup: ## Apply custom configuration files to extracted ISO + @echo "$(COLOR_BLUE)Applying custom configuration files...$(COLOR_RESET)" chmod 755 $(ISO_ROOT) + # Apply GRUB configuration + @echo " - Installing GRUB configuration" chmod 644 $(GRUBCFG_DEST) cp -f $(GRUBCFG_SRC) $(GRUBCFG_DEST) + # Apply cloud-init configuration + @echo " - Installing cloud-init user-data" chmod 755 $(ISO_ROOT) cp -f $(USERDATA_SRC) $(USERDATA_DEST) cp -f $(METADATA_SRC) $(METADATA_DEST) + # Copy additional files + @echo " - Installing additional files" rsync -av $(EXTRAS_SRCDIR)/. $(EXTRAS_DESTDIR)/. + @echo "$(COLOR_GREEN)Configuration setup completed$(COLOR_RESET)" .PHONY: iso_setup-isolinux -iso_setup-isolinux: +iso_setup-isolinux: ## Apply APU/APU2-specific ISOLINUX bootloader configuration + @echo "$(COLOR_BLUE)Configuring ISOLINUX for APU/APU2 systems...$(COLOR_RESET)" chmod 755 $(ISO_ROOT) + # Install ISOLINUX dependencies sudo apt install isolinux syslinux-common + # Copy ISOLINUX bootloader + @echo " - Installing ISOLINUX bootloader" cp $(GENISO_ISOLINUX) $(ISO_ROOT)/ + # Setup ISOLINUX configuration directory + @echo " - Setting up ISOLINUX modules and configuration" mkdir -p $(ISO_ROOT)/$(ISOLINUX_DIRNAME) rsync -av $(GENISO_ISOLINUX_MODULEDIR)/. $(ISO_ROOT)/$(ISOLINUX_DIRNAME)/. rsync -av $(ISOLINUX_CONFIGDIR)/. $(ISO_ROOT)/$(ISOLINUX_DIRNAME)/. + @echo "$(COLOR_GREEN)ISOLINUX configuration completed$(COLOR_RESET)" .PHONY: iso_geniso -iso_geniso: +iso_geniso: ## Generate standard GRUB-based ISO image + @echo "$(COLOR_BLUE)Generating GRUB-based ISO image...$(COLOR_RESET)" + @echo "Output: $(GENISO_FILENAME)" sudo env LANG=$(GENISO_LANG) xorriso -as mkisofs -volid $(GENISO_LABEL) \ -output $(GENISO_FILENAME) \ -eltorito-boot $(GENISO_BOOTIMG) \ @@ -96,9 +238,12 @@ iso_geniso: -e '--interval:appended_partition_2_start_1782357s_size_8496d:all::' \ --grub2-mbr --interval:local_fs:0s-15s:zero_mbrpt,zero_gpt:'$(ISO_FILENAME)' \ "${ISO_ROOT}" + @echo "$(COLOR_GREEN)GRUB-based ISO generation completed$(COLOR_RESET)" .PHONY: iso_geniso-isolinux -iso_geniso-isolinux: +iso_geniso-isolinux: ## Generate APU/APU2-optimized ISO with ISOLINUX bootloader + @echo "$(COLOR_BLUE)Generating APU/APU2-optimized ISO with ISOLINUX...$(COLOR_RESET)" + @echo "Output: $(GENISO_FILENAME)" sudo env LANG=$(GENISO_LANG) xorriso -as mkisofs -volid $(GENISO_LABEL) \ -output $(GENISO_FILENAME) \ -eltorito-boot /$(shell basename $(GENISO_ISOLINUX)) \ @@ -109,36 +254,64 @@ iso_geniso-isolinux: -isohybrid-mbr $(GENISO_HYBRIDMBR) \ -e '--interval:appended_partition_2_start_1782357s_size_8496d:all::' \ "${ISO_ROOT}" + @echo "$(COLOR_GREEN)APU/APU2-optimized ISO generation completed$(COLOR_RESET)" .PHONY: iso_write_usb -iso_write_usb: - latest_iso=$(shell ls -t $(ISO_FILES)/user-custom-autoinstaller.*.iso | head -n 1); \ - echo "$(COLOR_BLUE)Yazdirilacak son ISO bulunuyor....$(COLOR_RESET)"; \ +iso_write_usb: ## ⚠️ WARNING: Write latest ISO to USB devices (DESTRUCTIVE!) + @echo "$(COLOR_RED)$(BLINK)⚠️ WARNING: This command will overwrite USB devices!$(COLOR_RESET)" + @echo "$(COLOR_ORANGE)Make sure no important data is stored on connected USB devices$(COLOR_RESET)" + @echo "" + latest_iso=$$(ls -t $(ISO_FILES)/user-custom-autoinstaller.*.iso | head -n 1); \ + echo "$(COLOR_BLUE)Locating latest ISO file...$(COLOR_RESET)"; \ if [ -z "$$latest_iso" ]; then \ - echo -e "$(COLOR_RED)No ISO file found.$(COLOR_RESET)"; \ + echo -e "$(COLOR_RED)No ISO file found. Run 'make iso_geniso-isolinux' first.$(COLOR_RESET)"; \ + exit 1; \ else \ echo "$(COLOR_GREEN)Latest ISO file: $(UNDERLINE)$$latest_iso$(COLOR_RESET)"; \ fi; \ usb_device=$$(lsblk -npl -o NAME,TYPE | awk '$$2=="disk" && $$1 ~ /^\/dev\/sd[a-z]/ {print $$1}'); \ + if [ -z "$$usb_device" ]; then \ + echo "$(COLOR_RED)No USB devices detected$(COLOR_RESET)"; \ + exit 1; \ + fi; \ for disk in $$usb_device; do \ - echo "$(COLOR_GRAY)Found SD disk: $(COLOR_GREEN)$$disk$(COLOR_RESET)"; \ - echo "$(COLOR_GRAY_BLINK)Harun Kahve Icmeye gidebilirsin...$(COLOR_RESET)"; \ - yes | sudo mkfs -t ext4 "$$disk"; \ + echo "$(COLOR_GRAY)Found USB disk: $(COLOR_GREEN)$$disk$(COLOR_RESET)"; \ + echo "$(COLOR_ORANGE)Writing ISO to $$disk - This may take several minutes...$(COLOR_RESET)"; \ sudo dd if="$$latest_iso" of="$$disk" bs=4M status=progress; \ - echo "$(COLOR_GRAY_BLINK_UNDERLINE)--------------------------------------------------------$(COLOR_RESET)"; \ + sync; \ + echo "$(COLOR_GREEN)Successfully written to $$disk$(COLOR_RESET)"; \ + echo "$(COLOR_GRAY)--------------------------------------------------------$(COLOR_RESET)"; \ done; \ + echo "$(COLOR_GREEN)USB writing completed$(COLOR_RESET)" + +.PHONY: clean +clean: ## Clean up temporary files and directories + @echo "$(COLOR_BLUE)Cleaning up temporary files...$(COLOR_RESET)" + @make iso_clean-up-all + @echo "$(COLOR_GREEN)Cleanup completed$(COLOR_RESET)" +.PHONY: iso_clean-up-all +iso_clean-up-all: ## Remove all generated files and directories + @echo "$(COLOR_ORANGE)Removing all generated files and directories...$(COLOR_RESET)" + sudo rm -rf ${ISO_ROOT} + sudo rm -rf ${ISO_FILES} + sudo rm -rf ${ISO_ROOT}.* + @echo "$(COLOR_GREEN)All files cleaned up$(COLOR_RESET)" -# Chroot function +# ================================================ +# CHROOT FUNCTIONALITY FOR ADVANCED DEBUGGING +# ================================================ + +# Chroot function for system debugging define chroot sudo chroot $(ISO_ROOT) $(1) endef -# ... (Rest of your Makefile) - .PHONY: iso_chroot-shell -iso_chroot-shell: +iso_chroot-shell: ## Access chroot shell for advanced ISO debugging + @echo "$(COLOR_BLUE)Entering chroot environment...$(COLOR_RESET)" + @echo "$(COLOR_ORANGE)Use 'exit' to leave the chroot environment$(COLOR_RESET)" sudo mount --bind /dev $(ISO_ROOT)/dev sudo mount --bind /proc $(ISO_ROOT)/proc sudo mount --bind /sys $(ISO_ROOT)/sys @@ -146,19 +319,5 @@ iso_chroot-shell: sudo umount $(ISO_ROOT)/dev sudo umount $(ISO_ROOT)/proc sudo umount $(ISO_ROOT)/sys - - - -.PHONY: clean -clean: - echo User ISO Dosyalar temizlendi. - @make iso_clean-up-all - # find . -type f -a -user "$(shell id -un)" -a -name '*~' -exec rm {} \; -print - - -.PHONY: iso_clean-up-all -iso_clean-up-all: clean - sudo rm -rf ${ISO_ROOT} - sudo rm -rf ${ISO_FILES} - sudo rm -rf ${ISO_ROOT}.* + @echo "$(COLOR_GREEN)Chroot session ended$(COLOR_RESET)" diff --git a/custom-iso-editor/config/user-data b/custom-iso-editor/config/user-data index ccb8017..3756893 100644 --- a/custom-iso-editor/config/user-data +++ b/custom-iso-editor/config/user-data @@ -1,28 +1,98 @@ #cloud-config +# ================================================ +# UBUNTU SERVER AUTOINSTALL CONFIGURATION +# ================================================ +# This cloud-init configuration provides automated installation +# for Ubuntu 22.04 Server with custom user setup and packages. +# +# Configuration sections: +# - identity: User account and system identification +# - early-commands: Pre-installation setup tasks +# - packages: Additional software to install +# - late-commands: Post-installation configuration +# ================================================ + autoinstall: version: 1 + + # ================================================ + # SYSTEM IDENTITY CONFIGURATION + # ================================================ identity: - realname: User - hostname: user-server + realname: "Server Administrator" + hostname: ubuntu-server + # Default password: "1" (change for production use) password: '$6$74c2fbdbb4ca6c77$2IVdUExCZ9sn6KakQ3HgqYE0xCKydWY8gPGZEYOX7gn8vOqPYopRfqdqDYJyyGvx2qJ40lOyV2eaSt4xQ1F0I1' username: user + + # ================================================ + # PRE-INSTALLATION SETUP COMMANDS + # ================================================ early-commands: - - echo -e "\e[31mEarly Commands Started...\e[0m" - - apt install unzip - - echo -e "\e[32mUnzip package installed for outzip file\e[0m" - - echo -e "\e[31mFiles will be organized...\e[0m" + - echo -e "\e[34m[SETUP] Starting early installation commands...\e[0m" + - apt update + - apt install -y unzip curl wget + - echo -e "\e[32m[SETUP] Essential packages installed\e[0m" + - echo -e "\e[34m[SETUP] Preparing system configuration...\e[0m" + + # ================================================ + # PACKAGE INSTALLATION LIST + # ================================================ packages: - - unzip - - net-tools - locale: en_US + - openssh-server # SSH server for remote access + - unzip # Archive extraction utility + - curl # HTTP client tool + - wget # Download utility + - net-tools # Network configuration tools + - htop # System monitoring + - vim # Text editor + - git # Version control + + # ================================================ + # LOCALIZATION SETTINGS + # ================================================ + locale: en_US.UTF-8 keyboard: - layout: tr + layout: us # Change to your preferred keyboard layout + + # ================================================ + # USER ACCOUNT CONFIGURATION + # ================================================ user-data: users: - name: user - # password : 1 - passwd: '$6$74c2fbdbb4ca6c77$2IVdUExCZ9sn6KakQ3HgqYE0xCKydWY8gPGZEYOX7gn8vOqPYopRfqdqDYJyyGvx2qJ40lOyV2eaSt4xQ1F0I1' + # Default password: "1" + # Generate new password with: openssl passwd -6 -salt $(openssl rand -hex 8) "your_password" + passwd: '$6$74c2fbdbb4ca6c77$2IVdUExCZ9sn6KakQ3HgqYE0xCKydWY8gPGZEYOX7gn8vOqPYopRfqdqDYJyyGvx2qJ40lOyV2eaSt4xQ1F0I1' + shell: /bin/bash + groups: [sudo, users] + sudo: ALL=(ALL) NOPASSWD:ALL + + # ================================================ + # POST-INSTALLATION CONFIGURATION COMMANDS + # ================================================ late-commands: - - cp /cdrom/extras/user.sudoers /target/etc/sudoers.d/99-user-user - - curtin in-target --target=/target -- apt-get install -y unzip - - curtin in-target --target=/target -- mkdir /home/user/ + - echo -e "\e[34m[CONFIG] Starting post-installation configuration...\e[0m" + + # Configure sudo access + - cp /cdrom/extras/user.sudoers /target/etc/sudoers.d/99-user-user || true + + # Install additional packages in target system + - curtin in-target --target=/target -- apt-get update + - curtin in-target --target=/target -- apt-get install -y unzip curl wget + + # Create user home directory structure + - curtin in-target --target=/target -- mkdir -p /home/user/ + - curtin in-target --target=/target -- chown user:user /home/user/ + + # Enable and configure SSH + - curtin in-target --target=/target -- systemctl enable ssh + + # Set timezone (change as needed) + - curtin in-target --target=/target -- timedatectl set-timezone UTC + + # Final system update + - curtin in-target --target=/target -- apt-get update && apt-get upgrade -y + + - echo -e "\e[32m[CONFIG] Post-installation configuration completed\e[0m" + - echo -e "\e[36m[INFO] System ready for first boot\e[0m" diff --git a/custom-iso-server/Makefile b/custom-iso-server/Makefile index 3ad79f3..0aec685 100644 --- a/custom-iso-server/Makefile +++ b/custom-iso-server/Makefile @@ -1,30 +1,91 @@ +# ================================================ +# CUSTOM ISO DOCKER SERVER - MAKEFILE +# ================================================ +# This Makefile manages the Docker-based configuration server +# that provides dynamic configuration delivery during ISO installation. +# +# Network Configuration: +# - Subnet: 172.20.0.0/16 +# - Gateway: 172.20.0.1 +# - Server IP: 172.20.0.2 +# - Service Port: 3003 +# ================================================ + +# Docker command with sudo access DOCKER:= sudo docker + +# Network configuration for Docker server GATEWAY:=172.20.0.1 IP:=172.20.0.2 +NETWORK_NAME:=custom_iso_network +SUBNET:=172.20.0.0/16 +# Color definitions for output +COLOR_BLUE = \033[0;34m +COLOR_GREEN = \033[0;32m +COLOR_ORANGE = \033[0;33m +COLOR_RED = \033[0;31m +COLOR_RESET = \033[0m -all: iso_server_build server_run +# ================================================ +# MAKEFILE TARGETS +# ================================================ -iso_server_build: - $(DOCKER) network create --subnet=172.20.0.0/16 --gateway=172.20.0.1 custom_iso_network || true - $(DOCKER) build -t docker_server_user --file $(PWD)/custom-iso-server/server.Dockerfile $(PWD)/custom-iso-server/ +.PHONY: help +help: ## Show available Docker server commands + @echo "$(COLOR_BLUE)Custom ISO Docker Server - Available Commands$(COLOR_RESET)" + @echo "$(COLOR_BLUE)=============================================$(COLOR_RESET)" + @echo "" + @echo "$(COLOR_GREEN)Server Management:$(COLOR_RESET)" + @echo " iso_server_build - Build Docker configuration server image" + @echo " iso_server_run - Run Docker configuration server" + @echo " iso_server_shell - Access server shell for debugging" + @echo "" + @echo "$(COLOR_GREEN)Maintenance:$(COLOR_RESET)" + @echo " iso_server_clean - Remove Docker network and containers" + @echo " clean - Full cleanup of server components" + @echo "" + @echo "$(COLOR_ORANGE)Network Information:$(COLOR_RESET)" + @echo " Network: $(SUBNET)" + @echo " Gateway: $(GATEWAY)" + @echo " Server IP: $(IP)" + @echo "" -iso_server_run: - $(DOCKER) network create --subnet=172.20.0.0/16 --gateway=172.20.0.1 custom_iso_network || true - $(DOCKER) run -it --network custom_iso_network --ip 172.20.0.2 docker_server_user || true +# Default target for quick setup +all: iso_server_build iso_server_run -iso_server_shell: - $(DOCKER) run -it --network custom_iso_network --ip 172.20.0.2 --entrypoint /bin/bash docker_server_user +.PHONY: iso_server_build +iso_server_build: ## Build Docker configuration server image + @echo "$(COLOR_BLUE)Building Docker configuration server...$(COLOR_RESET)" + @echo "Creating Docker network: $(NETWORK_NAME)" + $(DOCKER) network create --subnet=$(SUBNET) --gateway=$(GATEWAY) $(NETWORK_NAME) || true + @echo "Building server image from Dockerfile" + $(DOCKER) build -t docker_server_user --file $(PWD)/custom-iso-server/server.Dockerfile $(PWD)/custom-iso-server/ + @echo "$(COLOR_GREEN)Docker server build completed$(COLOR_RESET)" +.PHONY: iso_server_run +iso_server_run: ## Run Docker configuration server + @echo "$(COLOR_BLUE)Starting Docker configuration server...$(COLOR_RESET)" + @echo "Network: $(NETWORK_NAME) ($(SUBNET))" + @echo "Server IP: $(IP)" + $(DOCKER) network create --subnet=$(SUBNET) --gateway=$(GATEWAY) $(NETWORK_NAME) || true + @echo "$(COLOR_GREEN)Server starting on http://$(IP):3003$(COLOR_RESET)" + @echo "$(COLOR_ORANGE)Use Ctrl+C to stop the server$(COLOR_RESET)" + $(DOCKER) run -it --network $(NETWORK_NAME) --ip $(IP) docker_server_user || true -.PHONY: iso_server_clean -iso_server_clean: - $(DOCKER) network rm custom_iso_network || true - @echo "User Custom ISO Server temizlendi." - @echo $(PWD) +.PHONY: iso_server_shell +iso_server_shell: ## Access server shell for debugging and monitoring + @echo "$(COLOR_BLUE)Accessing Docker server shell...$(COLOR_RESET)" + @echo "$(COLOR_ORANGE)Use 'exit' to leave the server shell$(COLOR_RESET)" + $(DOCKER) run -it --network $(NETWORK_NAME) --ip $(IP) --entrypoint /bin/bash docker_server_user +.PHONY: iso_server_clean +iso_server_clean: ## Clean up Docker network and containers + @echo "$(COLOR_BLUE)Cleaning up Docker server components...$(COLOR_RESET)" + $(DOCKER) network rm $(NETWORK_NAME) || true + @echo "$(COLOR_GREEN)Docker server cleanup completed$(COLOR_RESET)" .PHONY: clean -clean: +clean: ## Full cleanup of all server components @make iso_server_clean \ No newline at end of file