Skip to content

Commit

Permalink
Dockerfile and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
izderadicka committed Jan 20, 2018
1 parent 9eb3532 commit d1976cc
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
@@ -0,0 +1,6 @@
target
.vscode
npm-debug.log
**/node_modules
Dockerfile
README.md
57 changes: 57 additions & 0 deletions Dockerfile
@@ -0,0 +1,57 @@
FROM ubuntu:16.04
MAINTAINER Ivan <ivan@zderadicka.eu>

RUN apt-get update &&\
apt-get install -y pkg-config openssl libssl-dev libtag1-dev libtagc0-dev curl ffmpeg &&\
curl -sL https://deb.nodesource.com/setup_8.x | bash - &&\
apt-get install -y nodejs &&\
adduser audioserve


WORKDIR /home/audioserve

COPY . audioserve_src
VOLUME /audiobooks

RUN chown -R audioserve:audioserve audioserve_src &&\
mkdir /audioserve &&\
chown audioserve:audioserve /audioserve

VOLUME /audiobooks

USER audioserve

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

RUN export PATH=/home/audioserve/.cargo/bin:$PATH &&\
cd audioserve_src &&\
cargo build --release &&\
cargo test --release

RUN cd audioserve_src/client &&\
npm install &&\
npm run build

RUN cp audioserve_src/target/release/audioserve /audioserve &&\
mkdir /audioserve/client &&\
cp -r audioserve_src/client/dist /audioserve/client &&\
rm -r audioserve_src &&\
rm -r .cargo

WORKDIR /audioserve

RUN mkdir ssl &&\
cd ssl &&\
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem \
-subj "/C=CZ/ST=Prague/L=Prague/O=Ivan/CN=audioserve" &&\
openssl pkcs12 -inkey key.pem -in certificate.pem -export -passout pass:mypass -out audioserve.p12 &&\
rm key.pem certificate.pem

EXPOSE 3000

CMD ./audioserve -s mypass -t low --ssl-key ./ssl/audioserve.p12 --ssl-key-password mypass /audiobooks





87 changes: 84 additions & 3 deletions README.md
@@ -1,8 +1,89 @@
Audioserve
==========

Simple personal server to serve audiofiles files from folders. Intended primarily for audio books, but anything with decent folder structure will do.
Simple personal server to serve audio files files from directories. Intended primarily for audio books, but anything with decent directories structure will do. Focus here is on simplicity and minimalistic design.

This is pre-alpha version - basically PoC. Works locally, if client is served from other webserver.
Server is in Rust, client is Javascript intended for modern browser (latest Firefox or Chrome).

Server is in Rust, client is intended for modern browser (simple ES6 javascript).
For some background and video demo check this article [Audioserve Audiobooks Server - Stupidly Simple or Simply Stupid?](http://zderadicka.eu/audioserve-audiobooks-server-stupidly-simple-or-simply-stupid)

Media Library
-------------

Audioserve is intended to serve files from directory in exactly same structure, no audio tags are considered. So recommended structure is:

Author Last Name, First Name/Audio Book Name
Author Last Name, First Name/Series Name/Audio Book Name

Files should be named so they are in right alphabetical order - ideal is:

001 - First Chapter Name.opus
002 - Seconf Chapter Name.opus

But this structure is not mandatory - you will just see whatever directories and files you have, so use anything that will suite you.

In folders you can have additional metadata files - first available image (jpeg or png) is taken as a coverage picture and first text file (html, txt, md) is taken as description of the folder.

Search is done for folder names only (not individual files, neither audio metadata tags).

Security
--------

Audioserve is not writing anything to your media library, so read only access is OK. The only one file where it needs to write is a file were it keeps its secret key for authentication (by default in `~/.audioserve.secret`, but it can be specified by command line argument).

Authentication is done by shared secret phrase (supplied to server on command line), which client must know. Secret phrase is never sent in plain (it's sent as salted hash). If correct shared secret hash is provided sever generates a token, usinng its secret key. Token then can be used in cookie or HTTP Authorization header (Bearer method).
Token validity period is one year by default, but can be set as command line argument.
As token can be used to replay session https is recomended (TLS support is build in).

### TLS/SSL

Audioserve supports TLS/SSL - to enable it you need to provide your private server key as PKCS#12 file (in `--ssl-key` argument). Here is quick tip how to create private key with self-signed certificate:

openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem \
-subj "/C=CZ/ST=Prague/L=Prague/O=Ivan/CN=audioserve"
openssl pkcs12 -inkey key.pem -in certificate.pem -export -passout pass:mypass -out audioserve.p12
rm key.pem certificate.pem


Transcoding
-----------

Audioserve offers possibility to transcode audio files to opus format (opus codec, ogg container) to save bandwidth and volume of transfered data. For transcoding to work `ffmpeg` program must be install and available on system's PATH.
Transconding is provided is three options ( argument `-t`, if not provided no transcoding is done):

* low - 32 kbps opus with 12kHz cutoff
* medium - 48 kbps opus with 12kHz cutoff
* high - 64 kbps opus with 20kHz cutoff

As already noted audioserve is intended primarily for audiobooks and believe me opus codec is excellent there even in low bitrates.

Command line
------------
Check with `audioserve -h`. Only two required arguments are shared secrect and root of media library.
`audioserve` is server executable and it also needs web client files , which are `index.html` and `bundle.js`, which are defaultly in `./client/dist`, but their location can by specified by argument `-c`


Installation
------------

Clone repo with:

git clone https://github.com/izderadicka/audioserve

To install locally you need [Rust](https://www.rust-lang.org/en-US/install.html) and [NodeJS](https://nodejs.org/en/download/package-manager/) installed - compile with `cargo build --release` (Rust code have system dependencies to openssl and taglib) and build client in its directory:

npm install
npm run build

But easiest way how to test audioserve is to run it as docker container with provided `Dockerfile`, just run:

docker build --tag audioserve .
docker run -d --name audioserve -p 3000:3000 -v /path/to/your/audiobooks:/audiobooks audioserve

Then open https://localhost:3000 and accept insecure connection, shared secret to enter in client is mypass


License
-------

[MIT](https://opensource.org/licenses/MIT)

0 comments on commit d1976cc

Please sign in to comment.