From fea23aecc3d28628e7fb77435c5c199fa510fc56 Mon Sep 17 00:00:00 2001 From: mplorentz Date: Wed, 2 Jul 2025 23:28:36 -0300 Subject: [PATCH] Add Dockerfile I added this so that I could run a nak bunker on my server alongside my other containers. Thought it might be useful for others. --- .dockerignore | 36 ++++++++++++++++++++++++++++++++++++ Dockerfile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 8 ++++++++ 3 files changed, 93 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..166c79f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,36 @@ +# git files +.git +.gitignore + +# documentation +README.md +LICENSE + +# development files +justfile +*.md + +# test files +*_test.go +cli_test.go + +# build artifacts +nak +*.exe +mnt + +# ide and editor files +.vscode +.idea +*.swp +*.swo +*~ + +# os generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6836670 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# build stage +FROM golang:1.24-alpine AS builder + +# install git and ca-certificates (needed for fetching dependencies) +RUN apk add --no-cache git ca-certificates + +# set working directory +WORKDIR /app + +# copy go mod files first for better caching +COPY go.mod go.sum ./ + +# download dependencies +RUN go mod download + +# copy source code +COPY . . + +# build the application +# use cgo_enabled=0 to create a static binary +# use -ldflags to strip debug info and reduce binary size +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o nak . + +# runtime stage +FROM alpine:latest + +# install ca-certificates for https requests (needed for relay connections) +RUN apk --no-cache add ca-certificates + +# create a non-root user +RUN adduser -D -s /bin/sh nakuser + +# set working directory +WORKDIR /home/nakuser + +# copy the binary from builder stage +COPY --from=builder /app/nak /usr/local/bin/nak + +# make sure the binary is executable +RUN chmod +x /usr/local/bin/nak + +# switch to non-root user +USER nakuser + +# set the entrypoint +ENTRYPOINT ["nak"] + +# default command (show help) +CMD ["--help"] diff --git a/README.md b/README.md index f98d44d..e849812 100644 --- a/README.md +++ b/README.md @@ -304,6 +304,14 @@ ffmpeg -f alsa -i default -f webm -t 00:00:03 pipe:1 | nak blossom --server blos ```shell ~> cat all.jsonl | nak filter -k 1111 > filtered.jsonl ``` +### run nak in Docker + +If you want to run nak inside a container (i.e. to run nak as a server, or to avoid installing the Go toolchain) you can run it with Docker: + +```shell +docker build -t nak . +docker run nak event +``` ## contributing to this repository