pict-rs 0.3.2 on OpenBSD 7.2: Install

created
( modified )
@nabbisen

Summary

This post is a part of Lemmy 0.16.7 on OpenBSD 7.2 about Lemmy.

Premise

The server is OpenBSD and Rust (rustlang) is installed. Also, there is _lemmy user whose home directory is /var/lemmy.

Environment

  • OS: OpenBSD 7.2
  • Object Storage: MinIO - AWS S3-compatible (Optional)
  • Apps
    • pict-rs: 0.3.2
      • based on Rust 1.63 + Actix Web 4 + Actix 0.13

Tutorial

pict-rs server

Lemmy uses pict-rs to store image. It is a simple image hosting service which is open source and written in Rust, too.

Prepare for the dependencies

You have to install protobuf, “Protocol Buffers - Google’s data interchange format”

Therefore switch back to your own user if you are acting as _lemmy to install it:

$ exit

$ doas pkg_add protobuf

The output was:

quirks-6.42 signed on 2023-01-13T18:22:41Z
protobuf-3.21.6: ok

Build pict-rs server

Switch to _lemmy:

$ doas su - _lemmy

Get the source of the stable version (v0.4 didn’t work in my case):

$ git clone https://git.asonix.dog/asonix/pict-rs.git --branch v0.3.2 --single-branch

The output was:

Cloning into 'pict-rs'...
remote: Enumerating objects: 2707, done.
remote: Counting objects: 100% (2707/2707), done.
remote: Compressing objects: 100% (1932/1932), done.
remote: Total 2707 (delta 1806), reused 1077 (delta 687), pack-reused 0
Receiving objects: 100% (2707/2707), 2.21 MiB | 114.00 KiB/s, done.
Resolving deltas: 100% (1806/1806), done.
Note: switching to '4dff8de9851041911b8243a35bf9f6df4d612268'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
(...)

Go inside:

$ cd pict-rs

Then run to build:

$ cargo build --release

The output was:

    Updating git repository `https://github.com/asonix/rust-s3`
   (...)
   Compiling rustls v0.20.6
   (...)
   Compiling actix-web v4.1.0
   (...)
   Compiling pict-rs v0.3.2 (/var/lemmy/pict-rs)
    Finished release [optimized] target(s) in 20m 35s

Now you can run pict-rs server with -p option to specify data directory:

$ cargo run --release -- -p data

The output was:

    Finished release [optimized] target(s) in 0.24s
     Running `target/release/pict-rs -p data`
2023-01-14T12:51:58.377271Z  INFO restructure{store=FileStore { path_gen: "generator", root_dir: "data" }}: pict_rs::store::file_store::restructure: new
2023-01-14T12:51:58.377478Z  INFO restructure{store=FileStore { path_gen: "generator", root_dir: "data" }}: pict_rs::store::file_store::restructure: close time.busy=11.3µs time.idle=197µs
2023-01-14T12:51:58.377627Z  INFO actix_server::builder: Starting 1 workers
2023-01-14T12:51:58.377736Z  INFO actix_server::server: Actix runtime found; starting in Actix runtime

Additionally, you can specify address to listen:

$ cargo run --release -- -a 127.0.0.1:8080 -p data

Additionally, you can modify its configuration:

$ nvim pict-rs.toml

For example:

- api_key = 'API_KEY'

- image_format = 'jpeg'

- opentelemetry_url = 'http://localhost:4317/'
+ opentelemetry_url = 'http://127.0.0.1:4317/'
Integrate pict-rs with MinIO (Optional)

pict-rs stores image files in their local directory by default.

Well, there is a way to introduce MinIO bucket usage by editting pict-rc.toml as below:

- type = "file_store"
+ type = "s3_store"
+ 
+ region = "https://(minio-fqdn)"
+ bucket_name = "(...)"
+ access_key = "(...)"
+ secret_key = "(...)"

and, of course, creating MinIO bucket and service account, with bucket policy like:

{
 "Version": "2012-10-17",
 "Statement": [
  {
   "Effect": "Allow",
   "Action": [
    "admin:*"
   ]
  },
  {
   "Effect": "Allow",
   "Action": [
    "s3:*"
   ],
   "Resource": [
    "arn:aws:s3:::{bucket-name}",
    "arn:aws:s3:::{bucket-name}/*"
   ]
  }
 ]
}

Conclusion

Well done :) Go on to the next step.

Return

Comments or feedbacks are welcomed and appreciated.