From ca0e81eaa1ad19d9ec87258972c4525e4a596582 Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Sun, 11 Aug 2024 17:42:02 +1000 Subject: [PATCH] Add Dockerfile --- Dockerfile | 12 ++++++++++++ README.md | 32 ++++++++++++++++++++++++-------- main.go | 7 ++++--- 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c361130 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:alpine AS builder +WORKDIR /go/src/jrouter +COPY . . +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + apk add build-base libpcap-dev && \ + CGO_ENABLED=1 CGO_FLAGS='-static' go build -v -o jrouter . + +FROM alpine:latest +COPY --from=builder /go/src/jrouter/jrouter /usr/bin/ +RUN apk add libpcap +ENTRYPOINT ["/usr/bin/jrouter", "-config", "/etc/jrouter/jrouter.yaml"] diff --git a/README.md b/README.md index 7661b0d..38451b4 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Things I plan to fix Real Soon Now: Things I plan to fix At Some Point: -* For expediency I made it act as a _seed router_. At some point I might add +* For expediency I made it act as a _seed router_. At some point I might add "soft seed" functionality. @@ -49,20 +49,16 @@ First, set up a `jrouter.yaml` (use the one in this repo as an example). TODO: explain the configuration file -Building and running: +### Building and running directly 1. Install [Go](https://go.dev/dl). - 2. Run these commands (for Debian-variety Linuxen, e.g. Ubuntu, Raspbian, Mint...): - ```shell sudo apt install git build-essential libpcap-dev go install gitea.drjosh.dev/josh/jrouter@latest sudo setcap 'CAP_NET_BIND_SERVICE=ep CAP_NET_RAW=ep' ~/go/bin/jrouter ``` - 3. Configure `jrouter.yaml` - 4. To run: ```shell ~/go/bin/jrouter @@ -77,6 +73,26 @@ Notes: TODO: instructions for non-Linux / non-Debian-like machines -## Bug reports? Feature requests? Complaints? Praise? +### With Docker -You can contact me on the Fediverse at @DrJosh9000@cloudisland.nz, or email me at josh.deprez@gmail.com. +1. Clone the repo and `cd` into it. +2. `docker build -t jrouter .` +3. Example `docker run` command: + ```shell + docker run \ + -v ./cfg:/etc/jrouter \ + --cap-add NET_RAW \ + --net host \ + --name jrouter \ + jrouter + ``` + +Notes: + +* Put `jrouter.yaml` inside a `cfg` directory (or some path of your choice and bind-mount it at `/etc/jrouter`) for it to find the config file. +* `--cap-add NET_RAW` and `--net host` is needed for EtherTalk access to the network interface. +* By using `--net host`, the default AURP port (387) will be bound without `-p`. + +## Bug reports? Feature requests? Complaints? Praise? + +You can contact me on the Fediverse at @DrJosh9000@cloudisland.nz, or email me at josh.deprez@gmail.com. diff --git a/main.go b/main.go index 4a8d31a..e5ecdc8 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,6 @@ import ( "os" "os/signal" "regexp" - "runtime/debug" "slices" "strings" "sync" @@ -104,7 +103,7 @@ const peerTableTemplate = ` {{$peer.LastReconnectAgo}} {{$peer.LastUpdateAgo}} {{$peer.LastSendAgo}} - {{$peer.SendRetries}} + {{$peer.SendRetries}} {{end}} @@ -117,7 +116,9 @@ var configFilePath = flag.String("config", "jrouter.yaml", "Path to configuratio func main() { // For some reason it occasionally panics and the panics have no traceback? - debug.SetTraceback("all") + // This didn't help: + // debug.SetTraceback("all") + // I think it's calling recover in a defer too broadly. flag.Parse() log.Println("jrouter")