From 655598e807fe5ecf66cbadea4f0fccceb4bba1ea Mon Sep 17 00:00:00 2001 From: CodexHere Date: Tue, 12 Mar 2024 19:57:46 -0500 Subject: [PATCH] Feature: Dockerize project * Added Dockerfile to build project * Added docker-compose.yml for easy container orchestration * Added helper shell script docker_start.sh to easily start and attach the container. * Added dockerignore file to avoid over-including files. * Minor update to README to include docker information. --- .dockerignore | 2 ++ .editorconfig | 4 ++++ Dockerfile | 18 ++++++++++++++++++ README.md | 17 +++++++++++++++++ docker-compose.yml | 15 +++++++++++++++ docker_start.sh | 7 +++++++ 6 files changed, 63 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 docker_start.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..63d337d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +docker-compose.yml +Dockerfile diff --git a/.editorconfig b/.editorconfig index 011b707..30114ed 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,7 @@ indent_size = 4 [*.rs] indent_size = 2 + +[*.yml] +indent_size = 2 +indent_style = space diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b67b83f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM rust:1.76-bookworm + +RUN \ + apt update && \ + apt install -y pulseaudio && \ + apt-get clean autoclean && \ + rm -rf /var/lib/{apt,dpkg,cache,log}/ && \ + mkdir /app && chown 1000:1000 /app + +WORKDIR /app +USER 1000 + +COPY --chown=1000:1000 . /app + +RUN cargo build + +ENTRYPOINT ["/app/target/release/scope-tui"] +CMD ["pulse"] diff --git a/README.md b/README.md index 6e679e5..6564c27 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,22 @@ The audio buffer size directly impacts resource usage, latency and refresh rate To change audio buffer size, the PulseAudio client must be restarted. Because of this, such option is configurable only at startup. +## Docker Compose + +Included is a simple `Dockerfile` to build the project, and an accompanying `docker-compose.yml` to orchestrate starting the container with the proper volume mounts and environment variables. + +Also included is a helper shell script to launch the container, attach to the container instance, and destroy the container on exiting. + +```sh +docker compose up -d +docker attach scope_tui +docker compose down + +# OR + +./docker_start.sh +``` + ## Controls * Use `q` or `CTRL+C` to exit * Use `s` to toggle scatter mode @@ -104,6 +120,7 @@ Some features I plan to work on and would like to add: * [x] Multiple channels * [x] Spectroscope * [x] File source + * [x] Dockerize * [ ] Mac audio sources * [ ] Windows audio sources * [ ] Improve file audio source diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d15999e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.8" + +services: + scope_tui: + container_name: scope_tui + # command: ["--scatter", "pulse"] # Example of customizing options + image: scope_tui + build: . + stdin_open: true + tty: true + environment: + - PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native + volumes: + - ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native + - ~/.config/pulse/cookie:/.config/pulse/cookie diff --git a/docker_start.sh b/docker_start.sh new file mode 100755 index 0000000..a90e345 --- /dev/null +++ b/docker_start.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +docker compose up -d + +docker attach scope_tui + +docker compose down