Skip to content

Instantly share code, notes, and snippets.

@lukassup
Created November 12, 2016 20:09
Show Gist options
  • Save lukassup/b6b635683a26fb8bd0d25f09a2173113 to your computer and use it in GitHub Desktop.
Save lukassup/b6b635683a26fb8bd0d25f09a2173113 to your computer and use it in GitHub Desktop.

Creating an RPM from a Python package

On your dev host you need Python, virtualenv and Docker installed.

On your build host (or container) you need python and rpm-build packages.

Install cookiecutter Python package in your Python virtualenv. It can be used to create instalable Python packages. Most importantly, it creates the setup.py file for you.

$ virtualenv rpmbuild
$ source rpmbuild/bin/activate
$ pip install -U cookiecutter

Use a Github repo for the Python package cookiecutter.

$ cookiecutter gh:audreyr/cookiecutter-pypackage
full_name [Lukas Šupienis]: Lukas Šupienis
email [lukassup@yahoo.com]: lukassup@yahoo.com
github_username [lukassup]: lukassup
project_name [Python Boilerplate]: Example
project_slug [example]: 
project_short_description [Python Boilerplate contains all the boilerplate you need to create a Python package.]: 
pypi_username [lukassup]: lukassup
version [0.1.0]: 
use_pytest [n]: n
use_pypi_deployment_with_travis [y]: n
Select command_line_interface:
1 - Click
2 - No command-line interface
Choose from 1, 2 [1]: 2
create_author_file [y]: n
Select open_source_license:
1 - MIT license
2 - BSD license
3 - ISC license
4 - Apache Software License 2.0
5 - GNU General Public License v3
6 - Not open source
Choose from 1, 2, 3, 4, 5, 6 [1]: 6
$ cd example

Create the Dockerfile. Could be any Red Hat based distribution.

$ cat > Dockerfile << __EOF__
FROM fedora:latest
RUN dnf update -y && dnf clean all
RUN dnf install -y rpm-build && dnf clean all
RUN dnf install -y python && dnf clean all
ADD . /code
WORKDIR /code
RUN python setup.py bdist_rpm
WORKDIR /code/dist
CMD python -m SimpleHTTPServer
__EOF__

Start Docker, build an image from Dockerfile, build the RPM from Python package and expose port 8000.

$ sudo systemctl start docker
$ docker build -t rpm-build .
$ docker run -d -p 8000:8000 rpm-build

Go to http://localhost:8000/ in your browser and download the built RPM package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment