Skip to content

Commit 2a46fdd

Browse files
Build packages for Debian
1 parent 8a94220 commit 2a46fdd

13 files changed

+210
-2
lines changed

.github/workflows/build.yml

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name: Build and Release
77

88
jobs:
99
build-releases:
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-22.04
1111

1212
steps:
1313
- name: Checkout code
@@ -56,6 +56,24 @@ jobs:
5656
env:
5757
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5858

59+
build-packages:
60+
needs: build-releases
61+
runs-on: ubuntu-latest
62+
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v2
66+
67+
- name: Build packages
68+
run: ./scripts/build_packages.sh
69+
70+
- name: Push packages to Packagecloud
71+
uses: faucetsdn/action-packagecloud-upload-debian-packages@v1
72+
with:
73+
path: ./packages
74+
repo: ${{ secrets.PACKAGECLOUD_REPO }}
75+
token: ${{ secrets.PACKAGECLOUD_TOKEN }}
76+
5977
build-docker:
6078
runs-on: ubuntu-latest
6179

PACKAGING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We consider here the packaging flow of Sonic version `1.0.0` for Linux.
99
1. Bump version in `Cargo.toml` to `1.0.0`
1010
2. Execute `cargo update` to bump `Cargo.lock`
1111

12-
2. **How to build Sonic, package it and release it on Crates, GitHub and Docker Hub (multiple architectures):**
12+
2. **How to build Sonic, package it and release it on Crates, GitHub, Docker Hub and Packagecloud (multiple architectures):**
1313
1. Tag the latest Git commit corresponding to the release with tag `v1.0.0`, and push the tag
1414
2. Wait for all release jobs to complete on the [actions](https://github.com/valeriansaliou/sonic/actions) page on GitHub
1515
3. Download all release archives, and sign them locally using: `./scripts/sign_binaries.sh --version=1.0.0`

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,44 @@ Sonic is built in Rust. To install it, either download a version from the [Sonic
6363

6464
👉 _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)._
6565

66+
**👉 Install from packages:**
67+
68+
Sonic provides [pre-built packages](https://packagecloud.io/valeriansaliou/sonic) for Debian-based systems (Debian, Ubuntu, etc.).
69+
70+
**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).**
71+
72+
First, add the Sonic APT repository (eg. for Debian `bookworm`):
73+
74+
```bash
75+
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
76+
```
77+
78+
```bash
79+
curl -fsSL https://packagecloud.io/valeriansaliou/sonic/gpgkey | gpg --dearmor -o /usr/share/keyrings/valeriansaliou_sonic.gpg
80+
```
81+
82+
```bash
83+
apt-get update
84+
```
85+
86+
Then, install the Sonic package:
87+
88+
```bash
89+
apt-get install sonic
90+
```
91+
92+
Then, edit the pre-filled Sonic configuration file:
93+
94+
```bash
95+
nano /etc/sonic.cfg
96+
```
97+
98+
Finally, restart Sonic:
99+
100+
```
101+
service sonic restart
102+
```
103+
66104
**👉 Install from source:**
67105

68106
If you pulled the source code from Git, you can build it using `cargo`:

debian/changelog

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sonic (0.0.0-1) UNRELEASED; urgency=medium
2+
3+
* Initial release.
4+
5+
-- Valerian Saliou <valerian@valeriansaliou.name> Tue, 31 Aug 2023 12:00:00 +0000

debian/compat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10

debian/control

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Source: sonic
2+
Section: net
3+
Priority: ext
4+
Maintainer: Valerian Saliou <valerian@valeriansaliou.name>
5+
Standards-Version: 3.9.4
6+
Build-Depends: wget, ca-certificates
7+
Homepage: https://github.com/valeriansaliou/sonic
8+
9+
Package: sonic
10+
Architecture: any
11+
Depends: adduser
12+
Provides: sonic
13+
Description: Fast, lightweight & schema-less search backend. An alternative to Elasticsearch that runs on a few MBs of RAM.

debian/copyright

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: sonic
3+
Upstream-Contact: Valerian Saliou <valerian@valeriansaliou.name>
4+
Source: https://github.com/valeriansaliou/sonic
5+
6+
Files: *
7+
Copyright: 2023 Valerian Saliou
8+
License: MPL-2
9+
10+
License: MPL-2
11+
This Source Code Form is subject to the terms of the Mozilla Public License,
12+
v. 2.0. If a copy of the MPL was not distributed with this file,
13+
You can obtain one at http://mozilla.org/MPL/2.0/.

debian/rules

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/make -f
2+
3+
DISTRIBUTION = $(shell lsb_release -sr)
4+
VERSION = 1.4.2
5+
PACKAGEVERSION = $(VERSION)-0~$(DISTRIBUTION)0
6+
URL = https://github.com/valeriansaliou/sonic/releases/download/v$(VERSION)/
7+
8+
%:
9+
dh $@ --with systemd
10+
11+
override_dh_auto_clean:
12+
override_dh_auto_test:
13+
override_dh_auto_build:
14+
override_dh_auto_install:
15+
$(eval ENV_ARCH := $(shell dpkg --print-architecture))
16+
$(eval ENV_ISA := $(shell if [ "$(ENV_ARCH)" = "amd64" ]; then echo "x86_64"; else echo "$(ENV_ARCH)"; fi))
17+
$(eval ENV_TARBALL := v$(VERSION)-$(ENV_ISA)-gnu.tar.gz)
18+
19+
echo "Architecture: $(ENV_ARCH)"
20+
echo "Instruction Set: $(ENV_ISA)"
21+
echo "Target: $(URL)$(ENV_TARBALL)"
22+
23+
wget -N --progress=dot:mega $(URL)$(ENV_TARBALL)
24+
tar -xf $(ENV_TARBALL)
25+
strip sonic/sonic
26+
mv sonic/config.cfg sonic/sonic.cfg
27+
mkdir sonic/store/
28+
sed -i 's/path = ".\/data\/store\//path = "\/var\/lib\/sonic\/store\//g' sonic/sonic.cfg
29+
30+
override_dh_gencontrol:
31+
dh_gencontrol -- -v$(PACKAGEVERSION)

debian/sonic.install

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sonic/sonic usr/bin/
2+
sonic/sonic.cfg etc/
3+
sonic/store/ var/lib/sonic/

debian/sonic.postinst

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
case "$1" in
6+
configure)
7+
adduser --system --disabled-password --disabled-login --home /var/empty \
8+
--no-create-home --quiet --group sonic && \
9+
chown sonic:sonic -R /var/lib/sonic/
10+
;;
11+
esac
12+
13+
#DEBHELPER#
14+
15+
exit 0

