diff --git a/.github/workflows/building.yml b/.github/workflows/building.yml new file mode 100644 index 0000000..98c61e5 --- /dev/null +++ b/.github/workflows/building.yml @@ -0,0 +1,125 @@ +name: testing + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Setup Rust toolchain + uses: moonrepo/setup-rust@v1 + with: + channel: stable + bins: cargo-hack, cargo-deny + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get upgrade -y + sudo apt-get install -y wget clang + - name: Setup mold + uses: rui314/setup-mold@v1 + - name: Setup buf + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup sccache + uses: mozilla-actions/sccache-action@v0.0.4 + - name: Enable sccache + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + - name: Lint protobuf files + uses: bufbuild/buf-lint-action@v1 + - name: Run clippy lint + run: cargo hack clippy --all-targets --each-feature --workspace + - name: Run tests + run: cargo hack test --all-targets --each-feature --verbose --workspace + - name: Check for MSRV compliance + run: cargo hack check --rust-version --all-targets --each-feature --workspace + - name: Check dependency graph + run: cargo deny --all-features --workspace check + pkg-deb: + runs-on: ubuntu-latest + container: debian:bullseye + steps: + - uses: actions/checkout@v4 + - name: Setup Rust toolchain + uses: moonrepo/setup-rust@v1 + with: + channel: stable + bins: cargo-deb + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y wget lintian clang + - name: Setup mold + uses: rui314/setup-mold@v1 + - name: Setup buf + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup sccache + uses: mozilla-actions/sccache-action@v0.0.4 + - name: Enable sccache + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + - name: Build Debian package + run: cargo xtask dist deb && dpkg-deb -c target/debian/*.deb + - name: Lint Debian package + run: lintian -i target/debian/*.deb + - uses: actions/upload-artifact@v4 + with: + name: rsjudge-deb + path: target/debian/*.deb + pkg-rpm: + runs-on: ubuntu-latest + container: fedora:38 + steps: + - uses: actions/checkout@v4 + - name: Setup Rust toolchain + uses: moonrepo/setup-rust@v1 + with: + channel: stable + bins: cargo-generate-rpm + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Install dependencies + run: | + sudo dnf install -y wget clang mold protobuf-compiler + - name: Setup buf + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup sccache + uses: mozilla-actions/sccache-action@v0.0.4 + - name: Enable sccache + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + - name: Build RPM package + run: cargo xtask dist rpm && rpm -qlp target/generate-rpm/*.rpm + - uses: actions/upload-artifact@v4 + with: + name: rsjudge-rpm + path: target/generate-rpm/*.rpm diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml deleted file mode 100644 index 31ebbe9..0000000 --- a/.github/workflows/testing.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: testing - -on: - push: - branches: ["main"] - pull_request: - branches: ["main"] - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v4 - - name: Setup Rust toolchain - uses: moonrepo/setup-rust@v1 - with: - channel: stable - bins: cargo-deb, cargo-hack, cargo-deny - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Install dependencies - run: | - sudo apt-get update && sudo apt-get upgrade -y && \ - sudo apt-get install -y wget lintian clang - - name: Setup mold - uses: rui314/setup-mold@v1 - - name: Setup buf - uses: bufbuild/buf-setup-action@v1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Setup protoc - uses: arduino/setup-protoc@v3 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Setup sccache - uses: mozilla-actions/sccache-action@v0.0.3 - - name: Enable sccache - run: | - echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV - echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV - - name: Lint protobuf files - uses: bufbuild/buf-lint-action@v1 - - name: Run clippy lint - run: cargo hack clippy --all-targets --each-feature --workspace - - name: Run tests - run: cargo hack test --all-targets --each-feature --verbose --workspace - - name: Build Debian package - run: cargo xtask dist deb && dpkg-deb -c target/debian/*.deb - - name: Lint Debian package - run: lintian -i target/debian/*.deb - - uses: actions/upload-artifact@v4 - with: - name: rsjudge-deb - path: target/debian/*.deb - - name: Check for MSRV compliance - run: cargo hack check --rust-version --all-targets --each-feature --workspace - - name: Check dependency graph - run: cargo deny --all-features --workspace check diff --git a/Cargo.toml b/Cargo.toml index e7fa145..6ca66b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,13 +52,13 @@ assets = [ "644", ], [ - "target/assets/rsjudge.fish", - "usr/share/fish/vendor_completions.d/rsjudge.fish", + "target/assets/_rsjudge", + "usr/share/zsh/vendor-completions/_rsjudge", "644", ], [ - "target/assets/_rsjudge", - "usr/share/zsh/vendor-completions/_rsjudge", + "target/assets/rsjudge.fish", + "usr/share/fish/vendor_completions.d/rsjudge.fish", "644", ], ] @@ -73,7 +73,7 @@ depends = "$auto, adduser, libc6, libgcc-s1, libstdc++6, libssl1.1, libzstd1, li recommends = "gcc, g++, python3" suggests = "pypy3" section = "net" -systemd-units = { enable = false } +systemd-units = { unit-scripts = "packaging/shared", enable = false } [package.metadata.generate-rpm] @@ -94,7 +94,31 @@ mode = "644" [[package.metadata.generate-rpm.assets]] source = "README.adoc" -dest = "/usr/share/doc/rsjudge/README" +dest = "/usr/share/doc/rsjudge/README.adoc" + +[[package.metadata.generate-rpm.assets]] +source = "target/assets/rsjudge.bash" +dest = "/usr/share/bash-completion/completions/rsjudge" + +[[package.metadata.generate-rpm.assets]] +source = "target/assets/_rsjudge" +dest = "/usr/share/zsh/site-functions/_rsjudge" + +[[package.metadata.generate-rpm.assets]] +source = "target/assets/rsjudge.fish" +dest = "/usr/share/fish/vendor_completions.d/rsjudge.fish" + +[[package.metadata.generate-rpm.assets]] +source = "packaging/shared/service" +dest = "/usr/lib/systemd/system/rsjudge.service" + +[[package.metadata.generate-rpm.assets]] +source = "packaging/shared/tmpfile" +dest = "/usr/lib/tmpfiles.d/rsjudge.conf" + +[[package.metadata.generate-rpm.assets]] +source = "packaging/shared/sysuser" +dest = "/usr/lib/sysusers.d/rsjudge.conf" [dependencies] # Workspace dependencies diff --git a/README.adoc b/README.adoc index 05d56b6..3cf7732 100644 --- a/README.adoc +++ b/README.adoc @@ -32,8 +32,8 @@ An online judge sandbox server in Rust, inspired by https://github.com/criyle/go Crate for RESTful API server. `crates/rsjudge-runner/`::: Crate for sandbox logic. -`debian/`:: - Files for generating `.deb` package. +`packaging/`:: + Files for generating `.deb` and `.rpm` package. https://mango-dune-07a8b7110.1.azurestaticapps.net/?repo=NJUPT-SAST%2Frsjudge[ image:https://github.com/NJUPT-SAST/rsjudge/raw/diagram/diagram.svg[ diff --git a/README.zh-CN.adoc b/README.zh-CN.adoc index 3d3feb3..af50d4e 100644 --- a/README.zh-CN.adoc +++ b/README.zh-CN.adoc @@ -34,8 +34,8 @@ RESTful API 服务器。 `crates/rsjudge-runner/`::: 执行各种命令的沙箱,提供用户切换、I/O 重定向、安全上下文等功能。 -`debian/`:: - 用于生成 `.deb` 包的附加文件。 +`packaging/`:: + 用于生成 `.deb` 与 `.rpm` 包的附加文件。 https://mango-dune-07a8b7110.1.azurestaticapps.net/?repo=NJUPT-SAST%2Frsjudge[ image:https://github.com/NJUPT-SAST/rsjudge/raw/diagram/diagram.svg[ diff --git a/packaging/deb/postrm b/packaging/deb/postrm index 2a7ee1f..793e925 100644 --- a/packaging/deb/postrm +++ b/packaging/deb/postrm @@ -1,17 +1,17 @@ #!/bin/sh set -e -RSJUDGE_CONF="/etc/rsjudge/*.conf" +RSJUDGE_CONF="/etc/rsjudge/" case "$1" in purge) - if [ -f "${RSJUDGE_CONF}" ]; then - rm "${RSJUDGE_CONF}" + if [ -d "${RSJUDGE_CONF}" ]; then + rm -r "${RSJUDGE_CONF}" fi - deluser --system --remove-home --group "${RSJUDGE_USER}-supervisor" || true - deluser --system --remove-home --group "${RSJUDGE_USER}-builder" || true - deluser --system --remove-home --group "${RSJUDGE_USER}-runner" || true + deluser --system --remove-home "${RSJUDGE_USER}-supervisor" || true + deluser --system --remove-home "${RSJUDGE_USER}-builder" || true + deluser --system --remove-home "${RSJUDGE_USER}-runner" || true ;; esac diff --git a/packaging/deb/service b/packaging/shared/service similarity index 100% rename from packaging/deb/service rename to packaging/shared/service diff --git a/packaging/shared/sysuser b/packaging/shared/sysuser new file mode 100644 index 0000000..e3b4a1f --- /dev/null +++ b/packaging/shared/sysuser @@ -0,0 +1,4 @@ +#Type Name ID GECOS Home directory Shell +u rsjudge-supervisor - "Supervisor of rsjudge" /var/lib/rsjudge-supervisor +u rsjudge-builder - "Builder of rsjudge" /var/lib/rsjudge-builder +u rsjudge-runner - "Runner of rsjudge" /var/lib/rsjudge-runner diff --git a/packaging/deb/tmpfile b/packaging/shared/tmpfile similarity index 100% rename from packaging/deb/tmpfile rename to packaging/shared/tmpfile diff --git a/xtask/src/main.rs b/xtask/src/main.rs index dbd980f..1cf830e 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -8,7 +8,7 @@ use sh::cmd; enum Package { /// Build DEB package. Deb, - /// Build RPM package (unimplemented). + /// Build RPM package. Rpm, } @@ -38,13 +38,20 @@ fn main() -> anyhow::Result<()> { match command { Command::Dist { package } => match package { Package::Deb => cmd!(cargo deb "-v"), - Package::Rpm => todo!("Not implemented"), + Package::Rpm => cmd! { + cargo build "--release"; + cargo "generate-rpm" + }, }, Command::Docker => cmd!(docker build "-t" rsjudge "."), #[cfg(feature = "dbg")] Command::Debug => return Ok(()), } - .try_for_each(|cmd| cmd.exec())?; + .try_for_each(|cmd| { + #[cfg(feature = "dbg")] + eprintln!("Executing: {:?}", cmd); + cmd.exec() + })?; Ok(()) }