From 915c81b3ef426fd52ec138ad069ea1271052f209 Mon Sep 17 00:00:00 2001 From: Arthur Jones Date: Thu, 5 Apr 2018 17:52:15 -0700 Subject: [PATCH] alpine packaging: use a more standard packaging format Currently, we just package the frr daemons, but we don't run them. This is fine for basic tests, but it is inconvenient to orchestrate the daemons from downstream test environments. Here, we follow the redhat and debianpkg formats more closely, putting the daemons in /usr/lib/frr and including the frr user and groups in the package. We also include a docker specific startup script and a sysvinit link in /etc/init.d/frr for openrc based alpine installs. Testing done: Built packages, built base images, everything seems to work fine. Uninstalled the package, all the daemons stopped. Issue: https://github.com/FRRouting/frr/issues/2030 Signed-off-by: Arthur Jones --- alpine/APKBUILD.in | 32 +++++++++++++++++++++--- alpine/docker-start | 10 ++++++++ alpine/frr.post-deinstall | 6 +++++ alpine/frr.pre-deinstall | 4 +++ alpine/frr.pre-install | 10 ++++++++ doc/developer/building-frr-on-alpine.rst | 29 +++++++++++++++++---- docker/alpine/Dockerfile | 4 ++- tools/frr | 4 ++- 8 files changed, 88 insertions(+), 11 deletions(-) create mode 100755 alpine/docker-start create mode 100755 alpine/frr.post-deinstall create mode 100755 alpine/frr.pre-deinstall create mode 100755 alpine/frr.pre-install diff --git a/alpine/APKBUILD.in b/alpine/APKBUILD.in index 2b211ccafd..c3e7e939e4 100644 --- a/alpine/APKBUILD.in +++ b/alpine/APKBUILD.in @@ -4,9 +4,9 @@ pkgver=@VERSION@ pkgrel=0 pkgdesc="Free Range Routing is a fork of quagga" url="https://frrouting.org/" -arch="all" +arch="x86_64" license="GPL-2.0" -depends="iproute2 json-c c-ares ipsec-tools iproute2" +depends="json-c c-ares ipsec-tools iproute2 python py-ipaddr bash" makedepends="ncurses-dev net-snmp-dev gawk texinfo perl acct autoconf automake bash binutils binutils-libs bison bsd-compat-headers build-base @@ -20,18 +20,42 @@ makedepends="ncurses-dev net-snmp-dev gawk texinfo perl patch pax-utils pcre perl pkgconf python2 python2-dev readline readline-dev sqlite-libs squashfs-tools sudo tar texinfo xorriso xz-libs py-sphinx" +install="$pkgname.pre-install $pkgname.pre-deinstall $pkgname.post-deinstall" subpackages="$pkgname-dev $pkgname-doc $pkgname-dbg" -source="$pkgname-$pkgver.tar.gz" +source="$pkgname-$pkgver.tar.gz docker-start daemons daemons.conf" builddir="$srcdir"/$pkgname-$pkgver +_sbindir=/usr/lib/frr +_sysconfdir=/etc/frr +_libdir=/usr/lib +_localstatedir=/var/run/frr +_user=frr + build() { cd "$builddir" - ./configure --prefix=/usr || return 1 + ./configure \ + --prefix=/usr \ + --sbindir=$_sbindir \ + --sysconfdir=$_sysconfdir \ + --libdir=$_libdir \ + --localstatedir=$_localstatedir \ + --enable-systemd=no \ + --enable-vtysh \ + --enable-multipath=64 \ + --enable-vty-group=frrvty \ + --enable-user=$_user \ + --enable-group=$_user || return 1 make || return 1 } package() { cd "$builddir" make DESTDIR="$pkgdir" install || return 1 + + install -Dm755 "$srcdir"/docker-start "$pkgdir"$_sbindir + install -Dm644 "$srcdir"/daemons "$pkgdir"$_sysconfdir + install -Dm644 "$srcdir"/daemons.conf "$pkgdir"$_sysconfdir + install -d "$pkgdir"/etc/init.d + ln -s ${_sbindir}/frr "$pkgdir"/etc/init.d/frr } diff --git a/alpine/docker-start b/alpine/docker-start new file mode 100755 index 0000000000..43854ab142 --- /dev/null +++ b/alpine/docker-start @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e + +## +# For volume mounts... +## +chown -R frr:frr /etc/frr +/etc/init.d/frr start +exec sleep 10000d diff --git a/alpine/frr.post-deinstall b/alpine/frr.post-deinstall new file mode 100755 index 0000000000..8f5d3dc40c --- /dev/null +++ b/alpine/frr.post-deinstall @@ -0,0 +1,6 @@ +#!/bin/sh + +getent passwd frr > /dev/null && deluser frr +getent group frrvty > /dev/null && delgroup frrvty +getent group frr > /dev/null && delgroup frr +exit 0 diff --git a/alpine/frr.pre-deinstall b/alpine/frr.pre-deinstall new file mode 100755 index 0000000000..72cf73bc1c --- /dev/null +++ b/alpine/frr.pre-deinstall @@ -0,0 +1,4 @@ +#!/bin/sh + +/etc/init.d/frr stop +exit 0 diff --git a/alpine/frr.pre-install b/alpine/frr.pre-install new file mode 100755 index 0000000000..da608cdcbd --- /dev/null +++ b/alpine/frr.pre-install @@ -0,0 +1,10 @@ +#!/bin/sh + +for g in frr frrvty; do + ! getent group $g > /dev/null && addgroup -S $g +done + +! getent passwd frr > /dev/null && \ + adduser -S -D -h /var/run/frr -s /sbin/nologin -G frr -g frr frr + +adduser frr frrvty diff --git a/doc/developer/building-frr-on-alpine.rst b/doc/developer/building-frr-on-alpine.rst index f0f2aee138..089032b03c 100644 --- a/doc/developer/building-frr-on-alpine.rst +++ b/doc/developer/building-frr-on-alpine.rst @@ -52,13 +52,32 @@ And to run the image: :: - docker run -it --rm frr:latest /bin/sh + docker run -it --rm --name frr frr:latest -Currently, we only package the raw daemons and example files, so, you'll -need to run the daemons by hand (or, better, orchestrate in the Dockerfile). +In the default configuration, none of the frr daemons will be running. +To configure the daemons, exec into the container and edit the configuration +files or mount a volume with configuration files into the container on +startup. To configure by hand: -We can also build directly from docker-compose, with a docker-compose.yml file -like this one: +:: + + docker exec -it frr /bin/sh + vi /etc/frr/daemons + vi /etc/frr/daemons.conf + cp /etc/frr/zebra.conf.sample /etc/frr/zebra.conf + vi /etc/frr/zebra.conf + /etc/init.d/frr start + +Or, to configure the daemons using /etc/frr from a host volume, put the +config files in, say, ./docker/etc and bind mount that into the +container: + +:: + + docker run -it --rm -v `pwd`/docker/etc:/etc/frr frr:latest + +We can also build the base image directly from docker-compose, with a +docker-compose.yml file like this one: :: diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile index 6bd7d90aef..dd29358b07 100644 --- a/docker/alpine/Dockerfile +++ b/docker/alpine/Dockerfile @@ -23,11 +23,13 @@ FROM alpine:3.7 as alpine-builder RUN apk add --no-cache abuild alpine-sdk && mkdir -p /pkgs/apk ADD docker/alpine/alpine-build.sh /usr/bin/ ADD docker/alpine/builder /etc/sudoers.d -COPY --from=source-builder /src/*.tar.gz /src/alpine/APKBUILD /dist/ +COPY --from=source-builder /src/*.tar.gz /src/alpine/* /src/tools/etc/frr/daemons* /dist/ RUN adduser -D -G abuild builder && chown -R builder /dist /pkgs USER builder RUN /usr/bin/alpine-build.sh FROM alpine:3.7 RUN mkdir -p /pkgs/apk COPY --from=alpine-builder /pkgs/apk/ /pkgs/apk/ +RUN apk add --no-cache tini RUN apk add --no-cache --allow-untrusted /pkgs/apk/x86_64/*.apk +ENTRYPOINT [ "/sbin/tini", "--", "/usr/lib/frr/docker-start" ] diff --git a/tools/frr b/tools/frr index 6de19a4bde..e6d5d1053a 100755 --- a/tools/frr +++ b/tools/frr @@ -25,7 +25,9 @@ DAEMONS="zebra bgpd ripd ripngd ospfd ospf6d isisd babeld pimd ldpd nhrpd eigrpd MAX_INSTANCES=5 RELOAD_SCRIPT=/usr/lib/frr/frr-reload.py -. /lib/lsb/init-functions +if [ -e /lib/lsb/init-functions ]; then + . /lib/lsb/init-functions +fi if [ -f /usr/lib/frr/ssd ]; then SSD=/usr/lib/frr/ssd -- 2.39.5