Skip to content

Commit d725368

Browse files
author
Hugo Osvaldo Barrera
authored
Merge pull request pimutils#943 from pimutils/deb
Update script to publish deb packages
2 parents ac6e192 + 2c69f86 commit d725368

File tree

3 files changed

+92
-57
lines changed

3 files changed

+92
-57
lines changed

scripts/_build_deb_in_container.bash

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
#
3+
# This script is mean to be run inside a dedicated container,
4+
# and not interatively.
5+
6+
set -ex
7+
8+
export DEBIAN_FRONTEND=noninteractive
9+
10+
apt-get update
11+
apt-get install -y build-essential fakeroot debhelper git
12+
apt-get install -y python3-all python3-pip python3-venv
13+
apt-get install -y ruby ruby-dev
14+
15+
pip3 install virtualenv virtualenv-tools3
16+
virtualenv -p python3 /vdirsyncer/env/
17+
18+
gem install fpm
19+
20+
# See https://github.com/jordansissel/fpm/issues/1106#issuecomment-461678970
21+
pip3 uninstall -y virtualenv
22+
echo 'python3 -m venv "$@"' > /usr/local/bin/virtualenv
23+
chmod +x /usr/local/bin/virtualenv
24+
25+
cp -r /source/ /vdirsyncer/vdirsyncer/
26+
cd /vdirsyncer/vdirsyncer/ || exit 2
27+
mkdir /vdirsyncer/pkgs/
28+
29+
basename -- *.tar.gz .tar.gz | cut -d'-' -f2 | sed -e 's/\.dev/~/g' | tee version
30+
# XXX: Do I really not want google support included?
31+
(echo -n *.tar.gz; echo '[google]') | tee requirements.txt
32+
fpm --verbose \
33+
--input-type virtualenv \
34+
--output-type deb \
35+
--name "vdirsyncer-latest" \
36+
--version "$(cat version)" \
37+
--prefix /opt/venvs/vdirsyncer-latest \
38+
--depends python3 \
39+
requirements.txt
40+
41+
mv /vdirsyncer/vdirsyncer/*.deb /vdirsyncer/pkgs/
42+
43+
cd /vdirsyncer/pkgs/
44+
dpkg -i -- *.deb
45+
46+
# Check that it works:
47+
LC_ALL=C.UTF-8 LANG=C.UTF-8 /opt/venvs/vdirsyncer-latest/bin/vdirsyncer --version
48+
49+
cp -- *.deb /source/

scripts/dpkg.Dockerfile

Lines changed: 0 additions & 42 deletions
This file was deleted.

scripts/release-deb.sh

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
11
#!/bin/sh
22

3-
set -xe
3+
set -xeu
4+
5+
SCRIPT_PATH=$(realpath "$0")
6+
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
47

58
DISTRO=$1
69
DISTROVER=$2
7-
8-
NAME="vdirsyncer-${DISTRO}-${DISTROVER}:latest"
10+
CONTAINER_NAME="vdirsyncer-${DISTRO}-${DISTROVER}"
911
CONTEXT="$(mktemp -d)"
1012

13+
DEST_DIR="$SCRIPT_DIR/../$DISTRO-$DISTROVER"
14+
15+
cleanup() {
16+
rm -rf "$CONTEXT"
17+
}
18+
trap cleanup EXIT
19+
20+
# Prepare files.
21+
cp scripts/_build_deb_in_container.bash "$CONTEXT"
1122
python setup.py sdist -d "$CONTEXT"
1223

13-
# Build the package in a container with the right distro version.
14-
docker build \
15-
--build-arg distro=$DISTRO \
16-
--build-arg distrover=$DISTROVER \
17-
-t $NAME \
18-
-f scripts/dpkg.Dockerfile \
19-
"$CONTEXT"
24+
podman run -it \
25+
--name "$CONTAINER_NAME" \
26+
--volume "$CONTEXT:/source" \
27+
"$DISTRO:$DISTROVER" \
28+
bash /source/_build_deb_in_container.bash
29+
30+
# Keep around the package filename.
31+
PACKAGE=$(ls "$CONTEXT"/*.deb)
32+
PACKAGE=$(basename "$PACKAGE")
33+
34+
# Save the build deb files.
35+
mkdir -p "$DEST_DIR"
36+
cp "$CONTEXT"/*.deb "$DEST_DIR"
37+
38+
echo Build complete! 🤖
39+
40+
# Packagecloud uses some internal IDs for each distro.
41+
# Extract the one for the distro we're publishing.
42+
DISTRO_ID=$(
43+
curl -s \
44+
https://"$PACKAGECLOUD_TOKEN":@packagecloud.io/api/v1/distributions.json | \
45+
jq '.deb | .[] | select(.index_name=="'"$DISTRO"'") | .versions | .[] | select(.index_name=="'"$DISTROVER"'") | .id'
46+
)
2047

21-
# Push the package to packagecloud.
22-
# TODO: Use ~/.packagecloud for CI.
23-
docker run -e PACKAGECLOUD_TOKEN=$PACKAGECLOUD_TOKEN $NAME \
24-
bash -xec "package_cloud push pimutils/vdirsyncer/$DISTRO/$DISTROVER *.deb"
48+
# Actually push the package.
49+
curl \
50+
-F "package[distro_version_id]=$DISTRO_ID" \
51+
-F "package[package_file]=@$DEST_DIR/$PACKAGE" \
52+
https://"$PACKAGECLOUD_TOKEN":@packagecloud.io/api/v1/repos/pimutils/vdirsyncer/packages.json
2553

26-
rm -rf "$CONTEXT"
54+
echo Done!

0 commit comments

Comments
 (0)