Skip to content

Instantly share code, notes, and snippets.

@astraw
Created November 18, 2013 21:41
Show Gist options
  • Save astraw/7535850 to your computer and use it in GitHub Desktop.
Save astraw/7535850 to your computer and use it in GitHub Desktop.
stdeb quickstart: This uses docker ( http://docker.io ) to create an IPython notebook pre-configured to build a Debian source package. See the comments at the top of the Dockerfile for further instructions.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "build_and_publish_pypi"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "# Build a debian package from a PyPI file\n\nThis is a quick-and-dirty interface to build Debian source files (.dsc) directly from PyPI. These should work on Debian, Ubuntu, and so on.\n\n## What to do\n\nEdit the values below to create something useful for yourself."
},
{
"cell_type": "code",
"collapsed": false,
"input": "PyPI_name = 'argh'\nmaintainer = 'Andrew Straw <strawman@astraw.com>'\nworkdir = '/stdeb-work'\nsuite = 'precise'",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": "# With correct values above, the rest of this should Just Work."
},
{
"cell_type": "code",
"collapsed": false,
"input": "!mkdir -p {workdir} && cd {workdir} && pypi-download {PyPI_name}",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": "files = !cd {workdir} && ls\nfiles = [f for f in files if f != 'deb_dist'] # ignore previous builds\nassert len(files)==1\nsource_fname = files[0]",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": "!cd {workdir} && py2dsc --maintainer \"{maintainer}\" --suite {suite} {source_fname}",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": "import debian.deb822\n\nimport glob, os\n\ndsc_dir = os.path.join(workdir,'deb_dist')\n\ndsc_fnames = glob.glob(os.path.join(dsc_dir,'*.dsc'))\nassert len(dsc_fnames)==1\ndsc_full_fname=dsc_fnames[0]\ndsc_fname = os.path.basename(dsc_full_fname)\n\nfd = open(dsc_full_fname,mode='r')\ndsc = debian.deb822.Dsc( sequence=fd )\n\ndsc.get('Files')",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": "upload_files = [ f['name'] for f in dsc.get('Files')]\nupload_files.append( dsc_fname )\n\ntarball_name = os.path.splitext(dsc_fname)[0] + '.tar'\nfiles_str = ' '.join(upload_files)",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": "!tar cvf {tarball_name} -C {dsc_dir} {files_str}",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": "# Now download this file"
},
{
"cell_type": "code",
"collapsed": false,
"input": "from IPython.display import FileLink\nFileLink(tarball_name)",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
# Build this docker image with:
#
# sudo docker build .
#
# Take note of the <image_id>, which will be the output above in the
# form "Successfully built <image_id>". Now, run the IPython web
# notebook with:
#
# sudo docker run -p 8889:8889 <image_id>
#
# This will spawn a webserver on port 8889. Go there and follow the
# instructions.
FROM ubuntu:12.04
MAINTAINER Andrew Straw <strawman@astraw.com>
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y
# ---- install IPython ------------
RUN apt-get install -y curl python-dev build-essential
RUN curl -o distribute_setup.py http://python-distribute.org/distribute_setup.py
RUN python distribute_setup.py
RUN curl -o get-pip.py https://raw.github.com/pypa/pip/master/contrib/get-pip.py
RUN python get-pip.py
RUN apt-get install -y libzmq-dev
RUN pip install pyzmq
RUN pip install ipython
RUN pip install jinja2
RUN pip install tornado
# ---- install stdeb ------------
# Install stdeb
RUN apt-get install -y git debhelper python
RUN git clone https://github.com/astraw/stdeb.git
RUN cd stdeb && python setup.py install
# Get requirements for building debian source package
RUN apt-get install -y python-setuptools
# ---- misc helpers ------------
RUN pip install python-debian==0.1.21
RUN pip install chardet==2.1.1 # required for python-debian
# --- config for starting IPython -----
EXPOSE 8889
ADD build_and_publish_pypi.ipynb /notebooks/build_and_publish_pypi.ipynb
# --- command for starting IPython -----
CMD ipython notebook --NotebookApp.ip='*' --NotebookApp.port=8889 --notebook-dir=/notebooks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment