Skip to content
Permalink
Browse files

Support copr RPM build

  • Loading branch information...
subuk committed Sep 5, 2019
1 parent 973192e commit 3e8be328c65efde259bb1ab9e4fbb4fe7577ef91
@@ -0,0 +1,7 @@
# make -f .copr/Makefile srpm outdir="/tmp/coprtest" spec="<spec_path>"
outdir =
spec =

srpm:
yum install -y git || dnf install -y git
$(MAKE) srpm RPM_OUTDIR=$(outdir) RPM_SPEC=$(spec)
@@ -5,11 +5,9 @@ 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 static/ templates/ vendor/ go.mod go.sum
TARBALL_SOURCES = $(GO_SOURCES) Makefile Makefile.RPM.mk README.md vmango.dist.conf vmango.service static/ templates/ vendor/ go.mod go.sum

RPM_NAME = vmango
VERSION = 0.9.0
RELEASE = 1

BUILD_LDFLAGS = -X subuk/vmango/web.AppVersion=$(VERSION)

@@ -29,14 +27,6 @@ default: bin/vmango
bin/vmango: $(GO_SOURCES) web/assets_generated.go Makefile
$(GO) build -ldflags='$(BUILD_LDFLAGS)' -o bin/vmango

.PHONY: vendor
vendor:
$(GO) mod tidy -v
$(GO) mod vendor -v

test:
go test vmango/...

bin/go-bindata:
$(GO) install github.com/go-bindata/go-bindata/go-bindata

@@ -49,18 +39,21 @@ install: bin/vmango vmango.dist.conf
$(INSTALL) -m 0755 bin/vmango $(BIN_DIR)/
$(INSTALL) -m 0644 vmango.dist.conf $(CONF_DIR)/vmango.conf

.PHONY: spec
spec: $(RPM_NAME).spec.in
sed -e "s/@@_VERSION_@@/$(VERSION)/g" -e "s/@@_RELEASE_@@/$(RELEASE)/g" $(RPM_NAME).spec.in > $(RPM_NAME).spec
tarball: vmango-$(VERSION).tar.gz
vmango-$(VERSION).tar.gz: $(TARBALL_SOURCES)
$(TAR) --transform "s,,vmango-$(VERSION)/," -czf vmango-$(VERSION).tar.gz $^

.PHONY: apparchive
apparchive: $(TARBALL_SOURCES)
$(TAR) --transform "s,,$(RPM_NAME)-$(VERSION)/," -czf $(RPM_NAME)-$(VERSION).tar.gz $^
.PHONY: vendor
vendor:
$(GO) mod tidy -v
$(GO) mod vendor -v

.PHONY: rpm
rpm: spec apparchive
./build-rpm.sh centos-7 $(RPM_NAME).spec
.PHONY: test
test:
go test vmango/...

.PHONY: clean
clean:
rm -rf web/assets_generated.go result/ bin/ $(RPM_NAME).spec $(RPM_NAME)-*.tar.gz
$(GO) clean -testcache
rm -rf web/assets_generated.go bin/ $(RPM_NAME)*.spec $(RPM_NAME)-*.tar.gz *.rpm

include Makefile.RPM.mk
@@ -0,0 +1,41 @@
RPM_NAME = vmango
RPM_VERSION = $(VERSION)
RPM_DIST = $(shell rpm --eval '%{dist}')
RPM_TOPDIR = $(shell rpm --eval '%{_topdir}')
RPM_ARCH = $(shell rpm --eval '%{_arch}')
RPM_RELEASE = $(shell git describe --tags 2>/dev/null | awk -F- '{print $$2"."$$3}')
RPM_OUTDIR = .
RPM_SPEC = $(RPM_NAME).spec

ifeq ($(RPM_RELEASE),.)
RPM_RELEASE = 1
endif

ifeq ($(RPM_RELEASE),)
RPM_RELEASE = 1
endif


spec: $(RPM_SPEC)
$(RPM_SPEC): $(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE).spec
cp $(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE).spec $(RPM_SPEC)
$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE).spec: $(RPM_NAME).spec.in
sed -e "s/@@_VERSION_@@/$(RPM_VERSION)/g" -e "s/@@_RELEASE_@@/$(RPM_RELEASE)/g" $(RPM_NAME).spec.in > $(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE).spec

srpm: $(RPM_OUTDIR)/$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE)$(RPM_DIST).src.rpm
$(RPM_OUTDIR)/$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE)$(RPM_DIST).src.rpm: $(RPM_SPEC) $(RPM_NAME)-$(RPM_VERSION).tar.gz
mkdir -p $(RPM_OUTDIR)
cp $(RPM_NAME)-$(RPM_VERSION).tar.gz $(RPM_TOPDIR)/SOURCES
rpmbuild -bs $(RPM_SPEC)
mv $(RPM_TOPDIR)/SRPMS/$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE)$(RPM_DIST).src.rpm $(RPM_OUTDIR)

rpm: $(RPM_OUTDIR)/$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE)$(RPM_DIST).$(RPM_ARCH).rpm
$(RPM_OUTDIR)/$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE)$(RPM_DIST).$(RPM_ARCH).rpm: $(RPM_OUTDIR)/$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE)$(RPM_DIST).src.rpm
mkdir -p $(RPM_OUTDIR)
yum-builddep -y $(RPM_OUTDIR)/$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE)$(RPM_DIST).src.rpm
rpmbuild --rebuild $(RPM_OUTDIR)/$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE)$(RPM_DIST).src.rpm
mv $(RPM_TOPDIR)/RPMS/$(RPM_ARCH)/$(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE)$(RPM_DIST).$(RPM_ARCH).rpm $(RPM_OUTDIR)/

.PHONY: docker-rpm
docker-rpm:
./dockerbuild.sh centos-7 rpm
@@ -83,6 +83,10 @@ Make sure to add ?socket option to remote libvirt urls.

## Build RPM

Requires docker command.
With docker for Centos 7:

make clean docker-rpm

Locally:

make clean rpm

This file was deleted.

This file was deleted.

@@ -0,0 +1,28 @@
#!/bin/bash
set -e

USAGE="Usage: $0 [centos-7] <make args...>"
CACHE_DIR=/tmp/rpmbuild-cache

case "$1" in
"centos-7")
DOCKER_IMAGE=vmango:build_centos7
YUM_CONFIG=`pwd`/dockerbuild/centos7.yum.conf
if [[ "Y$(docker images -q $DOCKER_IMAGE)" == "Y" ]]; then
docker build -t $DOCKER_IMAGE -f dockerbuild/centos7.dockerfile .
fi
;;
*)
echo $USAGE
exit 1
esac
shift

mkdir -p $CACHE_DIR

exec docker run --rm -it \
-v `pwd`:/source \
-v $CACHE_DIR:/cache \
-v $YUM_CONFIG:/etc/yum.conf \
-w /source \
$DOCKER_IMAGE $@
@@ -0,0 +1,4 @@
FROM centos:7

RUN yum install -y rpmdevtools make epel-release git
RUN echo '%_topdir /tmp/buildd' > ~/.rpmmacros && rpmdev-setuptree
File renamed without changes.

0 comments on commit 3e8be32

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