debian/sonic.service

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Sonic Search Index
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
User=sonic
8+
Group=sonic
9+
ExecStart=/usr/bin/sonic -c /etc/sonic.cfg
10+
Restart=on-failure
11+
LimitNOFILE=infinity
12+
13+
[Install]
14+
WantedBy=multi-user.target

debian/source/format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0 (quilt)

scripts/build_packages.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
##
4+
# Sonic
5+
#
6+
# Fast, lightweight and schema-less search backend
7+
# Copyright: 2023, Valerian Saliou <valerian@valeriansaliou.name>
8+
# License: Mozilla Public License v2.0 (MPL v2.0)
9+
##
10+
11+
# Define build pipeline
12+
function build_for_target {
13+
OS="$2" DIST="$3" ARCH="$1" ./packpack/packpack
14+
release_result=$?
15+
16+
if [ $release_result -eq 0 ]; then
17+
mkdir -p "./packages/$2_$3/"
18+
mv ./build/*$4 "./packages/$2_$3/"
19+
20+
echo "Result: Packaged architecture: $1 for OS: $2:$3 (*$4)"
21+
fi
22+
23+
return $release_result
24+
}
25+
26+
# Run release tasks
27+
ABSPATH=$(cd "$(dirname "$0")"; pwd)
28+
BASE_DIR="$ABSPATH/../"
29+
30+
rc=0
31+
32+
pushd "$BASE_DIR" > /dev/null
33+
echo "Executing packages build steps for Sonic..."
34+
35+
# Initialize `packpack`
36+
rm -rf ./packpack && \
37+
git clone https://github.com/packpack/packpack.git packpack
38+
rc=$?
39+
40+
# Proceed build for each target?
41+
if [ $rc -eq 0 ]; then
42+
build_for_target "x86_64" "debian" "bookworm" ".deb"
43+
rc=$?
44+
fi
45+
46+
# Cleanup environment
47+
rm -rf ./build ./packpack
48+
49+
if [ $rc -eq 0 ]; then
50+
echo "Success: Done executing packages build steps for Sonic"
51+
else
52+
echo "Error: Failed executing packages build steps for Sonic"
53+
fi
54+
popd > /dev/null
55+
56+
exit $rc

0 commit comments

Comments
 (0)