From 2cdabfc43eafe9cb8191e08c017b392fb6648f71 Mon Sep 17 00:00:00 2001 From: Sayan Date: Fri, 21 Jan 2022 13:49:05 +0000 Subject: [PATCH] Automatically package Debian packages on release (#235) * Add debian package generation * Install cargo-deb on `make deb` * Reload systemd daemon on postinst * Add auto upload for Debian packages * Consider using runner.os for simplicity --- .github/workflows/release.yml | 58 ++++++++++++++++++++++++++++++----- .gitignore | 4 ++- Makefile | 6 ++++ pkg/README | 1 + pkg/common/skyd.service | 15 +++++++++ pkg/debian/description.txt | 5 +++ pkg/debian/postinst | 15 +++++++++ pkg/debian/preinst | 20 ++++++++++++ server/Cargo.toml | 33 ++++++++++++++++++++ 9 files changed, 148 insertions(+), 9 deletions(-) create mode 100644 pkg/README create mode 100644 pkg/common/skyd.service create mode 100644 pkg/debian/description.txt create mode 100644 pkg/debian/postinst create mode 100755 pkg/debian/preinst diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 260e9605..fbc2351c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -72,12 +72,25 @@ jobs: TARGET: ${{ matrix.rust }} ARTIFACT: ${{ matrix.artifact }} VERSION: ${{ steps.get_version.outputs.VERSION }} - - name: Upload assets + + - name: Build Linux packages + run: | + make deb + mv *.deb skytable-${{ steps.get_version.outputs.VERSION }}-${{ matrix.artifact }}.deb + if: runner.os == 'Linux' + + - name: Upload assets (bundles) uses: actions/upload-artifact@v2 with: name: sky-bundle-${{ steps.get_version.outputs.VERSION }}-${{ matrix.artifact }}.zip path: sky-bundle-${{ steps.get_version.outputs.VERSION }}-${{ matrix.artifact }}.zip + - name: Upload assets (Linux packages) + uses: actions/upload-artifact@v2 + with: + name: skytable-${{ steps.get_version.outputs.VERSION }}-${{ matrix.artifact }}.deb + if: runner.os == 'Linux' + build_32bit: name: Build artifacts (32-bit) runs-on: ${{ matrix.os }} @@ -142,12 +155,25 @@ jobs: TARGET: ${{ matrix.rust }} ARTIFACT: ${{ matrix.artifact }} VERSION: ${{ steps.get_version.outputs.VERSION }} - - name: Upload assets + + - name: Build Linux packages + run: | + make deb + mv *.deb skytable-${{ steps.get_version.outputs.VERSION }}-${{ matrix.artifact }}.deb + if: runner.os == 'Linux' + + - name: Upload assets (binaries) uses: actions/upload-artifact@v2 with: name: sky-bundle-${{ steps.get_version.outputs.VERSION }}-${{ matrix.artifact }}.zip path: sky-bundle-${{ steps.get_version.outputs.VERSION }}-${{ matrix.artifact }}.zip + - name: Upload assets (Linux packages) + uses: actions/upload-artifact@v2 + with: + name: skytable-${{ steps.get_version.outputs.VERSION }}-${{ matrix.artifact }}.deb + if: runner.os == 'Linux' + build_musl: name: Build Linux x86_64-musl (Tier 2) runs-on: ubuntu-latest @@ -191,8 +217,11 @@ jobs: - name: Install Rust run: rustup target add x86_64-unknown-linux-musl - - name: Make bundle - run: make bundle + - name: Make bundle and packages + run: | + make bundle + make deb + mv *.deb skytable-${{ steps.get_version.outputs.VERSION }}-x86_64-linux-musl.deb env: RUST_BACKTRACE: 1 TARGET: x86_64-unknown-linux-musl @@ -203,6 +232,12 @@ jobs: with: name: sky-bundle-${{ steps.get_version.outputs.VERSION }}-x86_64-linux-musl.zip path: sky-bundle-${{ steps.get_version.outputs.VERSION }}-x86_64-linux-musl.zip + + - name: Upload assets (Linux packages) + uses: actions/upload-artifact@v2 + with: + name: skytable-${{ steps.get_version.outputs.VERSION }}-x86_64-linux-musl.deb + build-arm64: name: Build artifacts (self-hosted-arm64-native) runs-on: self-hosted @@ -227,15 +262,19 @@ jobs: run: | echo "using version tag ${GITHUB_REF:10}" echo ::set-output name=version::"${GITHUB_REF:10}" - - name: Make bundle + - name: Make bundle and packages env: TARGET: aarch64-unknown-linux-gnu VERSION: ${{ steps.get_version.outputs.VERSION }} ARTIFACT: aarch64-linux-gnu - run: make bundle - - name: Upload bundle + run: | + make bundle + make deb + mv *.deb skytable-${{ steps.get_version.outputs.VERSION }}-aarch64-linux-gnu.deb + - name: Upload bundle and packages run: | aws --endpoint-url ${{ secrets.STORAGE_ACCESS_URL }} s3 cp sky-bundle-${{ steps.get_version.outputs.VERSION }}-aarch64-linux-gnu.zip s3://releases/${{ steps.get_version.outputs.VERSION }}/ + aws --endpoint-url ${{ secrets.STORAGE_ACCESS_URL }} s3 cp skytable-${{ steps.get_version.outputs.VERSION }}-aarch64-linux-gnu.deb s3://releases/${{ steps.get_version.outputs.VERSION }}/ release: name: Release @@ -260,9 +299,12 @@ jobs: - name: Download ARM64 bundle run: | wget https://releases.skytable.io/release/${{ steps.get_version.outputs.VERSION }}/sky-bundle-${{ steps.get_version.outputs.VERSION }}-aarch64-linux-gnu.zip + wget https://releases.skytable.io/release/${{ steps.get_version.outputs.VERSION }}/skytable-${{ steps.get_version.outputs.VERSION }}-aarch64-linux-gnu.deb working-directory: artifacts - name: Upload release binaries env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAG_NAME: ${{ steps.get_version.outputs.VERSION }} - run: hub release edit $(find . -type f -name "*.zip" -printf "-a %p ") -m "" "$TAG_NAME" + run: | + hub release edit $(find . -type f -name "*.zip" -printf "-a %p ") -m "" "$TAG_NAME" + hub release edit $(find . -type f -name "*.deb" -printf "-a %p ") -m "" "$TAG_NAME" diff --git a/.gitignore b/.gitignore index 93e26eac..7662b72e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ snapstore.partmap /.idea .DS_Store .sky_history -.sky_pid \ No newline at end of file +.sky_pid +.devcontainer +*.deb \ No newline at end of file diff --git a/Makefile b/Makefile index 5696215e..c2714a6e 100644 --- a/Makefile +++ b/Makefile @@ -101,6 +101,12 @@ endif @echo "Installing any additional dependencies" @echo "====================================================================" @$(ADDITIONAL_SOFTWARE) +deb: release + @echo "====================================================================" + @echo "Building Debian package (optimized)" + @echo "====================================================================" + @cargo $(TARGET_ARG) install cargo-deb + @cargo deb $(TARGET_ARG) --manifest-path=server/Cargo.toml --output . build: .pre @echo "====================================================================" @echo "Building all binaries in debug mode (unoptimized)" diff --git a/pkg/README b/pkg/README new file mode 100644 index 00000000..9ac264aa --- /dev/null +++ b/pkg/README @@ -0,0 +1 @@ +This directory contains files used for packaging Skytable for Linux distributions. \ No newline at end of file diff --git a/pkg/common/skyd.service b/pkg/common/skyd.service new file mode 100644 index 00000000..3990c09f --- /dev/null +++ b/pkg/common/skyd.service @@ -0,0 +1,15 @@ +[Unit] +Description=Skytable database server daemon +After=Network.target +StartLimitIntervalSec=0 + +[Service] +Type=simple +Restart=always +RestartSec=1 +User=skytable +ExecStart=/usr/bin/skyd --noart +WorkingDirectory=/var/lib/skytable + +[Install] +WantedBy=multi-user.target diff --git a/pkg/debian/description.txt b/pkg/debian/description.txt new file mode 100644 index 00000000..15a8dca7 --- /dev/null +++ b/pkg/debian/description.txt @@ -0,0 +1,5 @@ +Skytable is a free and open-source NoSQL database that aims +to provide flexibility in data modeling at scale. +The `skytable` package contains the database server (`skyd`), +an interactive command-line client (`skysh`), a benchmarking +tool (`sky-bench`) and a migration tool (`sky-migrate`). \ No newline at end of file diff --git a/pkg/debian/postinst b/pkg/debian/postinst new file mode 100644 index 00000000..15592134 --- /dev/null +++ b/pkg/debian/postinst @@ -0,0 +1,15 @@ +#!/bin/sh -e + +systemctl daemon-reload + +if [ $1 = "install" ]; then + systemctl enable skyd +fi + +if [ $1 = "upgrade" ]; then + systemctl stop skyd +fi + +systemctl start skyd + +#DEBHELPER# \ No newline at end of file diff --git a/pkg/debian/preinst b/pkg/debian/preinst new file mode 100755 index 00000000..158b1666 --- /dev/null +++ b/pkg/debian/preinst @@ -0,0 +1,20 @@ +#!/bin/sh -e + +SKY_DIR=/var/lib/skytable + +# create the data directory +if [ ! -e $SKY_DIR ]; then + mkdir $SKY_DIR +elif [ ! -d $SKY_DIR ]; then + echo "ERROR: /var/lib/skytable exists but it is not a directory" 1>&2 + return 1 +fi + +if [ $1 = "install" ]; then + # add the `skytable` user + adduser --system --group skytable + # change ownership + chown skytable:skytable /var/lib/skytable +fi + +#DEBHELPER# \ No newline at end of file diff --git a/server/Cargo.toml b/server/Cargo.toml index 763877a6..9bb8c7e2 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -55,3 +55,36 @@ libc = "0.2.112" [features] nightly = [] + +[package.metadata.deb] +name = "skytable" +maintainer = "Sayan Nandan " +copyright = "2020, Sayan Nandan " +license-file = ["../LICENSE", "0"] +maintainer-scripts = "../pkg/debian/" +extended-description-file = "pkg/debian/description.txt" +depends = "$auto" +section = "database" +priority = "optional" +assets = [ + [ + "target/release/skyd", + "usr/bin/", + "755", + ], + [ + "target/release/skysh", + "usr/bin/", + "755", + ], + [ + "target/release/sky-bench", + "usr/bin/", + "755", + ], + [ + "../pkg/common/skyd.service", + "/etc/systemd/system/skyd.service", + "644", + ], +]