Skip to content

Commit

Permalink
Build packages for Debian
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Sep 4, 2023
1 parent 8a94220 commit 2a46fdd
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 2 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: Build and Release

jobs:
build-releases:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- name: Checkout code
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion PACKAGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sonic (0.0.0-1) UNRELEASED; urgency=medium

* Initial release.

-- Valerian Saliou <[email protected]> Tue, 31 Aug 2023 12:00:00 +0000
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
13 changes: 13 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Source: sonic
Section: net
Priority: ext
Maintainer: Valerian Saliou <[email protected]>
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.
13 changes: 13 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: sonic
Upstream-Contact: Valerian Saliou <[email protected]>
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/.
31 changes: 31 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions debian/sonic.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sonic/sonic usr/bin/
sonic/sonic.cfg etc/
sonic/store/ var/lib/sonic/
15 changes: 15 additions & 0 deletions debian/sonic.postinst
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions debian/sonic.service
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (quilt)
56 changes: 56 additions & 0 deletions scripts/build_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

##
# Sonic
#
# Fast, lightweight and schema-less search backend
# Copyright: 2023, Valerian Saliou <[email protected]>
# 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

0 comments on commit 2a46fdd

Please sign in to comment.