Skip to content

Instantly share code, notes, and snippets.

@kazu69
Last active August 7, 2016 05:42
Show Gist options
  • Save kazu69/6679a7865fe79a1399658a6837176005 to your computer and use it in GitHub Desktop.
Save kazu69/6679a7865fe79a1399658a6837176005 to your computer and use it in GitHub Desktop.
rpmbuild custom package example

example

create rpm hello using rpmbuild.

docker build -t fedora -f ./fedora.dockerfile .
ocker run -it fedora /bin/bash
bash-4.3# hellow
bash: hellow: command not found
bash-4.3# hello
hello, world!
bash-4.3# exit
FROM fedora:21
RUN yum update -y && \
yum install -y rpm-build tar gcc sudo
# create rpmbuilder
RUN useradd rpmbuilder
USER rpmbuilder
# create working dir
RUN mkdir -p /home/rpmbuilder/hello-1.0
RUN mkdir -p /home/rpmbuilder/rpmbuild/{SOURCES,SPECS}
RUN chown rpmbuilder:rpmbuilder /home/rpmbuilder/rpmbuild/{SOURCES,SPECS}
# add source file
ADD ./hello.c /home/rpmbuilder/hello-1.0/hello.c
ADD ./hello.spec /home/rpmbuilder/rpmbuild/SPECS/hello.spec
# compile
WORKDIR /home/rpmbuilder/hello-1.0
RUN gcc -o hello hello.c && rm -rf hello.c
# packaging
WORKDIR /home/rpmbuilder/
RUN tar czvf hello-1.0.tar.gz hello-1.0 && \
chmod 777 rpmbuild/SOURCES/ && \
cp hello-1.0.tar.gz rpmbuild/SOURCES
# rpm create
WORKDIR /home/rpmbuilder/rpmbuild
RUN rpmbuild -bb -v SPECS/hello.spec
# install hello
USER root
RUN rpm -ivh RPMS/noarch/hello-1.0-1.noarch.rpm
CMD ["bin", "bash"]
#include <stdio.h>
main(void)
{
printf("hello, world!\n");
}
%define name hello
%define version 1.0
%define unmangled_version 1.0
%define release 1
%define _binaries_in_noarch_packages_terminate_build 0
%define _unpackaged_files_terminate_build 0
Summary: sample hello world program
Name: %{name}
Version: %{version}
Release: %{release}
License: GPL2
Source0: %{name}-%{unmangled_version}.tar.gz
Group: Applications/File
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
BuildArch: noarch
%define INSTALLDIR %{buildroot}/usr/local/bin
%description
This is a sample program to learn how to make a rpm package.
%prep
%setup -q
%build
%install
rm -rf %{INSTALLDIR}
mkdir -p %{INSTALLDIR}
cp -R * %{INSTALLDIR}
%clean
rm -rf %{buildroot}
%files
%defattr(-, root, root)
/usr/local/bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment