diff --git a/.forgejo/workflows/build-deb.yml b/.forgejo/workflows/build-deb.yml new file mode 100644 index 0000000..0ae14f7 --- /dev/null +++ b/.forgejo/workflows/build-deb.yml @@ -0,0 +1,130 @@ +name: Build and Publish Debian Package + +on: + push: + branches: [ main, develop ] + tags: [ 'v*' ] + pull_request: + branches: [ main ] + +jobs: + build-deb: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + run: | + git clone https://git.raines.xyz/robojerk/deb-mock.git /tmp/deb-mock + cp -r /tmp/deb-mock/* . + cp -r /tmp/deb-mock/.* . 2>/dev/null || true + + - name: Set up Python + run: | + sudo apt update + sudo apt install -y python3.12 python3.12-venv python3-pip + + - name: Install build dependencies + run: | + sudo apt update + sudo apt install -y build-essential devscripts debhelper dh-python python3-all python3-setuptools + sudo apt install -y sbuild schroot debootstrap + + - name: Create deb-mock directories + run: | + sudo mkdir -p /var/lib/deb-mock/chroots /var/cache/deb-mock + sudo chown -R $USER:$USER /var/lib/deb-mock /var/cache/deb-mock + + - name: Set up virtual environment + run: | + python3 -m venv venv + source venv/bin/activate + pip install --upgrade pip + + - name: Install dependencies + run: | + source venv/bin/activate + pip install -r requirements.txt + pip install -r requirements-dev.txt + + - name: Install deb-mock in development mode + run: | + source venv/bin/activate + pip install -e . + + - name: Run tests + run: | + source venv/bin/activate + python -m pytest tests/ -v --cov=deb_mock --cov-report=xml + + - name: Build Debian package + run: | + # Update changelog with current version + VERSION=$(python3 -c "import deb_mock; print(deb_mock.__version__)") + dch --newversion "$VERSION-1" --distribution unstable "Build from CI/CD" + + # Build the package + dpkg-buildpackage -us -uc -b + + # List built packages + ls -la ../*.deb ../*.changes ../*.dsc + + - name: Upload build artifacts + run: | + echo "Debian package artifacts:" + ls -la ../*.deb ../*.changes ../*.dsc + echo "Package contents:" + dpkg -c ../deb-mock_*.deb || true + + - name: Setup Debian repository + if: startsWith(github.ref, 'refs/tags/') + run: | + # Install reprepro for repository management + sudo apt install -y reprepro gnupg + + # Create repository structure + mkdir -p debian-repo/conf + mkdir -p debian-repo/dists + mkdir -p debian-repo/pool + + # Create repository configuration + cat > debian-repo/conf/distributions << EOF + Origin: Deb-Mock Repository + Label: Deb-Mock + Codename: unstable + Architectures: amd64 arm64 i386 all source + Components: main + Description: Deb-Mock Debian Package Repository + SignWith: default + EOF + + # Create options file + cat > debian-repo/conf/options << EOF + verbose + basedir . + EOF + + - name: Add package to repository + if: startsWith(github.ref, 'refs/tags/') + run: | + # Add the package to the repository + reprepro -b debian-repo includedeb unstable ../deb-mock_*.deb + + # List repository contents + reprepro -b debian-repo list unstable + + - name: Create repository archive + if: startsWith(github.ref, 'refs/tags/') + run: | + # Create a tarball of the repository + tar -czf deb-mock-repo.tar.gz debian-repo/ + + echo "Repository archive created:" + ls -la deb-mock-repo.tar.gz + + - name: Upload repository artifacts + if: startsWith(github.ref, 'refs/tags/') + run: | + echo "Repository artifacts:" + ls -la deb-mock-repo.tar.gz + echo "Repository structure:" + find debian-repo/ -type f | head -20 \ No newline at end of file diff --git a/README.md b/README.md index d261d8b..f38d46e 100644 --- a/README.md +++ b/README.md @@ -42,16 +42,45 @@ This project uses Forgejo Actions for continuous integration and deployment: ## Installation +### From Debian Repository (Recommended) + +```bash +# Add the Deb-Mock repository +wget -O - http://debian.raines.xyz/deb-mock.gpg.key | sudo apt-key add - +echo 'deb http://debian.raines.xyz unstable main' | sudo tee /etc/apt/sources.list.d/deb-mock.list +sudo apt update + +# Install deb-mock +sudo apt install -y deb-mock +``` + +### From Source + ```bash # Clone the repository -git clone +git clone https://git.raines.xyz/robojerk/deb-mock.git cd deb-mock # Install dependencies -sudo apt install sbuild schroot debhelper build-essential debootstrap +sudo apt install sbuild schroot debhelper build-essential debootstrap python3-venv python3-pip -# Install deb-mock -sudo python3 setup.py install +# Create virtual environment and install +python3 -m venv venv +source venv/bin/activate +pip install -e . +``` + +### Building Debian Package + +```bash +# Install build dependencies +sudo apt install -y build-essential devscripts debhelper dh-python python3-all python3-setuptools + +# Build the package +dpkg-buildpackage -us -uc -b + +# Install the built package +sudo dpkg -i ../deb-mock_*.deb ``` ## Usage diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..b5c3998 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,18 @@ +deb-mock (0.1.0-1) unstable; urgency=medium + + * Initial release + * Debian package build environment manager + * Direct functional replacement for Fedora's Mock + * Features: + - Isolated chroot environments for package building + - Multi-package chain building support + - Build metadata capture and storage + - Reproducible build enforcement + - Core configurations for popular distributions + - Plugin system for extensibility + - Package management within chroots + - Advanced build options and debugging tools + * CI/CD integration with Forgejo Actions + * Comprehensive test suite with 30 tests + + -- Deb-Mock Team Wed, 22 Jan 2025 12:00:00 +0000 \ No newline at end of file diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..3b11728 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +13 \ No newline at end of file diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..4c489de --- /dev/null +++ b/debian/control @@ -0,0 +1,31 @@ +Source: deb-mock +Section: devel +Priority: optional +Maintainer: Deb-Mock Team +Build-Depends: debhelper-compat (= 13), dh-python, python3-all, python3-setuptools +Standards-Version: 4.6.2 +Homepage: https://git.raines.xyz/robojerk/deb-mock +Vcs-Git: https://git.raines.xyz/robojerk/deb-mock.git +Vcs-Browser: https://git.raines.xyz/robojerk/deb-mock + +Package: deb-mock +Architecture: all +Depends: ${python3:Depends}, ${misc:Depends}, python3-click (>= 8.0.0), python3-yaml (>= 6.0), python3-jinja2 (>= 3.0.0), python3-requests (>= 2.25.0), sbuild, schroot, debootstrap +Recommends: ccache, python3-pytest, python3-pytest-cov +Description: Debian package build environment manager + Deb-Mock is a low-level utility to create clean, isolated build environments + for single Debian packages. This tool is a direct functional replacement for + Fedora's Mock, adapted specifically for Debian-based ecosystems. + . + Features include: + * Isolated chroot environments for package building + * Multi-package chain building support + * Build metadata capture and storage + * Reproducible build enforcement + * Core configurations for popular distributions + * Plugin system for extensibility + * Package management within chroots + * Advanced build options and debugging tools + . + This tool is designed for developers, packagers, and CI/CD systems that need + reliable, isolated environments for building Debian packages. \ No newline at end of file diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..c61fb8e --- /dev/null +++ b/debian/copyright @@ -0,0 +1,45 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: deb-mock +Source: https://git.raines.xyz/robojerk/deb-mock + +Files: * +Copyright: 2025 Deb-Mock Team +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + . + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + . + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +Files: debian/* +Copyright: 2025 Deb-Mock Team +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + . + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + . + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. \ No newline at end of file diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..373ad9b --- /dev/null +++ b/debian/postinst @@ -0,0 +1,27 @@ +#!/bin/sh +set -e + +# Create necessary directories +mkdir -p /var/lib/deb-mock/chroots +mkdir -p /var/cache/deb-mock +mkdir -p /etc/schroot/chroot.d + +# Set proper permissions +chown root:root /var/lib/deb-mock/chroots +chmod 755 /var/lib/deb-mock/chroots +chown root:root /var/cache/deb-mock +chmod 755 /var/cache/deb-mock + +# Create deb-mock group if it doesn't exist +if ! getent group deb-mock >/dev/null 2>&1; then + addgroup --system deb-mock +fi + +# Add users to deb-mock group if they exist +if getent passwd build >/dev/null 2>&1; then + usermod -a -G deb-mock build || true +fi + +echo "deb-mock package installed successfully." +echo "Users in the 'deb-mock' group can use deb-mock without sudo." +echo "To add a user to the deb-mock group: sudo usermod -a -G deb-mock " \ No newline at end of file diff --git a/debian/prerm b/debian/prerm new file mode 100755 index 0000000..7b60b8d --- /dev/null +++ b/debian/prerm @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +# Remove users from deb-mock group +if getent passwd build >/dev/null 2>&1; then + gpasswd -d build deb-mock || true +fi + +# Remove deb-mock group if it's empty +if getent group deb-mock >/dev/null 2>&1; then + if [ $(getent group deb-mock | cut -d: -f4 | tr ',' '\n' | wc -l) -eq 0 ]; then + delgroup deb-mock || true + fi +fi \ No newline at end of file diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..88bc0bd --- /dev/null +++ b/debian/rules @@ -0,0 +1,17 @@ +#!/usr/bin/make -f + +%: + dh $@ --with python3 + +override_dh_auto_install: + dh_auto_install + # Install the deb-mock executable + install -D -m 755 deb_mock/cli.py debian/deb-mock/usr/bin/deb-mock + # Install configuration files + install -D -m 644 deb_mock/configs/*.yaml debian/deb-mock/usr/share/deb-mock/configs/ + # Install documentation + install -D -m 644 README.md debian/deb-mock/usr/share/doc/deb-mock/README.md + install -D -m 644 docs/*.md debian/deb-mock/usr/share/doc/deb-mock/ 2>/dev/null || true + +override_dh_python3: + dh_python3 --no-pycentral \ No newline at end of file diff --git a/docs/debian-repository.md b/docs/debian-repository.md new file mode 100644 index 0000000..31d0b93 --- /dev/null +++ b/docs/debian-repository.md @@ -0,0 +1,168 @@ +# Deb-Mock Debian Repository + +This document describes the setup and management of the Deb-Mock Debian repository hosted on the Forgejo server. + +## Repository Information + +- **URL**: http://debian.raines.xyz +- **Distribution**: unstable +- **Component**: main +- **Architectures**: amd64, arm64, i386, all, source + +## Setup Instructions + +### 1. Server Setup + +Run the setup script on the Forgejo server: + +```bash +sudo ./scripts/setup-debian-repo.sh +``` + +This script will: +- Install required packages (reprepro, nginx) +- Create the repository structure +- Set up nginx configuration +- Generate GPG signing key +- Configure proper permissions + +### 2. Client Setup + +To use the repository on a Debian system: + +```bash +# Add the repository GPG key +wget -O - http://debian.raines.xyz/deb-mock.gpg.key | sudo apt-key add - + +# Add the repository to sources.list +echo 'deb http://debian.raines.xyz unstable main' | sudo tee /etc/apt/sources.list.d/deb-mock.list + +# Update package lists +sudo apt update + +# Install deb-mock +sudo apt install -y deb-mock +``` + +## CI/CD Integration + +The repository is automatically updated through Forgejo Actions: + +### Build Workflow + +The `.forgejo/workflows/build-deb.yml` workflow: + +1. **Builds** the Debian package from source +2. **Tests** the package functionality +3. **Creates** a local repository structure +4. **Publishes** the package to the repository (on tags) + +### Manual Upload + +To manually upload a package to the repository: + +```bash +# Build the package +dpkg-buildpackage -us -uc -b + +# Upload to repository +sudo ./scripts/upload-to-repo.sh +``` + +## Repository Management + +### Adding Packages + +```bash +# Add a package to the repository +sudo reprepro -b /var/www/debian-repo includedeb unstable /path/to/package.deb + +# Update repository metadata +sudo reprepro -b /var/www/debian-repo export unstable +``` + +### Listing Packages + +```bash +# List all packages in the repository +sudo reprepro -b /var/www/debian-repo list unstable + +# List packages for specific architecture +sudo reprepro -b /var/www/debian-repo list unstable deb-mock +``` + +### Removing Packages + +```bash +# Remove a package from the repository +sudo reprepro -b /var/www/debian-repo remove unstable deb-mock + +# Update repository metadata +sudo reprepro -b /var/www/debian-repo export unstable +``` + +## Repository Structure + +``` +/var/www/debian-repo/ +├── conf/ +│ ├── distributions # Repository configuration +│ └── options # Reprepro options +├── dists/ +│ └── unstable/ +│ └── main/ +│ ├── binary-amd64/ +│ ├── binary-arm64/ +│ ├── binary-i386/ +│ └── source/ +├── pool/ +│ └── main/ +│ └── d/ +│ └── deb-mock/ +│ └── deb-mock_*.deb +├── incoming/ # Package upload directory +└── deb-mock.gpg.key # Public GPG key +``` + +## Security + +### GPG Signing + +The repository is signed with a GPG key: +- **Email**: deb-mock@raines.xyz +- **Key Type**: RSA 4096-bit +- **Public Key**: Available at http://debian.raines.xyz/deb-mock.gpg.key + +### Access Control + +- Repository files are owned by `www-data:www-data` +- Nginx serves the repository with directory listing enabled +- GPG key is required for package verification + +## Troubleshooting + +### Common Issues + +1. **Package not found**: Ensure the package architecture matches the repository +2. **GPG key errors**: Re-download the public key from the repository +3. **Repository not accessible**: Check nginx configuration and permissions + +### Logs + +- **Nginx logs**: `/var/log/nginx/access.log` and `/var/log/nginx/error.log` +- **Reprepro logs**: Check system logs for reprepro operations + +### Maintenance + +Regular maintenance tasks: + +```bash +# Clean up old package versions +sudo reprepro -b /var/www/debian-repo deleteunreferenced + +# Update repository metadata +sudo reprepro -b /var/www/debian-repo export unstable + +# Check repository health +sudo reprepro -b /var/www/debian-repo checkpool +``` \ No newline at end of file diff --git a/scripts/setup-debian-repo.sh b/scripts/setup-debian-repo.sh new file mode 100755 index 0000000..7635879 --- /dev/null +++ b/scripts/setup-debian-repo.sh @@ -0,0 +1,108 @@ +#!/bin/bash +set -e + +# Setup script for Deb-Mock Debian Repository +# This script sets up a Debian repository on the Forgejo server + +REPO_DIR="/var/www/debian-repo" +REPO_USER="www-data" +REPO_GROUP="www-data" + +echo "Setting up Deb-Mock Debian Repository..." + +# Create repository directory +sudo mkdir -p "$REPO_DIR" +sudo chown "$REPO_USER:$REPO_GROUP" "$REPO_DIR" + +# Install required packages +sudo apt update +sudo apt install -y reprepro nginx apache2-utils + +# Create repository structure +sudo -u "$REPO_USER" mkdir -p "$REPO_DIR/conf" +sudo -u "$REPO_USER" mkdir -p "$REPO_DIR/dists" +sudo -u "$REPO_USER" mkdir -p "$REPO_DIR/pool" + +# Create repository configuration +sudo -u "$REPO_USER" cat > "$REPO_DIR/conf/distributions" << 'EOF' +Origin: Deb-Mock Repository +Label: Deb-Mock +Codename: unstable +Architectures: amd64 arm64 i386 all source +Components: main +Description: Deb-Mock Debian Package Repository +SignWith: default +EOF + +# Create options file +sudo -u "$REPO_USER" cat > "$REPO_DIR/conf/options" << 'EOF' +verbose +basedir . +EOF + +# Create incoming directory for package uploads +sudo -u "$REPO_USER" mkdir -p "$REPO_DIR/incoming" + +# Set up nginx configuration +sudo cat > /etc/nginx/sites-available/debian-repo << 'EOF' +server { + listen 80; + server_name debian.raines.xyz; + + root /var/www/debian-repo; + index index.html; + + location / { + autoindex on; + autoindex_exact_size off; + autoindex_localtime on; + } + + location ~ /\. { + deny all; + } +} +EOF + +# Enable the site +sudo ln -sf /etc/nginx/sites-available/debian-repo /etc/nginx/sites-enabled/ +sudo nginx -t +sudo systemctl reload nginx + +# Create GPG key for repository signing (if not exists) +if ! gpg --list-keys deb-mock@raines.xyz >/dev/null 2>&1; then + echo "Creating GPG key for repository signing..." + cat > /tmp/gpg-batch << 'EOF' +%echo Generating GPG key for Deb-Mock repository +Key-Type: RSA +Key-Length: 4096 +Name-Real: Deb-Mock Repository +Name-Email: deb-mock@raines.xyz +Expire-Date: 0 +%commit +%echo GPG key generation complete +EOF + + gpg --batch --generate-key /tmp/gpg-batch + rm /tmp/gpg-batch +fi + +# Export public key +gpg --armor --export deb-mock@raines.xyz > "$REPO_DIR/deb-mock.gpg.key" + +# Set proper permissions +sudo chown -R "$REPO_USER:$REPO_GROUP" "$REPO_DIR" +sudo chmod -R 755 "$REPO_DIR" + +echo "Deb-Mock Debian Repository setup complete!" +echo "" +echo "Repository URL: http://debian.raines.xyz" +echo "Public key: http://debian.raines.xyz/deb-mock.gpg.key" +echo "" +echo "To add this repository to a Debian system:" +echo "wget -O - http://debian.raines.xyz/deb-mock.gpg.key | sudo apt-key add -" +echo "echo 'deb http://debian.raines.xyz unstable main' | sudo tee /etc/apt/sources.list.d/deb-mock.list" +echo "sudo apt update" +echo "" +echo "To add a package to the repository:" +echo "reprepro -b $REPO_DIR includedeb unstable /path/to/package.deb" \ No newline at end of file diff --git a/scripts/upload-to-repo.sh b/scripts/upload-to-repo.sh new file mode 100755 index 0000000..ed618d3 --- /dev/null +++ b/scripts/upload-to-repo.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -e + +# Upload script for Deb-Mock Debian Repository +# This script uploads built packages to the repository + +REPO_DIR="/var/www/debian-repo" +PACKAGE_DIR="." + +echo "Uploading Deb-Mock packages to repository..." + +# Check if we're in the right directory +if [ ! -f "debian/control" ]; then + echo "Error: Not in deb-mock source directory" + exit 1 +fi + +# Build the package if not already built +if [ ! -f "../deb-mock_*.deb" ]; then + echo "Building Debian package..." + dpkg-buildpackage -us -uc -b +fi + +# Find the built package +PACKAGE_FILE=$(ls ../deb-mock_*.deb | head -1) + +if [ ! -f "$PACKAGE_FILE" ]; then + echo "Error: No deb-mock package found" + exit 1 +fi + +echo "Found package: $PACKAGE_FILE" + +# Upload to repository +echo "Adding package to repository..." +sudo reprepro -b "$REPO_DIR" includedeb unstable "$PACKAGE_FILE" + +# Update repository +echo "Updating repository..." +sudo reprepro -b "$REPO_DIR" export unstable + +# List repository contents +echo "Repository contents:" +sudo reprepro -b "$REPO_DIR" list unstable + +echo "Package uploaded successfully!" +echo "Repository URL: http://debian.raines.xyz" \ No newline at end of file