diff --git a/.gitignore b/.gitignore index 86b929b..9563954 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build/ dist/ rec/ *.egg-info/ +/venv diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b524389 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3.7 + +ARG hostuid=1000 +ARG hostgid=1000 + +ENV TECHREC_CONFIG=/src/techrec/docker/config.py +ENV DEBIAN_FRONTEND=noninteractive + +WORKDIR /src +COPY . /src/techrec + +RUN groupadd -g ${hostgid} techrec \ + && useradd -g techrec -u ${hostuid} -m techrec \ + && mkdir -p /src/techrec \ + && chown -R techrec:techrec /src \ + && apt-get update \ + && apt-get install -y ffmpeg \ + && rm -rf /var/lib/apt/lists/* + +USER techrec + + +RUN python -m venv ./venv \ + && ./venv/bin/python -m pip install wheel \ + && ./venv/bin/python -m pip install -e ./techrec + +ENTRYPOINT ["/src/venv/bin/techrec"] +CMD ["-vv", "serve"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9a51878 --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +DOCKER := docker +DOCKERC := docker-compose +PORT := 8000 +VENV := venv +CONFIG := dev_config.py +PY := python + +docker-build: + $(DOCKERC) build \ + --no-cache \ + --build-arg=hostgid=$(shell id -g) \ + --build-arg=hostuid=$(shell id -u) \ + --build-arg=audiogid=$(shell cat /etc/group | grep audio | awk -F: '{print $3}') + +docker-build-liquidsoap: + $(DOCKER) pull savonet/liquidsoap:main + $(DOCKERC) build \ + --no-cache \ + --build-arg=audiogid=$(shell cat /etc/group | grep audio | awk -F: '{print $3}') \ + liquidsoap + +docker-build-techrec: + $(DOCKERC) build \ + --no-cache \ + --build-arg=hostgid=$(shell id -g) \ + --build-arg=hostuid=$(shell id -u) \ + techrec + +docker-stop: + $(DOCKERC) down + +docker-run: + $(DOCKERC) run --rm --service-ports techrec + +docker-shell-techrec: + $(eval CONTAINER = $(shell docker ps|grep techrec_run|awk '{print $$12}')) + $(DOCKER) exec -ti $(CONTAINER) bash + +docker-shell-storage: + $(DOCKERC) exec storage bash + +docker-shell-liquidsoap: + $(eval CONTAINER = $(shell docker ps|grep liquidsoap|awk '{print $$12}')) + $(DOCKER) exec -ti $(CONTAINER) bash + +local-install: + $(PY) -m venv $(VENV) + ./$(VENV)/bin/pip install -e . + +local-serve: + env TECHREC_CONFIG=$(CONFIG) ./$(VENV)/bin/techrec -vv serve + + +.PHONY: docker-build docker-build-liquidsoap docker-build-techrec docker-stop docker-run docker-shell-techrec docker-shell-storage docker-shell-liquidsoap local-install local-serve diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..96a158a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,46 @@ +version: "3" + +services: + liquidsoap: + build: + context: . + dockerfile: docker/Dockerfile.liquidsoap + volumes: + - ./docker/run.liq:/run.liq + - ./docker/ror.sh:/ror.sh + - rec:/rec + devices: + - /dev/snd:/dev/snd + entrypoint: /run.liq + depends_on: + - storageprepare + + storage: + image: nginx + volumes: + - rec:/var/www/rec + - ./docker/storage.conf:/etc/nginx/conf.d/default.conf:ro + ports: + - 18080:80 + depends_on: + - storageprepare + + storageprepare: + image: bash + volumes: + - rec:/rec + command: chmod 777 /rec + + techrec: + build: . + volumes: + - .:/src/techrec + - ./docker/output:/src/output + ports: + - 8000:8000 + depends_on: + - liquidsoap + - storage + +volumes: + rec: diff --git a/docker/Dockerfile.liquidsoap b/docker/Dockerfile.liquidsoap new file mode 100644 index 0000000..9e33a34 --- /dev/null +++ b/docker/Dockerfile.liquidsoap @@ -0,0 +1,10 @@ +FROM savonet/liquidsoap:main + +ENV audiogid=995 + +USER root + +RUN groupadd -g ${audiogid} hostaudio \ + && usermod -a -G hostaudio liquidsoap + +USER liquidsoap diff --git a/docker/config.py b/docker/config.py new file mode 100644 index 0000000..ff80fba --- /dev/null +++ b/docker/config.py @@ -0,0 +1,12 @@ +import logging + +AUDIO_INPUT = "http://storage/ror" +AUDIO_OUTPUT = "/src/output" +DEBUG = True +HOST = "0.0.0.0" +PORT = 8000 +TRANSLOGGER_OPTS = { + "logger_name": "accesslog", + "set_logger_level": logging.INFO, + "setup_console_handler": True, +} diff --git a/docker/output/.gitkeep b/docker/output/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker/run.liq b/docker/run.liq new file mode 100755 index 0000000..b5be01d --- /dev/null +++ b/docker/run.liq @@ -0,0 +1,26 @@ +#!/usr/bin/liquidsoap + +settings.log.stdout.set(true); +settings.log.file.set(false); +settings.log.level.set(3); + +# settings.server.telnet.set(true); +# settings.server.telnet.bind_addr.set("127.0.0.1"); +# settings.server.telnet.port.set(6666); + +rorinput = input.alsa(device="default", bufferize=true); +#rorinput = input.pulseaudio( ); + +# rorinput = insert_metadata(id="trx",rorinput); +rorinput = rewrite_metadata([("artist","Radio OndaRossa")],rorinput); + +# ESCPOST +output.file( + id="rorrec", + reopen_when={0m}, + %mp3(bitrate=80, samplerate=44100, stereo=true,stereo_mode="joint_stereo"), + "/rec/ror/%Y-%m/%d/rec-%Y-%m-%d-%H-%M-%S.mp3", + # %vorbis(quality=0.3, samplerate=44100, channels=2), + # "/rec/ror/%Y-%m/%d/rec-%Y-%m-%d-%H-%M-%S.ogg", + rorinput +); diff --git a/docker/storage.conf b/docker/storage.conf new file mode 100644 index 0000000..b9741bd --- /dev/null +++ b/docker/storage.conf @@ -0,0 +1,9 @@ +server { + listen 80 default_server; + server_name storage; + + location / { + root /var/www/rec; + autoindex on; + } +}