diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml index e62a5d4..aa62c2a 100644 --- a/.github/workflows/release-artifacts.yml +++ b/.github/workflows/release-artifacts.yml @@ -6,7 +6,8 @@ on: - 'v*' jobs: - build: + build-deb: + name: 'Build Debian packages' runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -66,9 +67,40 @@ jobs: with: command: deb args: -p client + - name: Save DEBs + uses: actions/upload-artifact@v2 + with: + name: packaged-deb + path: target/debian/*.deb + + build-rpm: + name: 'Build RPM packages' + runs-on: ubuntu-latest + strategy: + matrix: + distros: ['fedora:32', 'fedora:33', 'centos:8'] + steps: + - uses: actions/checkout@v2 + - name: Build RPMs + run: rpm/build-package.sh ${{ matrix.distros }} + - name: Save RPMs + uses: actions/upload-artifact@v2 + with: + name: packaged-rpm + path: target/rpm/*.rpm + + release: + name: 'Release packages' + runs-on: ubuntu-latest + needs: [build-deb, build-rpm] + steps: + - name: Get artifacts + uses: actions/download-artifact@v2 - name: Release uses: softprops/action-gh-release@v1 with: - files: target/debian/*.deb + files: | + packaged-deb/*.deb + packaged-rpm/*.rpm env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1ad6ced..9aca196 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,6 +1,14 @@ name: Rust -on: [push, pull_request] +on: + push: + branches: + - '*' + tags-ignore: + - 'v*' + pull_request: + branches: + - '*' jobs: test: diff --git a/client/.rpm/innernet.spec b/client/.rpm/innernet.spec new file mode 100644 index 0000000..1a39dc7 --- /dev/null +++ b/client/.rpm/innernet.spec @@ -0,0 +1,40 @@ +%define __spec_install_post %{nil} +%define __os_install_post %{_dbpath}/brp-compress +%define debug_package %{nil} + +Name: innernet +Summary: A client to manage innernet network interfaces. +Version: @@VERSION@@ +Release: @@RELEASE@@%{?dist} +License: MIT +Source0: %{name}-%{version}.tar.gz +URL: https://github.com/tonarino/innernet + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root + +Requires: glibc +Requires: systemd +Requires: libgcc + +%description +%{summary} + +%prep +%setup -q + +%build +ln -s %{name} .%{_bindir}/inn + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot} +cp -a * %{buildroot} + +%clean +rm -rf %{buildroot} + +%files +%defattr(-,root,root,-) +%{_bindir}/* +%attr(0644, root, root) "/usr/lib/systemd/system/innernet@.service" +%attr(0644, root, root) "/usr/share/man/man8/innernet.8.gz" diff --git a/client/Cargo.toml b/client/Cargo.toml index 9a3f28b..601da9b 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -45,3 +45,16 @@ maintainer = "tonari " name = "innernet" priority = "optional" section = "net" + +[package.metadata.rpm] +package = "innernet" + +[package.metadata.rpm.cargo] +buildflags = ["--release"] + +[package.metadata.rpm.files] +"../innernet@.service" = { path = "/usr/lib/systemd/system/innernet@.service" } +"../../doc/innernet-server.8.gz" = { path = "/usr/share/man/man8/innernet.8.gz" } + +[package.metadata.rpm.targets] +innernet = { path = "/usr/bin/innernet" } diff --git a/rpm/Dockerfile b/rpm/Dockerfile new file mode 100644 index 0000000..29eb0b5 --- /dev/null +++ b/rpm/Dockerfile @@ -0,0 +1,27 @@ +ARG DISTRO +ARG VER + +FROM ${DISTRO}:${VER} as builder +LABEL stage=innernet-rpm + +RUN dnf -y update && \ + dnf -y install clang-devel sqlite-devel glibc-devel rpm-build && \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal + +WORKDIR /workdir +COPY . . +RUN rm -rf target + +RUN source $HOME/.cargo/env && \ + cargo install cargo-rpm && \ + cargo build --release --verbose&& \ + # device::tests::test_add_peers will fail due to restricted docker env + cargo test --release --verbose -- --skip test_add_peers && \ + cd server && cargo rpm build && \ + cd ../client && cargo rpm build + +FROM ${DISTRO}:${VER} +LABEL stage=innernet-rpm + +RUN mkdir -p /target/rpm +COPY --from=builder /workdir/target/release/rpmbuild/RPMS/x86_64/innernet-*.rpm /target/rpm/ diff --git a/rpm/build-package.sh b/rpm/build-package.sh new file mode 100755 index 0000000..352d90d --- /dev/null +++ b/rpm/build-package.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +cmd() { + echo "[#] $*" >&2 + "$@" +} + +if [ $# -lt 1 ]; then + echo "Usage: $0 distro version (from docker hub), e.g:" + echo + echo "$0 fedora:33" + exit 1 +else + SPLIT_ARG=(${1//:/ }) + DISTRO=${SPLIT_ARG[0]} + VER=${SPLIT_ARG[1]} + + if [[ -z "$DISTRO" || -z "$VER" ]]; then + echo "bad arg" + exit 1 + fi +fi + + +SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +cd $SCRIPT_DIR/.. + +cmd docker build --tag "innernet-rpm-$DISTRO$VER" --file rpm/Dockerfile --build-arg DISTRO=$DISTRO --build-arg VER=$VER . + +echo "exporting built rpm's from docker image" +cmd docker run --rm innernet-rpm-$DISTRO$VER sh -c "tar cf - target/rpm/*" | tar xv + +echo "cleaning up" +cmd docker image prune --force --filter label=stage=innernet-rpm diff --git a/server/.rpm/innernet-server.spec b/server/.rpm/innernet-server.spec new file mode 100644 index 0000000..20d2427 --- /dev/null +++ b/server/.rpm/innernet-server.spec @@ -0,0 +1,39 @@ +%define __spec_install_post %{nil} +%define __os_install_post %{_dbpath}/brp-compress +%define debug_package %{nil} + +Name: innernet-server +Summary: A server to coordinate innernet networks. +Version: @@VERSION@@ +Release: @@RELEASE@@%{?dist} +License: MIT +Source0: %{name}-%{version}.tar.gz +URL: https://github.com/tonarino/innernet + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root + +Requires: glibc +Requires: systemd +Requires: libgcc +Requires: sqlite +Requires: zlib + +%description +%{summary} + +%prep +%setup -q + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot} +cp -a * %{buildroot} + +%clean +rm -rf %{buildroot} + +%files +%defattr(-,root,root,-) +%{_bindir}/* +%attr(0644, root, root) "/usr/lib/systemd/system/innernet-server@.service" +%attr(0644, root, root) "/usr/share/man/man8/innernet-server.8.gz" diff --git a/server/Cargo.toml b/server/Cargo.toml index fcfb446..23914a2 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -56,3 +56,16 @@ maintainer = "tonari " name = "innernet-server" priority = "optional" section = "net" + +[package.metadata.rpm] +package = "innernet-server" + +[package.metadata.rpm.cargo] +buildflags = ["--release"] + +[package.metadata.rpm.files] +"../innernet-server@.service" = { path = "/usr/lib/systemd/system/innernet-server@.service" } +"../../doc/innernet-server.8.gz" = { path = "/usr/share/man/man8/innernet-server.8.gz" } + +[package.metadata.rpm.targets] +innernet-server = { path = "/usr/bin/innernet-server" }