diff --git a/scripts/_build_deb_in_container.bash b/scripts/_build_deb_in_container.bash new file mode 100644 index 0000000..c954e4b --- /dev/null +++ b/scripts/_build_deb_in_container.bash @@ -0,0 +1,49 @@ +#!/bin/bash +# +# This script is mean to be run inside a dedicated container, +# and not interatively. + +set -ex + +export DEBIAN_FRONTEND=noninteractive + +apt-get update +apt-get install -y build-essential fakeroot debhelper git +apt-get install -y python3-all python3-pip python3-venv +apt-get install -y ruby ruby-dev + +pip3 install virtualenv virtualenv-tools3 +virtualenv -p python3 /vdirsyncer/env/ + +gem install fpm + +# See https://github.com/jordansissel/fpm/issues/1106#issuecomment-461678970 +pip3 uninstall -y virtualenv +echo 'python3 -m venv "$@"' > /usr/local/bin/virtualenv +chmod +x /usr/local/bin/virtualenv + +cp -r /source/ /vdirsyncer/vdirsyncer/ +cd /vdirsyncer/vdirsyncer/ || exit 2 +mkdir /vdirsyncer/pkgs/ + +basename -- *.tar.gz .tar.gz | cut -d'-' -f2 | sed -e 's/\.dev/~/g' | tee version +# XXX: Do I really not want google support included? +(echo -n *.tar.gz; echo '[google]') | tee requirements.txt +fpm --verbose \ + --input-type virtualenv \ + --output-type deb \ + --name "vdirsyncer-latest" \ + --version "$(cat version)" \ + --prefix /opt/venvs/vdirsyncer-latest \ + --depends python3 \ + requirements.txt + +mv /vdirsyncer/vdirsyncer/*.deb /vdirsyncer/pkgs/ + +cd /vdirsyncer/pkgs/ +dpkg -i -- *.deb + +# Check that it works: +LC_ALL=C.UTF-8 LANG=C.UTF-8 /opt/venvs/vdirsyncer-latest/bin/vdirsyncer --version + +cp -- *.deb /source/ diff --git a/scripts/dpkg.Dockerfile b/scripts/dpkg.Dockerfile deleted file mode 100644 index 4238c18..0000000 --- a/scripts/dpkg.Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ -ARG distro -ARG distrover - -FROM $distro:$distrover - -RUN apt-get update -RUN apt-get install -y build-essential fakeroot debhelper git -RUN apt-get install -y python3-all python3-pip python3-venv -RUN apt-get install -y ruby ruby-dev - -RUN gem install fpm package_cloud - -RUN pip3 install virtualenv virtualenv-tools3 -RUN virtualenv -p python3 /vdirsyncer/env/ - -# See https://github.com/jordansissel/fpm/issues/1106#issuecomment-461678970 -RUN pip3 uninstall -y virtualenv -RUN echo 'python3 -m venv "$@"' > /usr/local/bin/virtualenv -RUN chmod +x /usr/local/bin/virtualenv - -COPY . /vdirsyncer/vdirsyncer/ -WORKDIR /vdirsyncer/vdirsyncer/ -RUN mkdir /vdirsyncer/pkgs/ - -RUN basename *.tar.gz .tar.gz | cut -d'-' -f2 | sed -e 's/\.dev/~/g' | tee version -RUN (echo -n *.tar.gz; echo '[google]') | tee requirements.txt -RUN fpm --verbose \ - --input-type virtualenv \ - --output-type deb \ - --name "vdirsyncer-latest" \ - --version "$(cat version)" \ - --prefix /opt/venvs/vdirsyncer-latest \ - --depends python3 \ - requirements.txt - -RUN mv /vdirsyncer/vdirsyncer/*.deb /vdirsyncer/pkgs/ - -WORKDIR /vdirsyncer/pkgs/ -RUN dpkg -i *.deb - -# Check that it works: -RUN LC_ALL=C.UTF-8 LANG=C.UTF-8 /opt/venvs/vdirsyncer-latest/bin/vdirsyncer --version diff --git a/scripts/release-deb.sh b/scripts/release-deb.sh index e2e7c12..7dca2dd 100644 --- a/scripts/release-deb.sh +++ b/scripts/release-deb.sh @@ -1,26 +1,54 @@ #!/bin/sh -set -xe +set -xeu + +SCRIPT_PATH=$(realpath "$0") +SCRIPT_DIR=$(dirname "$SCRIPT_PATH") DISTRO=$1 DISTROVER=$2 - -NAME="vdirsyncer-${DISTRO}-${DISTROVER}:latest" +CONTAINER_NAME="vdirsyncer-${DISTRO}-${DISTROVER}" CONTEXT="$(mktemp -d)" +DEST_DIR="$SCRIPT_DIR/../$DISTRO-$DISTROVER" + +cleanup() { + rm -rf "$CONTEXT" +} +trap cleanup EXIT + +# Prepare files. +cp scripts/_build_deb_in_container.bash "$CONTEXT" python setup.py sdist -d "$CONTEXT" -# Build the package in a container with the right distro version. -docker build \ - --build-arg distro=$DISTRO \ - --build-arg distrover=$DISTROVER \ - -t $NAME \ - -f scripts/dpkg.Dockerfile \ - "$CONTEXT" +podman run -it \ + --name "$CONTAINER_NAME" \ + --volume "$CONTEXT:/source" \ + "$DISTRO:$DISTROVER" \ + bash /source/_build_deb_in_container.bash -# Push the package to packagecloud. -# TODO: Use ~/.packagecloud for CI. -docker run -e PACKAGECLOUD_TOKEN=$PACKAGECLOUD_TOKEN $NAME \ - bash -xec "package_cloud push pimutils/vdirsyncer/$DISTRO/$DISTROVER *.deb" +# Keep around the package filename. +PACKAGE=$(ls "$CONTEXT"/*.deb) +PACKAGE=$(basename "$PACKAGE") -rm -rf "$CONTEXT" +# Save the build deb files. +mkdir -p "$DEST_DIR" +cp "$CONTEXT"/*.deb "$DEST_DIR" + +echo Build complete! 🤖 + +# Packagecloud uses some internal IDs for each distro. +# Extract the one for the distro we're publishing. +DISTRO_ID=$( + curl -s \ + https://"$PACKAGECLOUD_TOKEN":@packagecloud.io/api/v1/distributions.json | \ + jq '.deb | .[] | select(.index_name=="'"$DISTRO"'") | .versions | .[] | select(.index_name=="'"$DISTROVER"'") | .id' +) + +# Actually push the package. +curl \ + -F "package[distro_version_id]=$DISTRO_ID" \ + -F "package[package_file]=@$DEST_DIR/$PACKAGE" \ + https://"$PACKAGECLOUD_TOKEN":@packagecloud.io/api/v1/repos/pimutils/vdirsyncer/packages.json + +echo Done! ✨