diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9c5735a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +.github +data +*.png +coverage.* +*.out +spectogram +spectrogram diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddda3e8..ee2a132 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,3 +98,12 @@ jobs: - name: Run tests run: go test ./... -v + + docker: + name: Docker Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + + - name: Build image + run: docker build -t spectogram:ci . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..996b3f6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM golang:1.24-alpine AS builder + +WORKDIR /src + +COPY go.mod go.sum ./ +RUN go mod download + +COPY cmd/ ./cmd/ +RUN CGO_ENABLED=0 go build -o /out/spectogram ./cmd/spectogram + +FROM python:3.11-alpine + +WORKDIR /app + +COPY --from=builder /out/spectogram /usr/local/bin/spectogram +COPY web/ ./web/ +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +EXPOSE 8000 + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["serve"] diff --git a/README.md b/README.md index 7b7cd97..0bf317c 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,32 @@ http://localhost:8000/web You should now see an interactive, zoomable Plotly heatmap. +## 🐳 Running with Docker + +A `Dockerfile` is included so you can run both steps without installing Go or Python locally. Build the image once: + +```bash +docker build -t spectogram . +``` + +### Step 1. Generate the spectrogram data + +Mount a local directory containing your audio file to `/app/data`, and generate the output into it: + +```bash +docker run --rm -v "$(pwd)":/app/data spectogram generate -in /app/data/audio.mp3 -out /app/data/spectrogram.png -json /app/data/spectrogram.json +``` + +### Step 2. View the Spectrogram + +Using the same mount, so the web viewer can find `spectrogram.json`: + +```bash +docker run --rm -p 8000:8000 -v "$(pwd)":/app/data spectogram serve +``` + +Then open `http://localhost:8000/web` in your browser, same as the local workflow above. + ## 🧠 How It Works? The `Go` script: @@ -106,10 +132,12 @@ Unit and integration tests live alongside the code in `cmd/spectogram/main_test. ## 📁 Folder Structure ``` -.github/workflows/ - CI pipeline (build, vet, test) +.github/workflows/ - CI pipeline (build, vet, test, Docker image build) cmd/spectogram/ - main Go application and tests (main.go, main_test.go) web/ - HTML viewer with Plotly data/ - generated spectrogram.json output (created automatically, not tracked in git) +Dockerfile - containerized build (Go binary + Python static file server) +docker-entrypoint.sh - dispatches `generate` and `serve` container commands README.md - this file go.mod - Go module info ``` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..d89390f --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -e + +case "$1" in + generate) + shift + exec spectogram "$@" + ;; + serve) + exec python3 -m http.server 8000 + ;; + *) + exec "$@" + ;; +esac