Skip to content

Commit

Permalink
Merge branch 'Interstellar-Relay-Community/interstellar-next' into mu…
Browse files Browse the repository at this point in the history
…subi.moe/main

# Conflicts:
#	Cargo.lock
#	Cargo.toml
  • Loading branch information
sinoru committed Jan 26, 2024
2 parents 0bbbc19 + 7a30c9c commit 6878ab9
Show file tree
Hide file tree
Showing 29 changed files with 1,379 additions and 840 deletions.
1,672 changes: 1,139 additions & 533 deletions Cargo.lock

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "aode-relay"
description = "A simple activitypub relay"
version = "0.3.104+musubi-moe.0.4"
version = "0.3.106+musubi-moe.0.5"
authors = ["asonix <[email protected]>", "musubi.moe <[email protected]>"]
license = "AGPL-3.0"
readme = "README.md"
Expand All @@ -15,44 +15,46 @@ name = "relay"
path = "src/main.rs"

[features]
console = ["console-subscriber"]
console = ["dep:console-subscriber"]
default = []

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
actix-rt = "2.7.0"
actix-web = { version = "4.4.0", default-features = false, features = ["compress-brotli", "compress-gzip", "rustls-0_21"] }
actix-webfinger = { version = "0.5.0", default-features = false }
activitystreams = "0.7.0-alpha.25"
activitystreams-ext = "0.1.0-alpha.3"
ammonia = "3.1.0"
async-cpupool = "0.2.0"
bcrypt = "0.15"
base64 = "0.21"
clap = { version = "4.0.0", features = ["derive"] }
config = "0.13.0"
console-subscriber = { version = "0.1", optional = true }
console-subscriber = { version = "0.2", optional = true }
dashmap = "5.1.0"
dotenv = "0.15.0"
flume = "0.11.0"
lru = "0.11.0"
metrics = "0.21.0"
metrics-exporter-prometheus = { version = "0.12.0", default-features = false, features = [
lru = "0.12.0"
metrics = "0.22.0"
metrics-exporter-prometheus = { version = "0.13.0", default-features = false, features = [
"http-listener",
] }
metrics-util = "0.15.0"
metrics-util = "0.16.0"
mime = "0.3.16"
minify-html = "0.11.0"
opentelemetry = { version = "0.20", features = ["rt-tokio"] }
opentelemetry-otlp = "0.13"
minify-html = "0.15.0"
opentelemetry = "0.21"
opentelemetry_sdk = { version = "0.21", features = ["rt-tokio"] }
opentelemetry-otlp = "0.14"
pin-project-lite = "0.2.9"
quanta = "0.11.0"
# pinned to metrics-util
quanta = "0.12.0"
rand = "0.8"
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "stream"]}
reqwest-middleware = "0.2"
reqwest-tracing = "0.4.5"
ring = "0.16.20"
ring = "0.17.5"
rsa = { version = "0.9" }
rsa-magic-public-key = "0.8.0"
rustls = "0.21.0"
Expand All @@ -69,41 +71,40 @@ thiserror = "1.0"
time = { version = "0.3.17", features = ["serde"] }
tracing = "0.1"
tracing-error = "0.2"
tracing-futures = "0.2"
tracing-log = "0.1"
tracing-opentelemetry = "0.21"
tracing-log = "0.2"
tracing-opentelemetry = "0.22"
tracing-subscriber = { version = "0.3", features = [
"ansi",
"env-filter",
"fmt",
] }
tokio = { version = "1", features = ["macros", "sync"] }
tokio = { version = "1", features = ["full", "tracing"] }
uuid = { version = "1", features = ["v4", "serde"] }
streem = "0.1.0"
streem = "0.2.0"

[dependencies.background-jobs]
version = "0.15.0"
version = "0.17.0"
default-features = false
features = ["background-jobs-actix", "error-logging"]
features = ["error-logging", "metrics", "tokio"]

[dependencies.http-signature-normalization-actix]
version = "0.10.1"
version = "0.11.0"
default-features = false
features = ["server", "ring"]

[dependencies.http-signature-normalization-reqwest]
version = "0.10.0"
version = "0.11.0"
default-features = false
features = ["middleware", "ring"]

