fix: dput dependency and proper configuration

This commit is contained in:
Roberto Mier Escandon 2021-12-21 13:51:15 +01:00
parent 434fe7c372
commit f6d0c60a21

View File

@ -1,4 +1,4 @@
#!/bin/bash -eu #!/bin/bash -eux
# #
# Copyright (C) 2021 Roberto Mier Escandón <rmescandon@gmail.com> # Copyright (C) 2021 Roberto Mier Escandón <rmescandon@gmail.com>
# #
@ -11,7 +11,8 @@ OUTPUT=
GOVERSION="1.17.4" GOVERSION="1.17.4"
KEYID= KEYID=
MAINTAINER= MAINTAINER=
PPA= DO_PUBLISH=
PPA="rmescandon/yq"
VERSION= VERSION=
DISTRIBUTION= DISTRIBUTION=
DO_SIGN= DO_SIGN=
@ -34,8 +35,9 @@ show_help() {
echo " -m, --maintainer WHO The maintainer used as author of the changelog. git.name and git.email (see git config) is" echo " -m, --maintainer WHO The maintainer used as author of the changelog. git.name and git.email (see git config) is"
echo " the considered format" echo " the considered format"
echo " -o DIR, --output DIR The path where leaving the generated debian package. Default to a temporary folder if not set" echo " -o DIR, --output DIR The path where leaving the generated debian package. Default to a temporary folder if not set"
echo " -p, --push PPA Push resultant files to indicated ppa. This option should be given along with a signing key." echo " -p The resultant file is being published to ppa"
echo " Otherwise, the server could reject the package building" echo " --ppa PPA Push resultant files to indicated ppa. This option should be given along with a signing key."
echo " Otherwise, the server could reject the package building. Default is set to 'rmescandon/yq'"
echo " --passphrase PASSPHRASE Passphrase to decrypt the signage key" echo " --passphrase PASSPHRASE Passphrase to decrypt the signage key"
exit 1 exit 1
} }
@ -69,8 +71,12 @@ while [ $# -ne 0 ]; do
shift shift
OUTPUT="$1" OUTPUT="$1"
;; ;;
-p|--push) -p)
DO_PUBLISH="y"
;;
--ppa)
shift shift
DO_PUBLISH="y"
PPA="$1" PPA="$1"
;; ;;
--passphrase) --passphrase)
@ -97,17 +103,30 @@ else
OUTPUT="$(mktemp -d)" OUTPUT="$(mktemp -d)"
fi fi
# Create temporary folder with all the artifacts to create and deploy the docker image # Define the folders with the source project and the build artifacts and files
srcdir="$(realpath "$(dirname "$0")"/..)" srcdir="$(realpath "$(dirname "$0")"/..)"
blddir="$(cd "${srcdir}" && mkdir -p build && cd build && echo "$(pwd)")" blddir="$(cd "${srcdir}" && mkdir -p build && cd build && echo "$(pwd)")"
# clean on exit
cleanup() { cleanup() {
rm -f "${blddir}/build.sh" || true rm -f "${blddir}/build.sh" || true
rm -f "${blddir}/Dockerfile" || true rm -f "${blddir}/Dockerfile" || true
rm -f "${blddir}/dput.cf" || true
docker rmi "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" -f > /dev/null 2>&1 || true docker rmi "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" -f > /dev/null 2>&1 || true
} }
trap cleanup EXIT INT trap cleanup EXIT INT
# configure the dput config in case publishing is requested
lp_id="$(echo "$PPA" | cut -d'/' -f1)"
ppa_id="$(echo "$PPA" | cut -d'/' -f2)"
cat << EOF > ${blddir}/dput.cf
[ppa]
fqdn = ppa.launchpad.net
method = ftp
incoming = ~${lp_id}/ubuntu/${ppa_id}
login = anonymous
EOF
# create the main script
cat << EOF > ${blddir}/build.sh cat << EOF > ${blddir}/build.sh
#!/bin/bash #!/bin/bash
set -e -o pipefail set -e -o pipefail
@ -170,12 +189,13 @@ echo ""
echo -e "\tfind resulting package at: "$OUTPUT"" echo -e "\tfind resulting package at: "$OUTPUT""
# publish to ppa whether given # publish to ppa whether given
if [ -n "$PPA" ]; then if [ -n "$DO_PUBLISH" ]; then
dput ppa:"$PPA" "$OUTPUT"/yq_*.changes dput -c /etc/dput.cf ppa /home/yq/output/yq_*.changes
fi fi
EOF EOF
chmod +x "${blddir}"/build.sh chmod +x "${blddir}"/build.sh
# build the docker image with all dependencies
cat << EOF > ${blddir}/Dockerfile cat << EOF > ${blddir}/Dockerfile
FROM bitnami/minideb:bullseye as base FROM bitnami/minideb:bullseye as base
ENV LANG C.UTF-8 ENV LANG C.UTF-8
@ -201,6 +221,7 @@ RUN apt-get -qq -y --no-install-recommends install \
build-essential \ build-essential \
debhelper \ debhelper \
devscripts \ devscripts \
dput \
fakeroot \ fakeroot \
git-buildpackage \ git-buildpackage \
gpg-agent \ gpg-agent \
@ -218,6 +239,7 @@ RUN useradd -ms /bin/bash yq && \
mkdir /home/yq/src && chown -R yq: /home/yq/src && \ mkdir /home/yq/src && chown -R yq: /home/yq/src && \
mkdir /home/yq/output && chown -R yq: /home/yq/output mkdir /home/yq/output && chown -R yq: /home/yq/output
ADD ./build/dput.cf /etc/dput.cf
ADD ./build/build.sh /usr/bin/build.sh ADD ./build/build.sh /usr/bin/build.sh
RUN chmod +x /usr/bin/build.sh && chown -R yq: /usr/bin/build.sh RUN chmod +x /usr/bin/build.sh && chown -R yq: /usr/bin/build.sh