Skip to content

Commit

Permalink
Add Docker support and bump to 14.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mbevc1 committed Oct 4, 2018
1 parent b7ffcee commit 1b4c970
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 30 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*~
*.log
SOURCES/*.bz2
SOURCES/*.gz
SRPMS
RPMS
t/
rpmbuild/SOURCES/*.bz2
rpmbuild/SOURCES/*.gz
rpmbuild/cache
rpmbuild/output
pkg/
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM centos:7
MAINTAINER DevOps <[email protected]>

RUN yum -y --setopt="tsflags=nodocs" update && \
yum -y --setopt="tsflags=nodocs" install epel-release mock rpm-sign expect \
bash ca-certificates git make yum-utils rpmdevtools && \
yum clean all && \
rm -rf /var/cache/yum/

#Configure users
RUN useradd -u 1000 -G mock builder && \
chmod g+w /etc/mock/*.cfg

VOLUME ["/rpmbuild"]

ONBUILD COPY mock /etc/mock
ADD ./site-defaults-extra.cfg /etc/mock/

# create mock cache on external volume to speed up build
RUN install -g mock -m 2775 -d /rpmbuild/cache/mock
RUN echo "config_opts['cache_topdir'] = '/rpmbuild/cache/mock'" >> /etc/mock/site-defaults.cfg

RUN cat /etc/mock/site-defaults-extra.cfg >> /etc/mock/site-defaults.cfg

ADD ./build-rpm.sh /build-rpm.sh
RUN chmod +x /build-rpm.sh
#RUN setcap cap_sys_admin+ep /usr/sbin/mock
ADD ./rpm-sign.exp /rpm-sign.exp
RUN chmod +x /rpm-sign.exp

USER builder
ENV HOME /home/builder
CMD ["/build-rpm.sh"]
105 changes: 87 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
.PHONY: help clean clean-all srpm rpm prepare devbuild signrpm signrepo
.PHONY: help clean clean-build clean-cache srpm rpm prepare devbuild signrpm signrepo build-docker pkg-docker clean-docker rm-docker docker-prepare docker-cleanup docker-test

.DEFAULT: help

ifndef VERBOSE
.SILENT:
endif

SHELL=bash
CWD:=$(shell pwd -P)
NAME=nextcloud
VERSION:=$(shell cat SPECS/nextcloud.spec | grep "define base_version" | awk '{print $$3}')
VERSION:=$(shell cat rpmbuild/SPECS/nextcloud.spec | grep "define base_version" | awk '{print $$3}')
BUILD_NUMBER?=DEV
DONE = echo -e "\e[31m✓\e[0m \e[33m$@\e[0m \e[32mdone\e[0m"
TOOLS="rpmdevtools mock"
NTOOLS:=$(shell rpm -qa "$(TOOLS)" | wc -l)
PKG:=$(shell if [ -d pkg ]; then ls RPMS/$(NAME)-$(VERSION)*.noarch.rpm; else echo 0; fi)
PKG:=$(shell if [ -d pkg ]; then ls pkg/$(NAME)-$(VERSION)*.noarch.rpm; else echo 0; fi)
# default
MOCK_CONFIG=epel-7-x86_64
NO_COLOR=\033[0m
GREEN=\033[32;01m
YELLOW=\033[33;01m
RED=\033[31;01m

help:: ## Show this help
echo -e "\n$(NAME) packaging: Version \033[32m$(VERSION)\033[0m Release: \033[1m$(BUILD_NUMBER)\033[0m\n"
Expand All @@ -26,37 +35,44 @@ endif
$(DONE)

srpm: prepare ## Build a source rpm
mock --buildsrpm --spec=$(CWD)/SPECS/$(NAME).spec --sources=$(CWD)/SOURCES/ --resultdir=$(CWD)/SRPMS --define "__version $(VERSION)" --define "__release $(BUILD_NUMBER)"
rm -rf SRPMS/*.log
echo -e "Package saved to: \e[31m`ls SRPMS/$(NAME)-$(VERSION)*.src.rpm`\e[0m"
mock --buildsrpm --spec=$(CWD)/rpmbuild/SPECS/$(NAME).spec --sources=$(CWD)/rpmbuild/SOURCES/ --resultdir=$(CWD)/rpmbuild/output --define "__version $(VERSION)" --define "__release $(BUILD_NUMBER)"
rm -rf rpmbuild/output/*.log
echo -e "Package saved to: \e[31m`ls rpmbuild/output/$(NAME)-$(VERSION)*.src.rpm`\e[0m"
$(DONE)

minimalsrpm: prepare ## Build a source rpm
mock --buildsrpm --spec=$(CWD)/SPECS/$(NAME).spec --sources=$(CWD)/SOURCES/ --resultdir=$(CWD)/SRPMS --define "__version $(VERSION)" --define "__release $(BUILD_NUMBER)" --rpmbuild-opts "--without apache"
rm -rf SRPMS/*.log
echo -e "Package saved to: \e[31m`ls SRPMS/$(NAME)-$(VERSION)*.src.rpm`\e[0m"
mock --buildsrpm --spec=$(CWD)/rpmbuild/SPECS/$(NAME).spec --sources=$(CWD)/rpmbuild/SOURCES/ --resultdir=$(CWD)/rpmbuild/output --define "__version $(VERSION)" --define "__release $(BUILD_NUMBER)" --rpmbuild-opts "--without apache"
rm -rf rpmbuild/output/*.log
echo -e "Package saved to: \e[31m`ls rpmbuild/output/$(NAME)-$(VERSION)*.src.rpm`\e[0m"
$(DONE)

rpm: srpm ## Build an rpm from the sourcerpm
mock --rebuild $(CWD)/SRPMS/$(NAME)*.src.rpm --resultdir=$(CWD)/RPMS/ --define "__version $(VERSION)" --define "__release $(BUILD_NUMBER)"
cp RPMS/$(NAME)-$(VERSION)*.noarch.rpm pkg/
echo -e "Package saved to: \e[31m`ls RPMS/$(NAME)-$(VERSION)*.noarch.rpm`\e[0m"
mock --rebuild $(CWD)/rpmbuild/output/$(NAME)*.src.rpm --resultdir=$(CWD)/rpmbuild/output --define "__version $(VERSION)" --define "__release $(BUILD_NUMBER)"
cp rpmbuild/output/$(NAME)-$(VERSION)*.noarch.rpm pkg/
echo -e "Package saved to: \e[31m`ls rpmbuild/output/$(NAME)-$(VERSION)*.noarch.rpm`\e[0m"
$(DONE)

minimalrpm: minimalsrpm ## Build an rpm from the sourcerpm
mock --rebuild $(CWD)/SRPMS/$(NAME)*.src.rpm --resultdir=$(CWD)/RPMS/ --define "__version $(VERSION)" --define "__release $(BUILD_NUMBER)" --rpmbuild-opts "--without apache"
cp RPMS/$(NAME)-$(VERSION)*.noarch.rpm pkg/
echo -e "Package saved to: \e[31m`ls RPMS/$(NAME)-$(VERSION)*.noarch.rpm`\e[0m"
mock --rebuild $(CWD)/rpmbuild/output/$(NAME)*.src.rpm --resultdir=$(CWD)/rpmbuild/output --define "__version $(VERSION)" --define "__release $(BUILD_NUMBER)" --rpmbuild-opts "--without apache"
cp rpmbuild/output/$(NAME)-$(VERSION)*.noarch.rpm pkg/
echo -e "Package saved to: \e[31m`ls rpmbuild/output/$(NAME)-$(VERSION)*.noarch.rpm`\e[0m"
$(DONE)

clean-package: ## Clean-up packaging
$(DONE)

clean: ## Clean up the workspace
rm -rf RPMS SRPMS SOURCES/*.{gz,bz2}
clean-build: ## Clean up the workspace
rm -rf src rpmbuild/output rpmbuild/SOURCES/*.{gz,bz2}
$(DONE)

clean-all: clean ## Clean up also packages
clean: clean-build clean-cache ## Clean up also packages
rm -rf pkg
$(DONE)

clean-cache: ## Clean up mock cache
rm -rf rpmbuild/cache
$(DONE)

devbuild: prepare ## Build a dev version, bypassing mock (useful for debugging RPM build issues)
rpmbuild -ba --define "%_topdir $(CWD)" --define "__version $(VERSION)" --define "__release $(BRANCH).$(COMMIT).$(BUILD_NUMBER)" $(CWD)/SPECS/$(NAME).spec
$(DONE)
Expand All @@ -69,3 +85,56 @@ signrpm: ## Sign the rpm with the gpg key
signrepo: ## Sign the repo key
gpg --detach-sign --armor --yes repodata/repomd.xml
$(DONE)

build-docker: ## Build docker image
echo -e "==> $(YELLOW)Build Docker images$(NO_COLOR)"
docker build --network host --pull --force-rm \
-f Dockerfile -t bevc/$(NAME) \
.
$(DONE)

pkg-docker: build-docker clean-docker clean-build ## Package RPM using docker image
echo -e "==> $(GREEN)Build the RPM package$(NO_COLOR)"
mkdir -p pkg
# Build RPM package
docker run --cap-add=SYS_ADMIN --network host \
-e MOCK_CONFIG=$(MOCK_CONFIG) -e SOURCES=SOURCES/ \
-e SPEC_FILE=SPECS/$(NAME).spec \
-e MOCK_DEFINES="VERSION=$(VERSION) RELEASE=$(BUILD_NUMBER) ANYTHING_ELSE=1" \
--rm -v ${PWD}/rpmbuild:/rpmbuild \
bevc/$(NAME)
#--workdir=/src
echo -e "==> $(GREEN)Moving artifact $(RED)$$(basename $$(ls rpmbuild/output/$(MOCK_CONFIG)/*.noarch.rpm))$(GREEN) to $(YELLOW)pkg/$(GREEN) folder...$(NO_COLOR)"
mv rpmbuild/output/$(MOCK_CONFIG)/*.noarch.rpm pkg/
rm -rf rpmbuild/output/$(MOCK_CONFIG) rpmbuild/SOURCES/*.bz2
$(DONE)

clean-docker: ## Clean-up unused docker images
#docker rmi $$(docker images | grep "^<none>" | awk "{print $$3}")
#if [ $$(docker ps -q --filter ancestor=$$(docker images -f dangling=true -q) | wc -l) -gt 0 ]; then echo "Cleaning up letftover containers!"; docker rm -f $$(docker ps -q --filter ancestor=$$(docker images -f dangling=true -q)); fi
#if [ $$(docker images -f "dangling=true" -q | wc -l) -gt 0 ]; then docker rmi -f $$(docker images -f "dangling=true" -q); else echo "No orphan Docker images found ;)"; fi
# Clean up leftover containers from old images
docker container prune -f
# Clean up old unused images
docker image prune -f
$(DONE)

rm-docker: ## Remove all docker images
docker rmi -f $$(docker images -q -a)
$(DONE)

# Not parallel safe to prepare
docker-prepare: build-docker clean-docker ## Prepare Docker container image

# Docker clean up
docker-cleanup: ## Run tests in a Docker container
if [ $$(docker ps -qa --no-trunc --filter "status=exited" | wc -l) -ne 0 ]; then docker rm $$(docker ps -qa --no-trunc --filter "status=exited"); fi

# Test using Docker image and clean up
docker-test: ## Run tests in a Docker container
echo -e "==> $(YELLOW)Running test: ${TEST} in Docker$(NO_COLOR)"
docker run --network bridge -v ${PWD}:/src --workdir=/src -e LANG=en_US.UTF-8 \
-e DB_DATABASE=${DB_DATABASE} -e DB_USERNAME=${DB_USERNAME} -e DB_PASSWORD=${DB_PASSWORD} \
bevc/nextcloud make ${TEST}
$(MAKE) docker-cleanup
$(DONE)
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Nextcloud
Nextcloud community contributed RPM packaging

Nextcloud community contributed RPM packaging.

## Usage

To build RPM:
~~~ make
To build RPM using Docker:
```bash
make pkg-docker
```

To build RPM using local Mock installation:
```make
make rpm
~~~
```

To get other options you can use: `make help`

Expand All @@ -15,10 +21,13 @@ the response body.

## Tips

Produced RPM are saved to [`pkg/`](https://github.com/mbevc1/nextcloud/tree/master/pkg) folder where you can also find latest builds
in this repo.
Produced RPM are saved to `pkg/` folder.

## Authors
* [Marko Bevc](https://github.com/mbevc1)

## Contributors and thanks
* [Tobia De Koninck](https://github.com/LEDfan)
* Docker inspiration and scripts: https://github.com/mmornati/docker-mock-rpmbuilder

Check the commit log for a complete list.
114 changes: 114 additions & 0 deletions build-rpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash

MOCK_BIN=/usr/bin/mock
MOCK_CONF_FOLDER=/etc/mock
MOUNT_POINT=/rpmbuild
OUTPUT_FOLDER=$MOUNT_POINT/output
CACHE_FOLDER=$MOUNT_POINT/cache/mock
MOCK_DEFINES=($MOCK_DEFINES) # convert strings into array items
DEF_SIZE=${#MOCK_DEFINES[@]}

if [ $DEF_SIZE -gt 0 ];
then
for ((i=0; i<$DEF_SIZE; i++));
do
#MOCK_DEFINES{$i}=$(echo ${MOCK_DEFINES[$i]} |sed 's/=/ /g')
DEFINE_CMD+="--define '$(echo ${MOCK_DEFINES[$i]} |sed 's/=/ /g')' "
done
fi

#$DEFINE_CMD=$(printf %s $DEFINE_CMD)
if [ -z "$MOCK_CONFIG" ]; then
echo "MOCK_CONFIG is empty. Should bin one of: "
ls -l $MOCK_CONF_FOLDER
fi
if [ ! -f "${MOCK_CONF_FOLDER}/${MOCK_CONFIG}.cfg" ]; then
echo "MOCK_CONFIG is invalid. Should bin one of: "
ls -l $MOCK_CONF_FOLDER
fi
if [ -z "$SOURCE_RPM" ] && [ -z "$SPEC_FILE" ]; then
echo "You need to provide the src.rpm or spec file to build"
echo "Set SOURCE_RPM or SPEC_FILE environment variables"
exit 1
fi
if [ ! -z "$NO_CLEANUP" ]; then
echo "WARNING: Disabling clean up of the build folder after build."
fi

#If proxy env variable is set, add the proxy value to the configuration file
if [ ! -z "$HTTP_PROXY" ] || [ ! -z "$http_proxy" ]; then
TEMP_PROXY=""
if [ ! -z "$HTTP_PROXY" ]; then
TEMP_PROXY=$(echo $HTTP_PROXY | sed s/\\//\\\\\\//g)
fi
if [ ! -z "$http_proxy" ]; then
TEMP_PROXY=$(echo $http_proxy | sed s/\\//\\\\\\//g)
fi

echo "Configuring http proxy to the mock build file to: $TEMP_PROXY"
cp /etc/mock/$MOCK_CONFIG.cfg /tmp/$MOCK_CONFIG.cfg
sed s/\\[main\\]/\[main\]\\\nproxy=$TEMP_PROXY/g /tmp/$MOCK_CONFIG.cfg > /etc/mock/$MOCK_CONFIG.cfg
fi

OUTPUT_FOLDER=${OUTPUT_FOLDER}/${MOCK_CONFIG}
if [ ! -d "$OUTPUT_FOLDER" ]; then
mkdir -p $OUTPUT_FOLDER
else
rm -f $OUTPUT_FOLDER/*
fi

if [ ! -d "$CACHE_FOLDER" ]; then
mkdir -p $CACHE_FOLDER
fi

echo "=> Building parameters:"
echo "========================================================================"
echo " MOCK_CONFIG: $MOCK_CONFIG"
#Priority to SOURCE_RPM if both source and spec file env variable are set
if [ ! -z "$SOURCE_RPM" ]; then
echo " SOURCE_RPM: $SOURCE_RPM"
echo " OUTPUT_FOLDER: $OUTPUT_FOLDER"
echo "========================================================================"
if [ ! -z "$NO_CLEANUP" ]; then
echo "$MOCK_BIN $DEFINE_CMD -r $MOCK_CONFIG --rebuild $MOUNT_POINT/$SOURCE_RPM --resultdir=$OUTPUT_FOLDER --no-clean" > $OUTPUT_FOLDER/script-test.sh
else
echo "$MOCK_BIN $DEFINE_CMD -r $MOCK_CONFIG --rebuild $MOUNT_POINT/$SOURCE_RPM --resultdir=$OUTPUT_FOLDER" > $OUTPUT_FOLDER/script-test.sh
fi
elif [ ! -z "$SPEC_FILE" ]; then
if [ -z "$SOURCES" ]; then
echo "You need to specify SOURCES env variable pointing to folder or sources file (only when building with SPEC_FILE)"
exit 1;
fi
echo " SPEC_FILE: $SPEC_FILE"
echo " SOURCES: $SOURCES"
echo " OUTPUT_FOLDER: $OUTPUT_FOLDER"
echo " MOCK_DEFINES: $MOCK_DEFINES"
echo "========================================================================"
# Download dependencies
spectool -C $MOUNT_POINT/$SOURCES -g $MOUNT_POINT/$SPEC_FILE
if [ ! -z "$NO_CLEANUP" ]; then
# do not cleanup chroot between both mock calls as 1st does not alter it
echo "$MOCK_BIN $DEFINE_CMD -r $MOCK_CONFIG --buildsrpm --spec=$MOUNT_POINT/$SPEC_FILE --sources=$MOUNT_POINT/$SOURCES --resultdir=$OUTPUT_FOLDER --no-cleanup-after" > $OUTPUT_FOLDER/script-test.sh
echo "$MOCK_BIN $DEFINE_CMD -r $MOCK_CONFIG --rebuild \$(find $OUTPUT_FOLDER -type f -name \"*.src.rpm\") --resultdir=$OUTPUT_FOLDER --no-clean" >> $OUTPUT_FOLDER/script-test.sh
else
echo "$MOCK_BIN $DEFINE_CMD -r $MOCK_CONFIG --buildsrpm --spec=$MOUNT_POINT/$SPEC_FILE --sources=$MOUNT_POINT/$SOURCES --resultdir=$OUTPUT_FOLDER" > $OUTPUT_FOLDER/script-test.sh
echo "$MOCK_BIN $DEFINE_CMD -r $MOCK_CONFIG --rebuild \$(find $OUTPUT_FOLDER -type f -name \"*.src.rpm\") --resultdir=$OUTPUT_FOLDER" >> $OUTPUT_FOLDER/script-test.sh
fi
fi

chmod 755 $OUTPUT_FOLDER/script-test.sh
$OUTPUT_FOLDER/script-test.sh

rm $OUTPUT_FOLDER/script-test.sh


if [ ! -z "$SIGNATURE" ]; then
echo "%_signature gpg" > $HOME/.rpmmacros
echo "%_gpg_name ${SIGNATURE}" >> $HOME/.rpmmacros
echo "Signing RPM using ${SIGNATURE} key"
find $OUTPUT_FOLDER -type f -name "*.rpm" -exec /rpm-sign.exp {} ${GPG_PASS} \;
else
echo "No RPMs signature requested"
fi

echo "Build finished. Check results inside the mounted volume folder."
11 changes: 11 additions & 0 deletions rpm-sign.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/expect

### rpm-sign.exp -- Sign RPMs by sending the passphrase.
set file [lindex $argv 0]
set pass [lindex $argv 1]
spawn rpm --resign $file
expect -exact "Enter pass phrase: "
send -- "$pass\r"
expect eof

### End of rpm-sign.exp
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion SPECS/nextcloud.spec → rpmbuild/SPECS/nextcloud.spec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
%define statedir /run
%endif

%define base_version 13.0.6
%define base_version 14.0.1
%define rel %(echo 1)

Name: nextcloud
Expand Down Expand Up @@ -222,6 +222,7 @@ fi
%{apache_serverroot}/%{name}/lib
%{apache_serverroot}/%{name}/ocs
%{apache_serverroot}/%{name}/ocs-provider
%{apache_serverroot}/%{name}/ocm-provider
%{apache_serverroot}/%{name}/resources
%{apache_serverroot}/%{name}/settings
%{apache_serverroot}/%{name}/themes
Expand All @@ -242,6 +243,12 @@ fi
%{apache_serverroot}/%{name}/data

%changelog
* Thu Oct 04 2018 Marko Bevc <[email protected]> - 14.0.1-1
- Update to version 14.

* Thu Oct 04 2018 Marko Bevc <[email protected]> - 13.0.6-2
- Switch to Docker build.

* Sun Sep 02 2018 Marko Bevc <[email protected]> - 13.0.6-1
- Update version.

Expand Down

0 comments on commit 1b4c970

Please sign in to comment.