[dependencies.tracing-actix-web]
version = "0.7.6"
version = "0.7.9"

[build-dependencies]
anyhow = "1.0"
dotenv = "0.15.0"
ructe = { version = "0.17.0", features = ["sass", "mime03"] }
toml = "0.7.0"
toml = "0.8.0"

[profile.dev.package.rsa]
opt-level = 3
62 changes: 46 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
# syntax=docker/dockerfile:1.4
FROM alpine:3.19 AS alpine
ARG TARGETPLATFORM

RUN \
--mount=type=cache,id=$TARGETPLATFORM-alpine,target=/var/cache/apk,sharing=locked \
set -eux; \
apk add -U libgcc;

################################################################################

FROM alpine AS alpine-dev
ARG TARGETPLATFORM

RUN \
--mount=type=cache,id=$TARGETPLATFORM-alpine,target=/var/cache/apk,sharing=locked \
set -eux; \
apk add -U musl-dev;

################################################################################

FROM --platform=$BUILDPLATFORM rust:1 AS builder
ARG BUILDPLATFORM
ARG TARGETPLATFORM

RUN \
--mount=type=cache,target=/var/cache,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
--mount=type=tmpfs,target=/var/log \
--mount=type=cache,id=$BUILDPLATFORM-debian,target=/var/cache,sharing=locked \
--mount=type=cache,id=$BUILDPLATFORM-debian,target=/var/lib/apt,sharing=locked \
set -eux; \
case "${TARGETPLATFORM}" in \
linux/i386) \
rustArch='i686'; \
dpkgArch='i386'; \
;; \
linux/amd64) \
rustArch='x86_64'; \
dpkgArch='amd64'; \
;; \
linux/arm64) \
rustArch='aarch64'; \
dpkgArch='arm64'; \
;; \
*) echo "unsupported architecture"; exit 1 ;; \
Expand All @@ -28,31 +44,45 @@ RUN \
apt-get install -y --no-install-recommends \
musl-dev:$dpkgArch \
musl-tools:$dpkgArch \
; \
rustup target add "${rustArch}-unknown-linux-musl";
;

WORKDIR /opt/aode-relay

RUN set -eux; \
case "${TARGETPLATFORM}" in \
linux/i386) arch='i686';; \
linux/amd64) arch='x86_64';; \
linux/arm64) arch='aarch64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac; \
rustup target add "${arch}-unknown-linux-musl";

ADD Cargo.lock Cargo.toml /opt/aode-relay/
RUN cargo fetch;

ADD . /opt/aode-relay
COPY --link --from=alpine-dev / /opt/alpine/

RUN set -eux; \
case "${TARGETPLATFORM}" in \
linux/i386) rustArch='i686';; \
linux/amd64) rustArch='x86_64';; \
linux/arm64) rustArch='aarch64';; \
linux/i386) arch='i686';; \
linux/amd64) arch='x86_64';; \
linux/arm64) arch='aarch64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac; \
ln -s "target/${rustArch}-unknown-linux-musl/release/relay" "aode-relay"; \
# Workaround to use gnu-gcc instead of musl-gcc: https://github.com/rust-lang/rust/issues/95926
RUSTFLAGS="-C target-cpu=generic -C linker=${rustArch}-linux-gnu-gcc" cargo build --frozen --release --target="${rustArch}-unknown-linux-musl";
ln -s "target/${arch}-unknown-linux-musl/release/relay" "aode-relay"; \
export RUSTFLAGS="-C target-cpu=generic -C linker=${arch}-linux-musl-gcc -C target-feature=-crt-static -C link-self-contained=no -L /opt/alpine/lib -L /opt/alpine/usr/lib"; \
cargo build --frozen --release --target="${arch}-unknown-linux-musl";

################################################################################

FROM alpine:3.18
FROM alpine
ARG TARGETPLATFORM

RUN apk add --no-cache openssl ca-certificates curl tini
RUN \
--mount=type=cache,id=$TARGETPLATFORM-alpine,target=/var/cache/apk,sharing=locked \
set -eux; \
apk add -U ca-certificates curl tini;

COPY --link --from=builder /opt/aode-relay/aode-relay /usr/local/bin/aode-relay

Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions relay.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
{ lib
, nixosTests
, protobuf
, rustPlatform
}:

