From 6cbc1a5b4717a0c06a0453221bca6527041a4db6 Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Wed, 29 Mar 2023 00:16:31 +0100 Subject: [PATCH] build: remove local dockerfile for build. They have been moved to https://gitlab.com/roddhjav/builders --- dists/build.sh | 110 +++++++++++++++++++++++++++++++++++++++++++ dists/build/build.sh | 106 ----------------------------------------- 2 files changed, 110 insertions(+), 106 deletions(-) create mode 100644 dists/build.sh delete mode 100644 dists/build/build.sh diff --git a/dists/build.sh b/dists/build.sh new file mode 100644 index 00000000..5247f802 --- /dev/null +++ b/dists/build.sh @@ -0,0 +1,110 @@ +#!/usr/bin/env bash +# Build the package in a clean Archlinux/Debian/Ubuntu container +# Copyright (C) 2022 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +# Usage: make + +set -eu + +readonly BASEIMAGE="${BASEIMAGE:-registry.gitlab.com/roddhjav/builders}" +readonly PREFIX="builder-" +readonly PKGNAME=apparmor.d +readonly VOLUME=/tmp/build +readonly BUILDIR=/home/build/tmp +readonly COMMAND="$1" +VERSION="0.$(git rev-list --count HEAD)-1" +PACKAGER="$(git config user.name) <$(git config user.email)>" +readonly VERSION PACKAGER + +_start() { + local img="$1" + docker start "$img" +} + +_is_running() { + local img="$1" + res="$(docker inspect -f '{{ .State.Running }}' "$img")" &>/dev/null + exist=$? + if [[ $exist -ne 0 ]]; then + return $exist + elif [[ "$res" == true ]]; then + return 0 + else + return 1 + fi +} + +_exist() { + local img="$1" + docker inspect -f '{{ .State.Running }}' "$img" &>/dev/null +} + +sync() { + mkdir -p "$VOLUME" + rsync -ra --delete . "$VOLUME/$PKGNAME" +} + +build_in_docker_makepkg() { + local dist="$1" + local img="$PREFIX$dist" + + if _exist "$img"; then + if ! _is_running "$img"; then + _start "$img" + fi + else + docker pull "$BASEIMAGE/$dist" + docker run -tid --name "$img" --volume "$PWD:$BUILDIR" \ + --env MAKEFLAGS="-j$(nproc)" --env PACKAGER="$PACKAGER" \ + --env BUILDDIR=/tmp/build --env PKGDEST="$BUILDIR" \ + --env DIST="$dist" \ + "$BASEIMAGE/$dist" + fi + + docker exec --workdir="$BUILDIR/" "$img" \ + makepkg -sfC --noconfirm --noprogressbar + mv "$VOLUME/$PKGNAME"-*.pkg.* . +} + +build_in_docker_dpkg() { + local dist="$1" + local img="$PREFIX$dist" + + if _exist "$img"; then + if ! _is_running "$img"; then + _start "$img" + fi + else + docker pull "$BASEIMAGE/$dist" + docker run -tid --name "$img" --volume "$VOLUME:$BUILDIR" \ + --env DEBIAN_FRONTEND=noninteractive --env DIST="$dist" \ + "$BASEIMAGE/$dist" + docker exec "$img" sudo apt-get update -q + docker exec "$img" sudo apt-get install -y golang-go lsb-release config-package-dev rsync + fi + + docker exec --workdir="$BUILDIR/$PKGNAME" "$img" \ + dch --newversion="$VERSION" --urgency=medium --distribution=stable --controlmaint "Release $VERSION" + docker exec --workdir="$BUILDIR/$PKGNAME" "$img" \ + dpkg-buildpackage -b -d --no-sign + cp "$VOLUME/${PKGNAME}_${VERSION}_all.deb" "/tmp/${PKGNAME}_all.deb" + mv "$VOLUME/${PKGNAME}_${VERSION}"_*.* . +} + +main() { + case "$COMMAND" in + archlinux) + build_in_docker_makepkg "$COMMAND" + ;; + + debian | ubuntu | whonix) + sync + build_in_docker_dpkg "$COMMAND" + ;; + + *) ;; + esac +} + +main "$@" diff --git a/dists/build/build.sh b/dists/build/build.sh deleted file mode 100644 index 4aa83879..00000000 --- a/dists/build/build.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env bash -# Build the package in a clean Archlinux/Debian/Ubuntu container -# Copyright (C) 2022 Alexandre Pujol -# SPDX-License-Identifier: GPL-2.0-only - -# Usage: make - -set -eu - -readonly BASEIMAGE="${BASEIMAGE:-}" -readonly IMAGEPREFIX="builder-" -readonly PKGNAME=apparmor.d -readonly VOLUME=/tmp/build -readonly BUILDIR=/home/build/tmp -readonly COMMAND="$1" -VERSION="0.$(git rev-list --count HEAD)-1" -PACKAGER="$(git config user.name) <$(git config user.email)>" -readonly VERSION PACKAGER - -_start() { - local img="$1" - docker start "$img" -} - -_is_running() { - local img="$1" - res="$(docker inspect -f '{{ .State.Running }}' "$img")" &>/dev/null - exist=$? - if [[ $exist -ne 0 ]]; then - return $exist - elif [[ "$res" == true ]]; then - return 0 - else - return 1 - fi -} - -_exist() { - local img="$1" - docker inspect -f '{{ .State.Running }}' "$img" &>/dev/null -} - -sync() { - mkdir -p "$VOLUME" - rsync -ra --delete . "$VOLUME/$PKGNAME" -} - -build_in_docker_makepkg() { - local dist="$1" - local img="$IMAGEPREFIX$dist" - - if _exist "$img"; then - if ! _is_running "$img"; then - _start "$img" - fi - else - docker build -t "$BASEIMAGE$img" "dists/build/$dist" - docker run -tid --name "$img" --volume "$PWD:$BUILDIR" \ - --env MAKEFLAGS="-j$(nproc)" --env PACKAGER="$PACKAGER" \ - --env PKGDEST="$BUILDIR" --env DIST="$dist" \ - "$BASEIMAGE$img" - fi - - docker exec -i "$img" \ - makepkg -sfC --noconfirm --noprogressbar - mv "$VOLUME/$PKGNAME"-*.pkg.* . -} - -build_in_docker_dpkg() { - local dist="$1" - local img="$IMAGEPREFIX$dist" - - if _exist "$img"; then - if ! _is_running "$img"; then - _start "$img" - fi - else - docker build -t "$BASEIMAGE$img" "dists/build/$dist" - docker run -tid --name "$img" --volume "$VOLUME:$BUILDIR" \ - --env DEBIAN_FRONTEND=noninteractive --env DIST="$dist" \ - "$BASEIMAGE$img" - fi - - docker exec --workdir="$BUILDIR/$PKGNAME" "$img" \ - dch --newversion="$VERSION" --urgency=medium --distribution=stable --controlmaint "Release $VERSION" - docker exec --workdir="$BUILDIR/$PKGNAME" "$img" \ - dpkg-buildpackage -b -d --no-sign - mv "$VOLUME/${PKGNAME}_${VERSION}"_*.* . -} - -main() { - case "$COMMAND" in - archlinux) - build_in_docker_makepkg "$COMMAND" - ;; - - debian | ubuntu | whonix) - sync - build_in_docker_dpkg "$COMMAND" - ;; - - *) ;; - esac -} - -main "$@"