From 2a46fdd67931ed25b3a9a07c23d6caaa1466a42b Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Mon, 4 Sep 2023 23:03:59 +0200 Subject: [PATCH] Build packages for Debian --- .github/workflows/build.yml | 20 ++++++++++++- PACKAGING.md | 2 +- README.md | 38 +++++++++++++++++++++++++ debian/changelog | 5 ++++ debian/compat | 1 + debian/control | 13 +++++++++ debian/copyright | 13 +++++++++ debian/rules | 31 ++++++++++++++++++++ debian/sonic.install | 3 ++ debian/sonic.postinst | 15 ++++++++++ debian/sonic.service | 14 ++++++++++ debian/source/format | 1 + scripts/build_packages.sh | 56 +++++++++++++++++++++++++++++++++++++ 13 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/rules create mode 100644 debian/sonic.install create mode 100644 debian/sonic.postinst create mode 100644 debian/sonic.service create mode 100644 debian/source/format create mode 100755 scripts/build_packages.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 72aec2d1..e4d29dff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ name: Build and Release jobs: build-releases: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout code @@ -56,6 +56,24 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + build-packages: + needs: build-releases + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build packages + run: ./scripts/build_packages.sh + + - name: Push packages to Packagecloud + uses: faucetsdn/action-packagecloud-upload-debian-packages@v1 + with: + path: ./packages + repo: ${{ secrets.PACKAGECLOUD_REPO }} + token: ${{ secrets.PACKAGECLOUD_TOKEN }} + build-docker: runs-on: ubuntu-latest diff --git a/PACKAGING.md b/PACKAGING.md index 50fb21ba..5cfc9581 100644 --- a/PACKAGING.md +++ b/PACKAGING.md @@ -9,7 +9,7 @@ We consider here the packaging flow of Sonic version `1.0.0` for Linux. 1. Bump version in `Cargo.toml` to `1.0.0` 2. Execute `cargo update` to bump `Cargo.lock` -2. **How to build Sonic, package it and release it on Crates, GitHub and Docker Hub (multiple architectures):** +2. **How to build Sonic, package it and release it on Crates, GitHub, Docker Hub and Packagecloud (multiple architectures):** 1. Tag the latest Git commit corresponding to the release with tag `v1.0.0`, and push the tag 2. Wait for all release jobs to complete on the [actions](https://github.com/valeriansaliou/sonic/actions) page on GitHub 3. Download all release archives, and sign them locally using: `./scripts/sign_binaries.sh --version=1.0.0` diff --git a/README.md b/README.md index 6ada982d..3dc7502a 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,44 @@ Sonic is built in Rust. To install it, either download a version from the [Sonic 👉 _Each release binary comes with an `.asc` signature file, which can be verified using [@valeriansaliou](https://github.com/valeriansaliou) GPG public key: [:key:valeriansaliou.gpg.pub.asc](https://valeriansaliou.name/files/keys/valeriansaliou.gpg.pub.asc)._ +**👉 Install from packages:** + +Sonic provides [pre-built packages](https://packagecloud.io/valeriansaliou/sonic) for Debian-based systems (Debian, Ubuntu, etc.). + +**Important: Sonic only provides 64 bits packages targeting Debian 12 for now (codename: `bookworm`). You might still be able to use them on other Debian versions, as well as Ubuntu (although they rely on a specific `glibc` version that might not be available on older or newer systems).** + +First, add the Sonic APT repository (eg. for Debian `bookworm`): + +```bash +echo "deb [signed-by=/usr/share/keyrings/valeriansaliou_sonic.gpg] https://packagecloud.io/valeriansaliou/sonic/debian/ bookworm main" > /etc/apt/sources.list.d/valeriansaliou_sonic.list +``` + +```bash +curl -fsSL https://packagecloud.io/valeriansaliou/sonic/gpgkey | gpg --dearmor -o /usr/share/keyrings/valeriansaliou_sonic.gpg +``` + +```bash +apt-get update +``` + +Then, install the Sonic package: + +```bash +apt-get install sonic +``` + +Then, edit the pre-filled Sonic configuration file: + +```bash +nano /etc/sonic.cfg +``` + +Finally, restart Sonic: + +``` +service sonic restart +``` + **👉 Install from source:** If you pulled the source code from Git, you can build it using `cargo`: diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 00000000..90e9ae50 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +sonic (0.0.0-1) UNRELEASED; urgency=medium + + * Initial release. + + -- Valerian Saliou Tue, 31 Aug 2023 12:00:00 +0000 diff --git a/debian/compat b/debian/compat new file mode 100644 index 00000000..f599e28b --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +10 diff --git a/debian/control b/debian/control new file mode 100644 index 00000000..d668697b --- /dev/null +++ b/debian/control @@ -0,0 +1,13 @@ +Source: sonic +Section: net +Priority: ext +Maintainer: Valerian Saliou +Standards-Version: 3.9.4 +Build-Depends: wget, ca-certificates +Homepage: https://github.com/valeriansaliou/sonic + +Package: sonic +Architecture: any +Depends: adduser +Provides: sonic +Description: Fast, lightweight & schema-less search backend. An alternative to Elasticsearch that runs on a few MBs of RAM. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 00000000..81f7c8e4 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,13 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: sonic +Upstream-Contact: Valerian Saliou +Source: https://github.com/valeriansaliou/sonic + +Files: * +Copyright: 2023 Valerian Saliou +License: MPL-2 + +License: MPL-2 + This Source Code Form is subject to the terms of the Mozilla Public License, + v. 2.0. If a copy of the MPL was not distributed with this file, + You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/debian/rules b/debian/rules new file mode 100644 index 00000000..bebfa4c2 --- /dev/null +++ b/debian/rules @@ -0,0 +1,31 @@ +#!/usr/bin/make -f + +DISTRIBUTION = $(shell lsb_release -sr) +VERSION = 1.4.2 +PACKAGEVERSION = $(VERSION)-0~$(DISTRIBUTION)0 +URL = https://github.com/valeriansaliou/sonic/releases/download/v$(VERSION)/ + +%: + dh $@ --with systemd + +override_dh_auto_clean: +override_dh_auto_test: +override_dh_auto_build: +override_dh_auto_install: + $(eval ENV_ARCH := $(shell dpkg --print-architecture)) + $(eval ENV_ISA := $(shell if [ "$(ENV_ARCH)" = "amd64" ]; then echo "x86_64"; else echo "$(ENV_ARCH)"; fi)) + $(eval ENV_TARBALL := v$(VERSION)-$(ENV_ISA)-gnu.tar.gz) + + echo "Architecture: $(ENV_ARCH)" + echo "Instruction Set: $(ENV_ISA)" + echo "Target: $(URL)$(ENV_TARBALL)" + + wget -N --progress=dot:mega $(URL)$(ENV_TARBALL) + tar -xf $(ENV_TARBALL) + strip sonic/sonic + mv sonic/config.cfg sonic/sonic.cfg + mkdir sonic/store/ + sed -i 's/path = ".\/data\/store\//path = "\/var\/lib\/sonic\/store\//g' sonic/sonic.cfg + +override_dh_gencontrol: + dh_gencontrol -- -v$(PACKAGEVERSION) diff --git a/debian/sonic.install b/debian/sonic.install new file mode 100644 index 00000000..f590fc22 --- /dev/null +++ b/debian/sonic.install @@ -0,0 +1,3 @@ +sonic/sonic usr/bin/ +sonic/sonic.cfg etc/ +sonic/store/ var/lib/sonic/ diff --git a/debian/sonic.postinst b/debian/sonic.postinst new file mode 100644 index 00000000..370fa8bb --- /dev/null +++ b/debian/sonic.postinst @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +case "$1" in + configure) + adduser --system --disabled-password --disabled-login --home /var/empty \ + --no-create-home --quiet --group sonic && \ + chown sonic:sonic -R /var/lib/sonic/ + ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/debian/sonic.service b/debian/sonic.service new file mode 100644 index 00000000..4ac114f9 --- /dev/null +++ b/debian/sonic.service @@ -0,0 +1,14 @@ +[Unit] +Description=Sonic Search Index +After=network.target + +[Service] +Type=simple +User=sonic +Group=sonic +ExecStart=/usr/bin/sonic -c /etc/sonic.cfg +Restart=on-failure +LimitNOFILE=infinity + +[Install] +WantedBy=multi-user.target diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 00000000..163aaf8d --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/scripts/build_packages.sh b/scripts/build_packages.sh new file mode 100755 index 00000000..7c608c43 --- /dev/null +++ b/scripts/build_packages.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +## +# Sonic +# +# Fast, lightweight and schema-less search backend +# Copyright: 2023, Valerian Saliou +# License: Mozilla Public License v2.0 (MPL v2.0) +## + +# Define build pipeline +function build_for_target { + OS="$2" DIST="$3" ARCH="$1" ./packpack/packpack + release_result=$? + + if [ $release_result -eq 0 ]; then + mkdir -p "./packages/$2_$3/" + mv ./build/*$4 "./packages/$2_$3/" + + echo "Result: Packaged architecture: $1 for OS: $2:$3 (*$4)" + fi + + return $release_result +} + +# Run release tasks +ABSPATH=$(cd "$(dirname "$0")"; pwd) +BASE_DIR="$ABSPATH/../" + +rc=0 + +pushd "$BASE_DIR" > /dev/null + echo "Executing packages build steps for Sonic..." + + # Initialize `packpack` + rm -rf ./packpack && \ + git clone https://github.com/packpack/packpack.git packpack + rc=$? + + # Proceed build for each target? + if [ $rc -eq 0 ]; then + build_for_target "x86_64" "debian" "bookworm" ".deb" + rc=$? + fi + + # Cleanup environment + rm -rf ./build ./packpack + + if [ $rc -eq 0 ]; then + echo "Success: Done executing packages build steps for Sonic" + else + echo "Error: Failed executing packages build steps for Sonic" + fi +popd > /dev/null + +exit $rc