From bf37e6223e917b65626dc3a5e51c163300c1d88e Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sat, 30 Apr 2022 22:59:19 +0200 Subject: [PATCH] Add debian publishing Use brenard/debian-python-deb docker image to speedup pipeline --- .woodpecker.yml | 39 ++++++++++++++++++++++++++++++--------- build.sh | 37 +++++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 051a02f..22625e8 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -5,11 +5,11 @@ clone: pipeline: test: - image: debian + image: brenard/debian-python-deb commands: - DEBIAN_FRONTEND=noninteractive apt-get -qq update < /dev/null > /dev/null - DEBIAN_FRONTEND=noninteractive apt-get -y -qq upgrade < /dev/null > /dev/null - - DEBIAN_FRONTEND=noninteractive apt-get -qq -y install --no-install-recommends python3-all python3-dev python3-pip python3-venv build-essential pkg-config libsystemd-dev libldap2-dev libsasl2-dev libpq-dev libmariadb-dev wget unzip < /dev/null > /dev/null + - DEBIAN_FRONTEND=noninteractive apt-get -qq -y install --no-install-recommends pkg-config libsystemd-dev libldap2-dev libsasl2-dev libpq-dev libmariadb-dev wget unzip < /dev/null > /dev/null - wget --no-verbose -O /opt/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip - unzip -qq -d /opt /opt/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip - echo /opt/instantclient_* > /etc/ld.so.conf.d/oracle-instantclient.conf @@ -17,25 +17,26 @@ pipeline: - ./tests.sh --quiet build: - image: debian + image: brenard/debian-python-deb when: event: tag commands: - - DEBIAN_FRONTEND=noninteractive apt-get -qq update < /dev/null > /dev/null - - DEBIAN_FRONTEND=noninteractive apt-get -y -qq upgrade < /dev/null > /dev/null - - DEBIAN_FRONTEND=noninteractive apt-get -qq -y install --no-install-recommends git sed python3-all python3-dev python3-pip python3-venv dpkg-dev build-essential debhelper dh-python bash-completion lsb-release < /dev/null > /dev/null + - echo "$GPG_KEY"|base64 -d|gpg --import - ./build.sh --quiet - rm -fr deb_dist/mylib-* + secrets: [ maintainer_name, maintainer_email, gpg_key, debian_codename ] publish-dryrun: - image: debian + group: publish + image: alpine when: event: tag commands: - ls dist/* - - ls deb_dist/* + - ls deb_dist/*.deb - publish: + publish-gitea: + group: publish image: plugins/gitea-release when: event: tag @@ -49,3 +50,23 @@ pipeline: checksum: - md5 - sha512 + + publish-apt: + group: publish + image: brenard/curl + when: + event: tag + commands: + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/python3-mylib_*_all.deb ) $APT_API_URL/files/python3-mylib + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/mylib_*.dsc ) $APT_API_URL/files/python3-mylib + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/mylib_*.orig.tar.gz ) $APT_API_URL/files/python3-mylib + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/mylib_*.debian.tar.xz ) $APT_API_URL/files/python3-mylib + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/mylib_*.buildinfo ) $APT_API_URL/files/python3-mylib + - curl -u $APT_CREDS -X POST -F file=@$( ls dist/mylib_*.changes ) $APT_API_URL/files/python3-mylib + - curl -u $APT_CREDS -X POST $APT_API_URL/repos/$APT_REPO_NAME/include/python3-mylib + - APT_SNAP_NAME=$(date +%s)_$APT_REPO_NAME + - > + curl -u $APT_CREDS -X POST -H 'Content-Type: application/json' --data "{\"Name\":\"$APT_SNAP_NAME\"}" $APT_API_URL/repos/$APT_REPO_NAME/snapshots + - > + curl -u $APT_CREDS -X PUT -H 'Content-Type: application/json' --data "{\"Snapshots\": [{\"Component\": \"main\", \"Name\": \"$APT_SNAP_NAME\"}]}" $APT_API_URL/publish/:./$APT_REPO_NAME + secrets: [ apt_api_url, apt_creds, apt_repo_name ] diff --git a/build.sh b/build.sh index 2c8ead5..ff745b1 100755 --- a/build.sh +++ b/build.sh @@ -28,7 +28,7 @@ else fi echo "Install dependencies in virtualenv using pip..." -$VENV/bin/python3 -m pip install stdeb GitPython wheel $QUIET_ARG +$VENV/bin/python3 -m pip install stdeb wheel $QUIET_ARG echo "Build wheel package..." $VENV/bin/python3 setup.py bdist_wheel @@ -41,7 +41,9 @@ then TMP_GITDCH=$(mktemp -d) echo "Temporary install gitdch in $TMP_GITDCH..." git clone $QUIET_ARG https://gitea.zionetrix.net/bn8/gitdch.git $TMP_GITDCH/gitdch - GITDCH=$TMP_GITDCH/gitdch/gitdch + GITDCH="$VENV/bin/python3 $TMP_GITDCH/gitdch/gitdch" + echo "Install gitdch dependencies in $VENV..." + $VENV/bin/python3 -m pip install GitPython $QUIET_ARG else TMP_GITDCH="" echo "Use existing installation of gitdch ($GITDCH)" @@ -61,20 +63,35 @@ find deb_dist/ -maxdepth 1 -type f ! -name '*.orig.tar.gz' -delete echo "Enter in debian package directory..." cd deb_dist/mylib-$VERSION -echo "Retreive debian codename using lsb_release..." -DEBIAN_CODENAME=$( lsb_release -c -s ) -[ $( lsb_release -r -s ) -ge 9 ] && DEBIAN_CODENAME="${DEBIAN_CODENAME}-ee" +if [ -z "$DEBIAN_CODENAME" ] +then + echo "Retreive debian codename using lsb_release..." + DEBIAN_CODENAME=$( lsb_release -c -s ) + [ $( lsb_release -r -s ) -ge 9 ] && DEBIAN_CODENAME="${DEBIAN_CODENAME}-ee" +else + echo "Use debian codename from environment ($DEBIAN_CODENAME)" +fi echo "Generate debian changelog using gitdch..." -GITDCH_LOG_ARG='--verbose' -[ -n "$QUIET_ARG" ] && GITDCH_LOG_ARG='--warning' -$VENV/bin/python3 $GITDCH \ +GITDCH_ARGS='--verbose' +[ -n "$QUIET_ARG" ] && GITDCH_ARGS='--warning' +if [ -n "$MAINTAINER_NAME" ] +then + echo "Use maintainer name from environment ($MAINTAINER_NAME)" + GITDCH_ARGS="$GITDCH_ARGS --maintainer-name '$MAINTAINER_NAME'" +fi +if [ -n "$MAINTAINER_EMAIL" ] +then + echo "Use maintainer email from environment ($MAINTAINER_EMAIL)" + GITDCH_ARGS="$GITDCH_ARGS --maintainer-email '$MAINTAINER_EMAIL'" +fi +$GITDCH \ --package-name mylib \ --version "${VERSION}" \ --code-name $DEBIAN_CODENAME \ --output debian/changelog \ --path ../../ \ - $GITDCH_LOG_ARG + $GITDCH_ARGS echo "Add custom package name for dependencies..." cat << EOF > debian/py3dist-overrides @@ -86,4 +103,4 @@ EOF [ -n "$TMP_GITDCH" ] && echo "Clean temporary gitdch installation..." && rm -fr $TMP_GITDCH echo "Build debian package..." -dpkg-buildpackage --no-sign +dpkg-buildpackage