Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite packaging to use a single script in a docker container #416

Merged
merged 9 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 14 additions & 45 deletions .github/workflows/package-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
build-deb:
name: "${{ matrix.distro }}:${{ matrix.release }}"
runs-on: buildjet-16vcpu-ubuntu-2204${{ matrix.arch == 'arm64' && '-arm' || '' }}
container: "${{ matrix.distro }}:${{ matrix.release }}"
strategy:
matrix:
include:
Expand Down Expand Up @@ -73,59 +72,29 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: install buildsystem apt dependencies
run: |
apt-get update
apt-get install -y \
build-essential \
curl jq lsb-release unzip gpg

- name: install rust
run: |
curl -sSf https://sh.rustup.rs | sh /dev/stdin -y
echo "PATH=$HOME/.cargo/bin:$PATH" >> "$GITHUB_ENV"

- uses: Swatinem/rust-cache@v2
with:
shared-key: build-deb-${{ matrix.distro }}-${{ matrix.release }}-${{ matrix.arch }}

- name: check cargo
shell: bash
run: |
echo "::group::rustc -vV"
rustc -vV
echo "::endgroup::"
echo "::group::cargo -vV"
cargo -vV
echo "::endgroup::"

- name: set release env var
if: ${{ github.event_name == 'workflow_dispatch' }}
shell: bash
run: |
echo 'RELEASE=${{ github.event.inputs.release }}' >> $GITHUB_ENV

# Changelogs with revisions cause dpkg-source to emit an error when
# building. We only use the source package to install the build deps
# so building it with an invalid version is ok.
- name: build source package
run: dpkg-source --build .

- name: generate changelog

- name: set release env var
if: ${{ github.event_name != 'workflow_dispatch' }}
shell: bash
run: ./debian/gen-changelog.sh > debian/changelog

- name: install build dependencies
run: apt-get build-dep -y ../rezolus*.dsc
- name: build package
run: dpkg-buildpackage -b -us -uc
run: |
echo 'RELEASE=0' >> $GITHUB_ENV

- name: copy debs
shell: bash
- name: run packaging script
run: |
shopt -s nullglob
mkdir -p target/debian
cp ../*.deb ../*.ddeb target/debian/
docker run --rm \
-v $(pwd):/mnt/rezolus \
-v $(pwd)/target/debian:/mnt/output \
${{ matrix.distro }}:${{ matrix.release }} \
/mnt/rezolus/debian/package.sh \
--release "$RELEASE" \
--chown "$(id -u)" \
--verbose

- uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package-rpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: install build dependencies
shell: bash
run: |
yum install -y gcc elfutils-devel clang
yum install -y gcc elfutils-devel clang openssl-devel

- uses: Swatinem/rust-cache@v2
with:
Expand Down
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Standards-Version: 4.6.2
Build-Depends:
debhelper (>= 10),
pkg-config,
libssl-dev,
libelf-dev,
libelf-dev:native,
clang:native
Expand Down
149 changes: 149 additions & 0 deletions debian/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/bin/bash

set -euo pipefail

PROGRAM="$(basename "$0")"

VERBOSE=false

REZOLUS=/mnt/rezolus
OUTPUT=/mnt/output
RELEASE=0
CHOWN=

help() {
cat <<EOF
$PROGRAM - Build rezolus debian packages.

USAGE:
$PROGRAM <FLAGS>

OPTIONS:
-h|--help Show this help text.
-v|--verbose Display the commands run by this script.

--release The release number to use for the package. [default: $RELEASE]
--rezolus-dir The directory that the rezolus source is stored in. [default: $REZOLUS]
--output-dir The directory to place the output artifacts in. [default: $OUTPUT]
--chown Change the ownership of the resulting package files.

USE WITH DOCKER:
This script is intended to be run within a debian-based docker container.
As an example, consider building for ubuntu focal:

docker run -it --rm \\
-v \$(pwd):/mnt/rezolus \\
-v \$(pwd)/target/debian:/mnt/output \\
ubuntu:noble /mnt/rezolus/debian/package.sh --release 0 --chown \$(id -u) --verbose

You should be able to swap out the docker container in order to build for different
distros, provided that rezolus can be built on each distro. Note that you may have to
clean out the debian/cargo_home and debian/cargo_target directories when switching distros.
EOF
}

error() {
1>&2 echo "error: $1"
1>&2 echo "Try '$PROGRAM --help' for more information."
}

while [ $# -gt 0 ]; do
opt="$1"
shift

case "$opt" in
-h|--help)
help
exit 0
;;
-v|--verbose) VERBOSE=true ;;

--release) RELEASE="$1"; shift ;;
--rezolus-dir) REZOLUS="$1"; shift ;;
--output-dir) OUTPUT="$1"; shift ;;
--chown) CHOWN="$1"; shift ;;

*)
error "unexpected option '$opt'"
exit 1
;;
esac
done

pushgroup() {
(
set +x
if [ -n "${CI:-}" ]; then
echo "::group::$*"
fi
)
}

nextgroup() {
(
set +x
if [ -n "${CI:-}" ]; then
echo "::endgroup::"
echo "::group::$*"
fi
)
}

popgroup() {
(
set +x
if [ -n "${CI:-}" ]; then
echo "::endgroup::"
fi
)
}


if $VERBOSE; then
set -x
fi

if [ "$(id -u)" -ne 0 ]; then
error "package script must be run as root"
fi

shopt -s nullglob globstar

cd "$REZOLUS"

pushgroup install required dependencies

# Disable tzdata requests or other things that may require user interaction
export DEBIAN_FRONTEND=noninteractive

apt-get -q update
apt-get -q install -y build-essential curl jq lsb-release unzip gpg

nextgroup install rust
curl -sSf https://sh.rustup.rs | sh /dev/stdin -y
. "$HOME/.cargo/env"

nextgroup build source package
dpkg-source --build .

nextgroup generate changelog
export RELEASE="$RELEASE"
cp -p debian/changelog /tmp/changelog
trap 'cp -fp /tmp/changelog debian/changelog' EXIT
./debian/gen-changelog.sh | tee debian/changelog

nextgroup install build dependencies
apt-get -q build-dep -y ../rezolus*.dsc

nextgroup build the package
dpkg-buildpackage -b -us -uc

nextgroup change ownership of deb files
if [ -n "$CHOWN" ]; then
chown "$CHOWN" ../*.deb ../*.ddeb
fi

nextgroup copy deb files to the output directory
cp ../*.deb ../*.ddeb "$OUTPUT"

popgroup
Loading