$30 off During Our Annual Pro Sale. View Details »

fpm-cookery RUGHH Oct 2011

fpm-cookery RUGHH Oct 2011

An introduction to fpm-cookery I gave at the Ruby User Group Hamburg/Germany in October 2011.

Bernd Ahlers

October 12, 2011
Tweet

More Decks by Bernd Ahlers

Other Decks in Programming

Transcript

  1. fpm-cookery
    Ruby User Group HH
    12. Oct 2011

    View Slide

  2. No web stuff today!
    this talk is about building and packaging software

    View Slide

  3. No web stuff today!

    View Slide

  4. I need a custom package real
    quick!

    View Slide

  5. Debian
    $ curl http://.../redis-2.2.14.tar.gz
    $ mkdir redis-2.2.14
    $ cd redis-2.2.14
    $ dh_make -f ../redis-2.2.14.tar.gz
    [answer questions]

    View Slide

  6. Debian
    $ find . | sort
    .
    ./debian
    ./debian/changelog
    ./debian/compat
    ./debian/control
    ./debian/copyright
    ./debian/cron.d.ex
    ./debian/docs
    ./debian/emacsen-install.ex

    View Slide

  7. $ [cont.]
    ./debian/emacsen-remove.ex
    ./debian/emacsen-startup.ex
    ./debian/init.d.ex
    ./debian/init.d.lsb.ex
    ./debian/manpage.1.ex
    ./debian/manpage.sgml.ex
    ./debian/manpage.xml.ex
    ./debian/menu.ex
    ./debian/postinst.ex
    ./debian/postrm.ex
    ./debian/preinst.ex
    ./debian/prerm.ex
    ./debian/README.Debian
    ./debian/README.source
    ./debian/rules
    ./debian/redis.default.ex
    ./debian/redis.doc-base.EX
    ./debian/watch.ex

    View Slide

  8. Debian
    we haven't built anything yet
    I cant' remember the commands

    View Slide

  9. Debian
    lots of Debian documentation to read
    lots of rules to follow

    View Slide

  10. Debian ?!

    View Slide

  11. fpm

    View Slide

  12. fpm
    by Jordan Sissel (@jordansissel)
    helps you build packages quickly
    DEB and RPM formats

    View Slide

  13. fpm
    $ curl http://.../redis-2.2.14.tar.gz
    $ tar -xzf redis-2.2.14
    $ cd redis-2.2.14
    $ make
    $ make PREFIX=$PWD/dest/usr install
    $ fpm -s dir -t deb -n redis -v 2.2.14 -C dest
    Created $PWD/redis_2.2.14_i386.deb

    View Slide

  14. RPM packages?
    $ curl http://.../redis-2.2.14.tar.gz
    $ tar -xzf redis-2.2.14
    $ cd redis-2.2.14
    $ make
    $ make PREFIX=$PWD/dest/usr install
    $ fpm -s dir -t rpm -n redis -v 2.2.14 -C dest
    Created $PWD/redis-2.2.14.i686.rpm

    View Slide

  15. brew2deb

    View Slide

  16. brew2deb
    by Aman Gupta (@tmm1)
    a hack that combines Homebrew and fpm

    View Slide

  17. brew2deb (good stuff)
    helps you to build packages quickly
    can use Homebrew formulas (with minimal
    modifications)
    can handle Debian .dsc files (awesome!)

    View Slide

  18. brew2deb (stuff I don't
    like)
    vendored Homebrew (with lots of Mac OS specific
    stuff)
    vendored fpm
    no speparation between framework and formulas

    View Slide

  19. brew2deb Usage
    $ cd brew2deb.git/packages/redis
    $ ../../bin/brew2deb
    ==> Downloading ...
    ==> Extracing source
    ...
    ==> Packaging into a .deb
    Created brew2deb/packages/redis/pkg/redis-2.2.14+github1_i386.deb

    View Slide

  20. Custom Scripts

    View Slide

  21. Custom Scripts
    I built my own hacks
    Makefiles
    shell scripts

    View Slide

  22. Makefile
    $ cat ~/.fpmmake
    zeromq: destdir
    rm -rf $(DEST_DIR)/$@
    ./configure --prefix=/usr
    make
    make DESTDIR=$(DEST_ROOT)/$@ install
    fpm -s dir -t $(TARGET) -n zeromq -v 2.1.7 \
    -C $(DEST_ROOT)/$@ \
    -m $(MAINTAINER) --url http://www.zeromq.org/
    $ make -f ~/.fpmmake zeromq

    View Slide

  23. Custom Scripts
    works but feels crappy
    isn't really shareable

    View Slide

  24. fpm-cookery

    View Slide

  25. fpm-cookery
    an infrastructure to automatically build and package
    software based on recipes

    View Slide

  26. fpm-cookery
    ideas and code from Homebrew
    ideas and code from brew2deb

    View Slide

  27. Features
    recipes to describe the build
    can handle different source types (http/https/ftp for
    now...)
    builds software based on the recipe (configure,
    make, make install)

    View Slide

  28. Features (cont.)
    sandboxed builds (no root, no install in /usr)
    creates packages with fpm
    standalone recipe trees

    View Slide

  29. Features - planned
    patch handling
    build/run depends check
    recipe validation

    View Slide

  30. Features - planned (cont.)
    more source types (Git, SVN, ...)
    support for rpm (dependencies, rpm specific
    options)
    programing api?

    View Slide

  31. Setup
    $ gem install fpm-cookery
    Fetching: fpm-cookery-0.0.1.gem (100%)
    Successfully installed fpm-cookery-0.0.1
    1 gem installed
    $ mkdir fpm-recipes/redis && cd fpm-recipes/redis
    $ $EDITOR recipe.rb

    View Slide

  32. Example Recipe
    class Redis < F
    P
    M
    :
    :
    C
    o
    o
    k
    e
    r
    y
    :
    :
    R
    e
    c
    i
    p
    e
    description '
    A
    n a
    d
    v
    a
    n
    c
    e
    d k
    e
    y
    -
    v
    a
    l
    u
    e s
    t
    o
    r
    e
    '
    name '
    r
    e
    d
    i
    s
    -
    s
    e
    r
    v
    e
    r
    '
    version '
    2
    :
    2
    .
    2
    .
    1
    4
    '
    revision 1
    homepage '
    h
    t
    t
    p
    :
    /
    /
    r
    e
    d
    i
    s
    .
    i
    o
    /
    '
    source \
    "
    h
    t
    t
    p
    :
    /
    /
    r
    e
    d
    i
    s
    .
    g
    o
    o
    g
    l
    e
    c
    o
    d
    e
    .
    c
    o
    m
    /
    f
    i
    l
    e
    s
    /
    r
    e
    d
    i
    s
    -
    2
    .
    2
    .
    1
    4
    .
    t
    a
    r
    .
    g
    z
    "
    section '
    d
    a
    t
    a
    b
    a
    s
    e
    '
    conflicts '
    r
    e
    d
    i
    s
    -
    s
    e
    r
    v
    e
    r
    '
    config_files '
    /
    e
    t
    c
    /
    r
    e
    d
    i
    s
    /
    r
    e
    d
    i
    s
    .
    c
    o
    n
    f
    '
    # ...
    end

    View Slide

  33. Example Recipe (cont.)
    class Redis < F
    P
    M
    :
    :
    C
    o
    o
    k
    e
    r
    y
    :
    :
    R
    e
    c
    i
    p
    e
    # ...
    def build
    make
    # Fix up default conf file to match our paths
    inline_replace "
    r
    e
    d
    i
    s
    .
    c
    o
    n
    f
    " do |s|
    s.gsub! '
    d
    a
    e
    m
    o
    n
    i
    z
    e n
    o
    '
    , '
    d
    a
    e
    m
    o
    n
    i
    z
    e y
    e
    s
    '
    s.gsub! '
    l
    o
    g
    f
    i
    l
    e s
    t
    d
    o
    u
    t
    '
    ,
    '
    l
    o
    g
    f
    i
    l
    e /
    v
    a
    r
    /
    l
    o
    g
    /
    r
    e
    d
    i
    s
    /
    r
    e
    d
    i
    s
    -
    s
    e
    r
    v
    e
    r
    .
    l
    o
    g
    '
    s.gsub! '
    l
    o
    g
    l
    e
    v
    e
    l v
    e
    r
    b
    o
    s
    e
    '
    , '
    l
    o
    g
    l
    e
    v
    e
    l n
    o
    t
    i
    c
    e
    '
    s.gsub! '
    d
    i
    r .
    /
    '
    , '
    d
    i
    r /
    v
    a
    r
    /
    l
    i
    b
    /
    r
    e
    d
    i
    s
    /
    '
    s.gsub! '
    /
    v
    a
    r
    /
    r
    u
    n
    /
    r
    e
    d
    i
    s
    .
    p
    i
    d
    '
    , '
    /
    v
    a
    r
    /
    r
    u
    n
    /
    r
    e
    d
    i
    s
    .
    p
    i
    d
    '
    end
    end
    # ...
    end

    View Slide

  34. Example Recipe (cont.)
    class Redis < F
    P
    M
    :
    :
    C
    o
    o
    k
    e
    r
    y
    :
    :
    R
    e
    c
    i
    p
    e
    # ...
    def install
    %w(run lib/
    r
    e
    d
    i
    s l
    o
    g
    /
    redis).each { |p| var(p).mkpath }
    bin.install Dir["
    s
    r
    c
    /
    r
    e
    d
    i
    s
    -
    *
    "
    ].select do |f|
    f =~ /
    r
    e
    d
    i
    s
    -
    [
    ^
    \
    .
    ]
    +
    $
    /
    end
    etc('
    r
    e
    d
    i
    s
    '
    ).install "
    r
    e
    d
    i
    s
    .
    c
    o
    n
    f
    "
    etc('
    i
    n
    i
    t
    .
    d
    '
    ).install_p(workdir('
    r
    e
    d
    i
    s
    -
    s
    e
    r
    v
    e
    r
    .
    i
    n
    i
    t
    .
    d
    '
    ),
    '
    r
    e
    d
    i
    s
    -
    s
    e
    r
    v
    e
    r
    '
    )
    end
    end

    View Slide

  35. CLI Example (build)
    $ cd fpm-recipes/redis
    $ fpm-cook
    cd src && make all
    make[1]: Entering directory `tmp-build/redis-2.2.14/src'
    ...
    ["fpm", "-n", "redis-server", "-v", "2.2.14+fpm1",
    "-t", "deb", "-s", "dir", "--url", "http://redis.io/",
    "-C", "fpm-recipes/redis/tmp-dest",
    "--maintainer", "Bernd Ahlers ",
    "--category", "database", "--epoch", "2",
    "--description", "An advanced key-value store",
    "--conflicts", "redis-server",
    "--config-files", "/etc/redis/redis.conf", "."]
    Created $PWD/pkg/redis-server_2.2.14+fpm1_i386.deb

    View Slide

  36. CLI Example (clean)
    $ cd fpm-recipes/redis
    $ fpm-cook clean
    => removes temp stuff

    View Slide

  37. How To Contribute
    I'd love to hear from you (likes, hate, usage reports)
    fork and send pull requests
    send patches
    have fun
    anything!

    View Slide

  38. Thank you!
    I am Bernd Ahlers
    @berndahlers
    github.com/bernd
    xing.to/bernd
    [email protected]

    View Slide

  39. Questions?
    github.com/bernd/fpm­cookery
    github.com/bernd/fpm­recipes
    github.com/jordansissel/fpm
    github.com/tmm1/brew2deb

    View Slide