rustPlatform.buildRustPackage {
pname = "relay";
version = "0.3.104";
version = "0.3.106";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;

PROTOC = "${protobuf}/bin/protoc";
PROTOC_INCLUDE = "${protobuf}/include";
RUSTFLAGS = "--cfg tokio_unstable";

nativeBuildInputs = [ ];
Expand Down
14 changes: 7 additions & 7 deletions src/collector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use metrics::{Key, Recorder, SetRecorderError};
use metrics::{Key, Metadata, Recorder, SetRecorderError};
use metrics_util::{
registry::{AtomicStorage, GenerationalStorage, Recency, Registry},
MetricKindMask, Summary,
Expand Down Expand Up @@ -289,7 +289,7 @@ impl Inner {
}

let mut d = self.distributions.write().unwrap();
let outer_entry = d.entry(name.clone()).or_insert_with(BTreeMap::new);
let outer_entry = d.entry(name.clone()).or_default();

let entry = outer_entry
.entry(labels)
Expand Down Expand Up @@ -360,8 +360,8 @@ impl MemoryCollector {
d.entry(key.as_str().to_owned()).or_insert(description);
}

pub(crate) fn install(&self) -> Result<(), SetRecorderError> {
metrics::set_boxed_recorder(Box::new(self.clone()))
pub(crate) fn install(&self) -> Result<(), SetRecorderError<Self>> {
metrics::set_global_recorder(self.clone())
}
}

Expand Down Expand Up @@ -393,19 +393,19 @@ impl Recorder for MemoryCollector {
self.add_description_if_missing(&key, description)
}

fn register_counter(&self, key: &Key) -> metrics::Counter {
fn register_counter(&self, key: &Key, _: &Metadata<'_>) -> metrics::Counter {
self.inner
.registry
.get_or_create_counter(key, |c| c.clone().into())
}

fn register_gauge(&self, key: &Key) -> metrics::Gauge {
fn register_gauge(&self, key: &Key, _: &Metadata<'_>) -> metrics::Gauge {
self.inner
.registry
.get_or_create_gauge(key, |c| c.clone().into())
}

fn register_histogram(&self, key: &Key) -> metrics::Histogram {
fn register_histogram(&self, key: &Key, _: &Metadata<'_>) -> metrics::Histogram {
self.inner
.registry
.get_or_create_histogram(key, |c| c.clone().into())
Expand Down
7 changes: 6 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,11 @@ mod tests {
{
let db =
Db::build_inner(true, sled::Config::new().temporary(true).open().unwrap()).unwrap();
actix_rt::System::new().block_on((f)(db));

tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on((f)(db));
}
}
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use activitystreams::checked::CheckError;
use actix_rt::task::JoinError;
use actix_web::{
error::{BlockingError, ResponseError},
http::StatusCode,
HttpResponse,
};
use http_signature_normalization_reqwest::SignError;
use std::{convert::Infallible, fmt::Debug, io};
use tokio::task::JoinError;
use tracing_error::SpanTrace;

pub(crate) struct Error {
Expand Down
8 changes: 3 additions & 5 deletions src/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl AdminConfig {
}

fn verify(&self, token: XApiToken) -> Result<bool, Error> {
bcrypt::verify(&token.0, &self.hashed_api_token).map_err(Error::bcrypt_verify)
bcrypt::verify(token.0, &self.hashed_api_token).map_err(Error::bcrypt_verify)
}
}

Expand Down Expand Up @@ -200,10 +200,8 @@ impl FromRequest for Admin {
Box::pin(async move {
let (db, c, s, t) = res?;
Self::verify(c, s, t).await?;
metrics::histogram!(
"relay.admin.verify",
now.elapsed().as_micros() as f64 / 1_000_000_f64
);
metrics::histogram!("relay.admin.verify")
.record(now.elapsed().as_micros() as f64 / 1_000_000_f64);
Ok(Admin { db })
})
}
Expand Down
1 change: 1 addition & 0 deletions src/future.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::{future::Future, pin::Pin};

pub(crate) type LocalBoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
pub(crate) type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
Loading

0 comments on commit 6878ab9

Please sign in to comment.