Add feature to embed pictrs in lemmy binary (fixes #2627) (#2633)

* Add feature to embed pictrs in lemmy binary (fixes #2627)

* Add pictrs config

* add protobuf

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
Nutomic 2023-01-20 18:46:49 +01:00 committed by GitHub
parent 6eb5ed343c
commit 1eaf2c8a03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 838 additions and 25 deletions

View file

@ -5,3 +5,4 @@ api_tests
ansible
tests
*.sh
pictrs

View file

@ -29,6 +29,8 @@ steps:
environment:
CARGO_HOME: .cargo
commands:
- apt-get update
- apt-get install -y --no-install-recommends protobuf-compiler libprotobuf-dev
- rustup component add clippy
- cargo clippy --workspace --tests --all-targets --all-features --
-D warnings -D deprecated -D clippy::perf -D clippy::complexity

3
.gitignore vendored
View file

@ -18,3 +18,6 @@ query_testing/**/reports/*.json
# API tests
api_tests/node_modules
# pictrs data
pictrs/

817
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -30,8 +30,8 @@ strip = "symbols"
debug = 0
[features]
console = ["console-subscriber", "opentelemetry", "opentelemetry-otlp", "tracing-opentelemetry",
"reqwest-tracing/opentelemetry_0_16"]
embed-pictrs = ["pict-rs"]
console = ["console-subscriber", "opentelemetry", "opentelemetry-otlp", "tracing-opentelemetry", "reqwest-tracing/opentelemetry_0_16"]
default = []
[workspace]
@ -144,3 +144,5 @@ actix-rt = "2.6"
rand = { workspace = true }
console-subscriber = { version = "0.1.8", optional = true }
opentelemetry-otlp = { version = "0.10.0", optional = true }
pict-rs = { version = "0.4.0-beta.9", optional = true }
tokio.workspace = true

View file

@ -18,7 +18,7 @@
# Pictrs image server configuration.
pictrs: {
# Address where pictrs is available (for image hosting)
url: "http://pictrs:8080/"
url: "http://localhost:8080/"
# Set a custom pictrs API key. ( Required for deleting images )
api_key: "string"
}

View file

@ -45,8 +45,8 @@ pub struct Settings {
#[serde(default)]
pub struct PictrsConfig {
/// Address where pictrs is available (for image hosting)
#[default(Url::parse("http://pictrs:8080").expect("parse pictrs url"))]
#[doku(example = "http://pictrs:8080")]
#[default(Url::parse("http://localhost:8080").expect("parse pictrs url"))]
#[doku(example = "http://localhost:8080")]
pub url: Url,
/// Set a custom pictrs API key. ( Required for deleting images )

View file

@ -4,5 +4,31 @@ use lemmy_utils::{error::LemmyError, settings::SETTINGS};
#[actix_web::main]
pub async fn main() -> Result<(), LemmyError> {
init_logging(&SETTINGS.opentelemetry_url)?;
start_lemmy_server().await
#[cfg(not(feature = "embed-pictrs"))]
start_lemmy_server().await?;
#[cfg(feature = "embed-pictrs")]
{
pict_rs::ConfigSource::memory(serde_json::json!({
"server": {
"address": "127.0.0.1:8080"
},
"old_db": {
"path": "./pictrs/old"
},
"repo": {
"type": "sled",
"path": "./pictrs/sled-repo"
},
"store": {
"type": "filesystem",
"path": "./pictrs/files"
}
}))
.init::<&str>(None)
.expect("initialize pictrs config");
let (lemmy, pictrs) = tokio::join!(start_lemmy_server(), pict_rs::run());
lemmy?;
pictrs.expect("run pictrs");
}
Ok(())
}