Skip to content

Commit

Permalink
feat: Create automated debian and RPM packaging (#1549)
Browse files Browse the repository at this point in the history
* Adding RPM packaging functionality for minimega.

* Testing a variable version number

* Adding a github action to test the RPM building

* Version upgrades

* Adding more necessary packages

* Clearer path for updating rpm spec

* Update rpm.yml artifact path

* Adding a script for the debian packaging

* Update deb.yml

* Update build.bash

* Update build.bash

* Update control to use debhelp as the build dependency

* Addressing ntfs-3g which resides in the epel repository

* Adding a warning message about ntfs-3g

* Automatically fail if ntfs-3g is not found

* Fixing packaging with libpcap and updating environment variables to be similar to those in the dockerized version. (#2)

* Addressing review comments by addressing inefficencies and inconsistencies

* Minor pipeline bug fixes

* Cleaning up after the build script

* Copy the x86_64 RPM to the root directory to keep consistency with debian files.

* Updating debhelper to ensure that the systemd service does not automatically start.
  • Loading branch information
sdelliot authored Jan 30, 2025
1 parent b2aedba commit 04215d1
Show file tree
Hide file tree
Showing 21 changed files with 450 additions and 31 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/deb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: DEB Build
on: push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential debhelper dnsmasq iproute2 isc-dhcp-client libpcap-dev ntfs-3g openssh-client openvswitch-switch qemu-kvm qemu-utils
- name: Build Deb package
id: deb
run: |
chmod +x ./packaging/debian/build.bash
./packaging/debian/build.bash
- name: Upload artifact
uses: actions/[email protected]
with:
name: minimega-deb
path: ./*.deb
25 changes: 25 additions & 0 deletions .github/workflows/rpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: RPM Build
on: push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y rpm dnsmasq iproute2 isc-dhcp-client libpcap-dev ntfs-3g openssh-client openvswitch-switch qemu-kvm qemu-utils
- name: Build RPM package
id: rpm
run: |
chmod +x ./packaging/rpm/build.bash
./packaging/rpm/build.bash
- name: Upload artifact
uses: actions/[email protected]
with:
name: minimega-rpm
path: ./packaging/rpm/rpmbuild/RPMS/*
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@ lib/minimega.py
tests/*.got
tests/*/*.got
.DS_Store*
*.deb
*.changes
*.buildinfo
*.ddeb
*.rpm
packaging/debian/.debhelper/
packaging/debian/debhelper-build-stamp
packaging/debian/files
packaging/debian/minimega.debhelper.log
packaging/debian/minimega.postinst.debhelper
packaging/debian/minimega.postrm.debhelper
packaging/debian/minimega.prerm.debhelper
packaging/debian/minimega.service
packaging/debian/minimega.substvars
packaging/debian/minimega/DEBIAN/control
packaging/debian/minimega/DEBIAN/md5sums
packaging/debian/minimega/DEBIAN/postrm
packaging/debian/minimega/DEBIAN/prerm
packaging/debian/tmp/
packaging/debian/minimega/
lib/minimega.egg-info/
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Miles Crabill <[email protected]>
Jonathan Crussell <[email protected]>
Jerry Cruz <[email protected]>
Jacob Davis <[email protected]>
Steven Elliott <[email protected]>
Jeremy Erickson <[email protected]>
John Floren <[email protected]>
David Fritz <[email protected]>
Expand Down
44 changes: 42 additions & 2 deletions misc/daemon/minimega.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
# minimega source/build directory
MINIMEGA_DIR="/opt/minimega/"
# Runtime directory for minimega to use

# Runtime directory for minimega to use also known as the BASE directory
# "MM_RUN_PATH" is deprecated and will be removed in a future release
# Please use "MM_BASE" instead.
MM_RUN_PATH="/tmp/minimega"
MM_BASE="/tmp/minimega"

# Directory to serve files from
MM_FILEPATH="/tmp/minimega/files"

# Number of meshage peers to find
# "MM_MESH_DEGREE" is deprecated and will be removed in a future release
# Please use "MM_DEGREE" instead.
MM_MESH_DEGREE=0
MM_DEGREE=0

# meshage MSA timeout
MM_MSA=10

# Context for finding meshage peers (must be set the same among peers)
MM_CONTEXT="minimega"

# Port to listen on for meshage connections and to look for peers on (must be set the same among peers)
MM_PORT=9000
# Run as a daemonized process (should be true when started via /etc/init.d)

# Run as a daemonized process (should be true when started via /etc/init.d or systemd)
MM_DAEMON=true

# Logging level - options are "debug","info","warn","error","fatal"
# "MM_LOG_LEVEL" is deprecated and will be removed in a future release
# Please use "MM_LOGLEVEL" instead.
MM_LOG_LEVEL="error"
MM_LOGLEVEL="error"

# Location for log file
# "MM_LOG_FILE" is deprecated and will be removed in a future release
# Please use "MM_LOGFILE" instead.
MM_LOG_FILE="/tmp/minimega.log"
MM_LOGFILE="/var/log/minimega.log"

# Panic on quit, producing stack traces for debugging
MM_PANIC=false

# The meshage broadcast address to use (default "255.255.255.255")
MM_BROADCAST="255.255.255.255"

# The VLAN range for namespaces (default "101-4096")
MM_VLANRANGE="101-4096"

# Force minimega to run even if it appears to already be running
MM_FORCE=true

# Attempt to recover from a previously running instance (only if MM_FORCE is false)
MM_RECOVER=false

# Path to control group (cgroup) mount location
MM_CGROUP="/sys/fs/cgroup"
30 changes: 30 additions & 0 deletions misc/daemon/minimega.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[Unit]
Description="minimega Emulytics Daemon"
Documentation=https://www.sandia.gov/minimega
Wants=openvswitch-switch.service

[Install]
WantedBy=default.target

[Service]
Type=simple
# Kill mode settings
KillMode=control-group
TimeoutStopSec=5
Restart=on-success
# Setting ulimit and environment variables
LimitNOFILE=1024000
LimitNPROC=4096000
EnvironmentFile=/etc/minimega/minimega.conf
# Pre Start script
ExecStartPre=/bin/mkdir -p /etc/minimega/saved_vms/
ExecStartPre=/bin/mkdir -p ${MM_RUN_PATH}
# Starting minimega
ExecStart=/usr/bin/minimega -nostdin=${MM_DAEMON} -force=${MM_FORCE} -recover=${MM_RECOVER} -base=${MM_BASE} -filepath=${MM_FILEPATH} -broadcast=${MM_BROADCAST} -vlanrange=${MM_VLANRANGE} -port=${MM_PORT} -degree=${MM_DEGREE} -context=${MM_CONTEXT} -level=${MM_LOGLEVEL} -logfile=${MM_LOGFILE} -cgroup=${MM_CGROUP} -panic=${MM_PANIC} -msa=${MM_MSA}
# After start options
ExecStartPost=/bin/sleep 1
ExecStartPost=/bin/chgrp -R minimega ${MM_RUN_PATH}
ExecStartPost=/bin/chmod -R g=u ${MM_RUN_PATH}
ExecStartPost=/bin/chmod g+s ${MM_RUN_PATH} ${MM_RUN_PATH}/minimega
# Post stop instructions
ExecStopPost=/bin/rm -f ${MM_RUN_PATH}/minimega
10 changes: 10 additions & 0 deletions packaging/debian/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Building minimega

To create a ``.deb`` you will need the following additional dependencies:

```bash
sudo apt install debhelper
```

Once that is installed, run ``build.bash`` to create a new package.
It, along with other build files will be placed in minimega's top level directory.
32 changes: 9 additions & 23 deletions packaging/debian/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,18 @@ echo BUILDING MINIMEGA...
(cd $MM && ./scripts/build.bash && ./scripts/doc.bash)
echo DONE BUILDING

echo COPYING FILES...

DST=$SCRIPT_DIR/minimega/opt/minimega
mkdir -p $DST
cp -r $MM/bin $DST/
cp -r $MM/doc $DST/
cp -r $MM/lib $DST/
mkdir -p $DST/misc
cp -r $MM/misc/daemon $DST/misc/
cp -r $MM/misc/vmbetter_configs $DST/misc/
mkdir -p $DST/web
cp -r $MM/web $DST/web/

DOCS=$SCRIPT_DIR/minimega/usr/share/doc/minimega
mkdir -p $DOCS
cp $MM/LICENSE $DOCS/
cp -r $MM/LICENSES $DOCS/

echo COPIED FILES

# substitute version for control file
source $MM/VERSION
sed -e 's/${version}/'"$VERSION"'/g' minimega/DEBIAN/control.base > minimega/DEBIAN/control
DATE=$(date -R)
sed -e 's/${version}/'"$VERSION"'/g' $SCRIPT_DIR/changelog.base > $SCRIPT_DIR/changelog.out
sed -e 's/${date}/'"$DATE"'/g' $SCRIPT_DIR/changelog.out > $SCRIPT_DIR/changelog
rm $SCRIPT_DIR/changelog.out
cp $MM/misc/daemon/minimega.service .

echo BUILDING PACKAGE...
(cd $SCRIPT_DIR && fakeroot dpkg-deb -b minimega)
rm minimega/DEBIAN/control


(cd $SCRIPT_DIR/.. && dpkg-buildpackage --no-sign -b)
rm $SCRIPT_DIR/changelog
echo DONE

5 changes: 5 additions & 0 deletions packaging/debian/changelog.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
minimega (${version}) stable; urgency=low

* Release minimega version ${version}.

-- Minimega-Dev <[email protected]> ${date}
9 changes: 7 additions & 2 deletions packaging/debian/clean.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

rm -r $SCRIPT_DIR/minimega/opt
rm -r $SCRIPT_DIR/minimega/usr
rm -rf $SCRIPT_DIR/minimega
rm -rf $SCRIPT_DIR/*.debhelper*
rm -rf $SCRIPT_DIR/minimega.service
rm -rf $SCRIPT_DIR/minimega.substvars
rm -rf $SCRIPT_DIR/debhelper-build-stamp
rm -rf $SCRIPT_DIR/tmp
rm -f $SCRIPT_DIR/changelog
1 change: 1 addition & 0 deletions packaging/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
Package: minimega
Version: ${version}
Source: minimega
Section: utils
Priority: extra
Architecture: amd64
Depends: qemu-kvm, qemu-utils, openvswitch-switch, dnsmasq, dosfstools, ntfs-3g, libpcap-dev
Maintainer: Arthur Hernandez <[email protected]>, Jacob Davis <[email protected]>
Build-Depends: debhelper
Vcs-Browser: https://github.com/sandia-minimega/minimega/
Vcs-Git: https://github.com/sandia-minimega/minimega.git

Package: minimega
Architecture: amd64
Homepage: https://www.sandia.gov/minimega
Depends: qemu-kvm,
qemu-utils,
openvswitch-switch,
dnsmasq,
dosfstools,
ntfs-3g,
libpcap-dev
Description: a distributed VM management tool.
minimega is a tool for launching and managing virtual machines. It can run on
your laptop or distributed across a cluster. minimega is fast, easy to deploy,
Expand Down
8 changes: 8 additions & 0 deletions packaging/debian/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
../../../bin /opt/minimega/
../../../doc /opt/minimega/
../../../lib /opt/minimega/
../../../misc/daemon /opt/minimega/misc/
../../../misc/vmbetter_configs /opt/minimega/misc/
../../../web /opt/minimega/
../../../LICENSE /usr/share/doc/minimega/
../../../LICENSES /usr/share/doc/minimega/
5 changes: 5 additions & 0 deletions packaging/debian/links
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
opt/minimega/bin/minimega usr/bin/minimega
opt/minimega/bin/miniweb usr/bin/miniweb
opt/minimega/bin/protonuke usr/bin/protonuke
opt/minimega/misc/daemon/minimega.conf /etc/minimega/minimega.conf

Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ fi

chown -R minimega:minimega /usr/share/doc/minimega
chown -R minimega:minimega /opt/minimega
chown -R minimega:minimega /etc/minimega

# Symlink all binaries

#DEBHELPER#
24 changes: 24 additions & 0 deletions packaging/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/make -f
#export DH_VERBOSE=1

MM=".."
DST="debian/tmp/opt/minimega"
DOCS="debian/tmp/usr/share/doc/minimega"

%:
dh $@ --with systemd --no-start --parallel

override_dh_prep:
dh_prep
mkdir -p $(DST)
cp -r $(MM)/bin $(DST)/
cp -r $(MM)/doc $(DST)/
cp -r $(MM)/lib $(DST)/
mkdir -p $(DST)/misc
cp -r $(MM)/misc/daemon $(DST)/misc/
cp -r $(MM)/misc/vmbetter_configs $(DST)/misc/
mkdir -p $(DST)/web
cp -r $(MM)/web $(DST)/web/
mkdir -p $(DOCS)
cp $(MM)/LICENSE $(DOCS)/
cp -r $(MM)/LICENSES $(DOCS)/
1 change: 1 addition & 0 deletions packaging/rpm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rpmbuild/BUILDROOT
10 changes: 10 additions & 0 deletions packaging/rpm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Building minimega

To create a ``.rpm`` you will need the following additional dependencies:

```bash
sudo apt install rpm
```

Once that is installed, run ``build.bash`` to create a new package.
The package will be placed in minimega's top level directory.
23 changes: 23 additions & 0 deletions packaging/rpm/build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

MM=$SCRIPT_DIR/../..
FILES=$SCRIPT_DIR/minmega

# substitute version for control file
source $MM/VERSION
sed -e 's/${version}/'"$VERSION"'/g' $SCRIPT_DIR/rpmbuild/SPECS/minimega.spec.base > $SCRIPT_DIR/rpmbuild/SPECS/minimega.spec

echo "PREPARING FOR BUILDING RPM..."
mkdir -p rpmbuild/BUILD
mkdir -p rpmbuild/RPMS
mkdir -p rpmbuild/SOURCES
mkdir -p rpmbuild/SPECS
mkdir -p rpmbuild/SRPMS

echo "BUILDING PACKAGE..."
(cd $SCRIPT_DIR && rpmbuild --define "_topdir $SCRIPT_DIR/rpmbuild" -bb rpmbuild/SPECS/minimega.spec)
cp $SCRIPT_DIR/rpmbuild/RPMS/x86_64/*.rpm $SCRIPT_DIR/../../
rm -rf $SCRIPT_DIR/rpmbuild/SPECS/minimega.spec
echo "DONE"
9 changes: 9 additions & 0 deletions packaging/rpm/clean.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

rm -rf rpmbuild/BUILD
rm -rf rpmbuild/BUILDROOT
rm -rf rpmbuild/RPMS
rm -rf rpmbuild/SOURCES
rm -rf rpmbuild/SRPMS
Loading

0 comments on commit 04215d1

Please sign in to comment.