Skip to content
Permalink
Browse files

Add RPM packaging

  • Loading branch information...
subuk committed Sep 3, 2019
1 parent 0f1bb34 commit 362fa1f95e773527e079576c6ec25def5d7be379
Showing with 211 additions and 10 deletions.
  1. +3 −0 .gitignore
  2. +2 −2 Makefile
  3. +7 −0 README.md
  4. +34 −0 build-rpm.sh
  5. +36 −0 buildhelpers/build.sh
  6. +54 −0 buildhelpers/centos7.yum.conf
  7. +8 −8 vmango.dist.conf
  8. +15 −0 vmango.service
  9. +52 −0 vmango.spec.in
@@ -12,3 +12,6 @@
/rpm/*.tar.gz
/deb/*.tar.gz
/.vscode/
/vmango.spec
/result/
/vmango.conf
@@ -5,7 +5,7 @@ INSTALL = install
GO_SOURCES = $(shell find . -name '*.go')
ASSETS_SOURCES = $(shell find templates static)
UNAME_S := $(shell uname -s)
TARBALL_SOURCES = $(GO_SOURCES) Makefile README.md vmango.dist.conf vmango.service vendor/
TARBALL_SOURCES = $(GO_SOURCES) Makefile README.md vmango.dist.conf vmango.service static/ templates/ vendor/ go.mod go.sum

RPM_NAME = vmango
VERSION = 0.8.0
@@ -54,7 +54,7 @@ spec: $(RPM_NAME).spec.in
sed -e "s/@@_VERSION_@@/$(VERSION)/g" -e "s/@@_RELEASE_@@/$(RELEASE)/g" $(RPM_NAME).spec.in > $(RPM_NAME).spec

.PHONY: apparchive
apparchive: $(TARBALL_SOURCES) RELEASE_BUILD_COMMIT.txt
apparchive: $(TARBALL_SOURCES)
$(TAR) --transform "s,,$(RPM_NAME)-$(VERSION)/," -czf $(RPM_NAME)-$(VERSION).tar.gz $^

.PHONY: rpm
@@ -78,3 +78,10 @@ Install Go compiler, libvirt C library and mkisofs util (for configdrive creatio

You need a linux hypervisor somewhere in the world, because libvirt doesn't support MacOS.
Make sure to add ?socket option to remote libvirt urls.


## Build RPM

Requires docker command.

make clean rpm
@@ -0,0 +1,34 @@
#!/bin/bash
set -e

USAGE="Usage: $0 [centos-7] <path_to_rpm_spec>"
CACHE_DIR=/tmp/rpmbuild-cache
BUILD_SCRIPT=`pwd`/buildhelpers/build.sh
RESULT_DIR="result/RPMS-$1"

case "$1" in
"centos-7")
DOCKER_IMAGE=centos:7
YUM_CONFIG=`pwd`/buildhelpers/centos7.yum.conf
;;
*)
echo $USAGE
exit 1
esac

mkdir -p $RESULT_DIR
mkdir -p $CACHE_DIR

RPMSPEC=$2
if [ -z "$RPMSPEC" ];then
echo $USAGE
exit 1
fi

exec docker run --rm -it \
-v `pwd`:/source \
-v `pwd`/$RESULT_DIR:/result \
-v $CACHE_DIR:/cache \
-v $YUM_CONFIG:/etc/yum.conf \
-v $BUILD_SCRIPT:/build.sh \
$DOCKER_IMAGE /build.sh $RPMSPEC
@@ -0,0 +1,36 @@
#!/bin/sh
set -e
set -x

SPECFILE="/source/$1"
SOURCES_DIR=$(dirname $SPECFILE)

yum makecache fast
yum install -y rpmdevtools yum-utils fakeroot make gcc

useradd -s /bin/bash builder
chown builder. /cache -R

pushd $SOURCES_DIR
spectool -g $SPECFILE
yum-builddep -y $SPECFILE
popd

su builder -c /bin/bash <<EOF
set -e
set -x
mkdir -p /cache/builder-cache-dir
ln -sf /cache/builder-cache-dir ~/.cache
cat > ~/.rpmmacros <<EOT
%_topdir /tmp/buildd
EOT
mkdir -p /tmp/buildd/{BUILD,BUILDROOT,RPMS,SPECS,SRPMS}
ln -s $SOURCES_DIR /tmp/buildd/SOURCES
fakeroot-sysv rpmbuild -ba $SPECFILE
EOF

find /tmp/buildd/RPMS /tmp/buildd/SRPMS -type f |xargs -I{} -n1 cp {} /result
@@ -0,0 +1,54 @@
[main]
cachedir=/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
assumeyes=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
override_install_langs=en_US.UTF-8
tsflags=nodocs

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7

[go-repo]
name=go-repo - CentOS
baseurl=https://mirror.go-repo.io/centos/$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO
@@ -1,19 +1,19 @@
key_file = "/tmp/vmango/authorized_keys"
key_file = "/var/lib/vmango/authorized_keys"
libvirt_uri = "qemu:///system"
# libvirt_uri = "qemu+ssh://user@example.com/system?socket=/var/run/libvirt/libvirt-sock"
libvirt_config_drive_pool = "default"
libvirt_config_drive_suffix = "_config.iso"
bridges = ["br0"]
# bridges = ["br0"]

web {
debug = false
listen = ":8080"
session_secret = "changeme"

user "admin" {
email = "admin"
hashed_password = "$2a$10$igHQGROHntvl05AztpfMeONSBDUsEbZHxayc5DOPTKIFX50WrHURS"
}
# Uncomment to set admin / admin password
# user "admin" {
# email = "admin"
# hashed_password = "$2a$10$igHQGROHntvl05AztpfMeONSBDUsEbZHxayc5DOPTKIFX50WrHURS"
# }
}

image "/var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1901.qcow2" {
@@ -24,6 +24,6 @@ image "/var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1901.qcow2" {

image "/var/lib/libvirt/images/ubuntu-18.04-minimal-cloudimg-amd64.img" {
os_name = "Ubuntu"
os_version = "14.04"
os_version = "18.04"
os_arch = "x86_64"
}
@@ -0,0 +1,15 @@
[Unit]
Description=Virtual Machine Manager
After=network.target

[Service]
EnvironmentFile=-/etc/sysconfig/vmango
User=vmango
Group=vmango
ExecStart=/usr/bin/vmango --config /etc/vmango.conf
Restart=on-failure
RestartSec=5s
PrivateTmp=true

[Install]
WantedBy=multi-user.target
@@ -0,0 +1,52 @@
%define debug_package %{nil}

Name: vmango
Summary: Virtual Machine Manager
Version: @@_VERSION_@@
Release: @@_RELEASE_@@%{dist}
Source0: %{name}-%{version}.tar.gz
License: GPLv3
Group: Other
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}.buildroot
Vendor: subuk
BuildRequires: golang = 1.12.9
BuildRequires: libvirt-devel
Requires(pre): shadow-utils
%{?systemd_requires}

%description
%{summary}

%prep
%setup -q

%build
make

%install
make install DESTDIR=%{buildroot} PREFIX=%{_prefix}
install -d %{buildroot}%{_unitdir}
install vmango.service %{buildroot}%{_unitdir}/

%pre
getent group vmango >/dev/null || groupadd -r vmango
getent passwd vmango >/dev/null || \
useradd -r -g vmango -d /var/lib/vmango -s /sbin/nologin -c "github.com/subuk/vmango" vmango
exit 0

%postun
%systemd_postun vmango.service

%preun
%systemd_preun vmango.service

%post
%systemd_post vmango.service

%clean
rm -rf $RPM_BUILD_ROOT

%files
%attr(0755,root,root) %{_prefix}/bin/vmango
%config(noreplace) /etc/vmango.conf
%{_unitdir}/vmango.service

0 comments on commit 362fa1f

Please sign in to comment.
You can’t perform that action at this time.