diff --git a/.forgejo/workflows/container-build.yaml b/.forgejo/workflows/container-build.yaml new file mode 100644 index 0000000..8908050 --- /dev/null +++ b/.forgejo/workflows/container-build.yaml @@ -0,0 +1,29 @@ +on: [push] +jobs: + build-container: + runs-on: docker + container: + image: library/docker:dind + steps: + - run: apk add --no-cache nodejs git + - name: login to container registry + run: echo "${{ secrets.PACKAGE_PUBLISH_TOKEN }}" | docker login --username finn --password-stdin git.janky.solutions + - name: gather metadata for container image tags + uses: https://github.com/docker/metadata-action@v5 + id: meta + with: + images: git.janky.solutions/finn/matrix-bridge-meshtastic + tags: | + type=schedule + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=ref,event=branch + type=sha + - name: build container image + uses: docker/build-push-action@v6 + with: + file: Containerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + push: ${{ github.ref == 'refs/heads/main' }} diff --git a/.gitignore b/.gitignore index bdfd3d7..853b77e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -matrix-meshtastic-bridge.json -matrix-meshtastic-bridge.db +matrix-bridge-meshtastic.json +matrix-bridge-meshtastic.db diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..afcdd6f --- /dev/null +++ b/Containerfile @@ -0,0 +1,8 @@ +FROM library/golang:1.23 AS build +ADD . /bridge +WORKDIR /bridge +RUN go build ./cmd/matrix-bridge-meshtastic + +FROM gcr.io/distroless/base-debian12:nonroot +COPY --from=build /bridge/matrix-bridge-meshtastic /usr/bin/matrix-bridge-meshtastic +ENTRYPOINT ["/usr/bin/matrix-bridge-meshtastic"] diff --git a/bridge/bridge.go b/bridge/bridge.go index 4311c0a..dca14b2 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -89,10 +89,9 @@ func handlePacket(ctx context.Context, packet *protobufs.MeshPacket) error { sourceString = fmt.Sprintf("%x", packet.From) } - logrus.WithField("source", sourceString).Debug("handling incoming meshtastic node") - switch payload.Decoded.Portnum { case protobufs.PortNum_TEXT_MESSAGE_APP: + logrus.WithField("source", sourceString).Info("handling incoming meshtastic -> matrix message") return matrix.SendMessage(ctx, fmt.Sprintf("text from %s: %s (snr: %f, rssi: %d, hop limit: %d, hop start: %d)", sourceString, payload.Decoded.Payload, packet.RxSnr, packet.RxRssi, packet.HopLimit, packet.HopStart)) default: logrus.WithField("type", protobufs.PortNum_name[int32(payload.Decoded.Portnum)]).Debug("ignoring unknown app payload") diff --git a/config/config.go b/config/config.go index a383a3c..ae24f83 100644 --- a/config/config.go +++ b/config/config.go @@ -28,7 +28,7 @@ type Matrix struct { } var C = Config{ - Database: "matrix-meshtastic-bridge.db", + Database: "matrix-bridge-meshtastic.db", Meshtastic: Meshtastic{ RequestTimeout: time.Second * 5, PollingInterval: time.Millisecond * 500, @@ -36,7 +36,14 @@ var C = Config{ } func Load() error { - return load("matrix-meshtastic-bridge.json") + for _, filename := range []string{"/etc/matrix-bridge-meshtastic.json", "matrix-bridge-meshtastic.json"} { + err := load(filename) + if err != nil && !os.IsNotExist(err) { + return err + } + } + + return nil } func load(filename string) error { diff --git a/matrix-meshtastic-bridge.sample.json b/matrix-bridge-meshtastic.sample.json similarity index 100% rename from matrix-meshtastic-bridge.sample.json rename to matrix-bridge-meshtastic.sample.json