# Description: An open platform for distributed applications for developers and sysadmins
# URL: https://www.docker.com/community-edition
# Maintainer: Matt Housh, jaeger at crux dot ninja
# Depends on: containerd runc btrfs-progs cgroupfs-mount

name=docker
version=24.0.2
release=1
source=(https://github.com/moby/moby/archive/v${version}/moby-${version}.tar.gz \
    https://github.com/docker/cli/archive/v${version}/cli-${version}.tar.gz \
    http://jaeger.morpheus.net/linux/crux/files/$name-man-pages-$version.tar.xz \
    $name.rc $name.conf)

build() {
    export GO111MODULE=auto
    export GOPATH=$SRC
    export DOCKER_GITCOMMIT=659604f
    export DOCKER_BUILDTAGS='seccomp'
    export DISABLE_WARN_OUTSIDE_CONTAINER=1
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external"

    mkdir -p src/github.com/docker

    pushd src/github.com/docker
    ln -s $SRC/cli-$version cli
    pushd cli
    make VERSION=$version GITCOMMIT=${DOCKER_GITCOMMIT} dynbinary
    popd
    popd

    pushd src/github.com/docker
    ln -s $SRC/moby-$version docker
    pushd docker
    VERSION=$version hack/make.sh dynbinary
    popd
    popd

    install -D -m 0755 cli-$version/build/$name $PKG/usr/bin/$name
    install -D -m 0755 moby-$version/bundles/dynbinary-daemon/dockerd \
        $PKG/usr/bin/dockerd
    install -D -m 0755 moby-$version/bundles/dynbinary-daemon/docker-proxy \
        $PKG/usr/bin/docker-proxy

    for M in 1 5 8; do
        install -d -m 0755 $PKG/usr/share/man/man${M}
        install -m 0644 $SRC/man${M}/* $PKG/usr/share/man/man${M}/
    done

    install -D -m 0755 $SRC/$name.rc \
        $PKG/etc/rc.d/$name
    install -D -m 0644 $SRC/$name.conf \
        $PKG/etc/$name.conf

    ln -s containerd $PKG/usr/bin/docker-containerd
    ln -s containerd-shim $PKG/usr/bin/docker-containerd-shim
    ln -s ctr $PKG/usr/bin/docker-containerd-ctr
    ln -s runc $PKG/usr/bin/docker-runc

    install -D -m 0755 moby-$version/contrib/check-config.sh \
        $PKG/usr/share/$name/check-config.sh
    install -D -m 0644 moby-$version/contrib/udev/80-$name.rules \
        $PKG/etc/udev/rules.d/80-$name.rules
    install -D -m 0644 cli-$version/contrib/completion/bash/docker \
        $PKG/etc/bash_completion.d/docker
}
