pastebin/README.md
Mateusz Kaczanowski 1b4f8e7d82
Update README.md
2020-05-10 03:14:04 +02:00

4.7 KiB

Build Status Docker Cloud Build Status Docker Pulls Docker Image Size

Pastebin

Simple, fast, standalone pastebin service.

Why?

Whenever you need to share a code snippet, diff, logs, or a secret with another human being, the Pastebin service is invaluable. However, using public services such as pastebin.com, privnote.com, etc. should be avoided whenever you're sharing data that should be available only for a selected audience (i.e., your company, private network). Instead of trusting external providers, you could host your own Pastebin service and take ownership of all your data!

There are numerous Pastebin implementations out there, why would you implement another one?

While the other implementation is great, I couldn't find one that would satisfy my requirements:

  • no dependencies - one binary is all I want, no python libs, ruby runtime magic, no javascript or external databases to setup
  • storage - fast, lightweight, self-hosted key-value storage able to hold a lot of data.
  • speed - it must be fast. Once deployed in a mid-sized company you can expect high(er) traffic with low latency expectations from users
  • reliability - no one wants to fix things that should just work (and are that simple!)
  • cheap - low-cost service that would not steal too much of CPU time, thus add up to your bill
  • CLI + GUI - it must be easy to interface from both ends (but still, no deps!)
  • other features: ** on-demand encryption ** syntax highlighting ** destroy after reading ** destroy after expiration date

This Pastebin implementation satisfies all of the above requirements!

Implementation

This is a rust version of Pastebin service with rocksdb database as storage. In addition to previously mentioned feature I should add:

  • all-in-one binary - all the data, including css/javascript files are compiled into the binary. This way you don't need to worry about external dependencies, it's all witin. (see: std::include_bytes)
  • REST endpoint - you can add/delete pastes via standard HTTP client (ie. curl)
  • RocksDB compaction filter - the expired pastes will be automatically removed by custom compaction filter
  • flatbuffers - data is serialized with flatbuffers (access to serialized data without parsing/unpacking)
  • GUI - the UI is a plain HTML with Bootstrap JS, jQuery and prism.js
  • Encryption - password-protected pastes are AES encrypted/decprypted in the browser via CryptoJS

Usage

Pastebin builds only with rust-nightly version and requires llvm compiler to be present (rocksdb deps). To skip the build process, you can use the docker image.

Cargo

cargo build --release
cargo run

Docker

docker pull mkaczanowski/pastebin:latest
docker run mkaczanowski/pastebin --address localhost --port 8000

Client

alias pastebin="curl -q -L -d @- -o - http://localhost:8000/"

echo "hello World" | pastebin
http://localhost:8000/T9kGrI5aNkI4Z-PelmQ5U

Nginx (optional)

The Pastebin service serves /static files from memory. To lower down the load on the service you might want to consider setting up nginx with caching and compression enabled, as shown here:

map $sent_http_content_type $expires {
    default                    off;
    text/css                   30d;
    application/javascript     30d;
    image/x-icon               30d;
}

server {
    listen       80; 
    server_name  paste.domain.com;
    
    gzip on;
    gzip_types text/plain application/xml text/css application/javascript;

    expires $expires;
    location  / {
        proxy_pass        http://localhost:8000;
           include        proxy-settings.conf;
    }

    access_log /var/log/nginx/access.log;
}

Demo

Pastebin service demo