Skip to content

Commit

Permalink
feat: ✨ experimental RPM generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Mar 30, 2024
1 parent b31aaae commit d6250bb
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 81 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/building.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- 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/[email protected]
- 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/[email protected]
- 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
62 changes: 0 additions & 62 deletions .github/workflows/testing.yml

This file was deleted.

36 changes: 30 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
]
Expand All @@ -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]

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down
12 changes: 6 additions & 6 deletions packaging/deb/postrm
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions packaging/shared/sysuser
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
13 changes: 10 additions & 3 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use sh::cmd;
enum Package {
/// Build DEB package.
Deb,
/// Build RPM package (unimplemented).
/// Build RPM package.
Rpm,
}

Expand Down Expand Up @@ -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(())
}

0 comments on commit d6250bb

Please sign in to comment.