From 9b7140e65001fa51388897987de1bf1f82f013cb Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sat, 3 May 2025 19:18:32 +0100 Subject: [PATCH 01/16] add docker instructions and examples --- Dockerfile | 14 ++++++++++++ docker/Dockerfile | 19 ++++++++++++++++ docker/Dockerfile.dist | 21 +++++++++++++++++ docker/README.md | 48 +++++++++++++++++++++++++++++++++++++++ docker/docker-compose.yml | 29 +++++++++++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 Dockerfile create mode 100644 docker/Dockerfile create mode 100644 docker/Dockerfile.dist create mode 100644 docker/README.md create mode 100644 docker/docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..32da7e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.13-alpine + +RUN pip --no-cache-dir --disable-pip-version-check --no-input -q install rns + +RUN mkdir /config + +RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns +RUN chown rns:rns /config + +USER rns:rns + +VOLUME ["/config"] + +ENTRYPOINT ["/usr/local/bin/rnsd", "--config", "/config"] diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..e0f1b24 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.13-alpine + +ENV PIP_ROOT_USER_ACTION=ignore +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 +ENV PIP_NO_CACHE_DIR=1 +RUN pip install rns + +RUN mkdir /config + +RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns dialout +RUN chown rns:rns /config + +USER rns:rns + +VOLUME ["/config"] + +ENV PYTHONUNBUFFERED=1 + +ENTRYPOINT ["/usr/local/bin/rnsd", "--config", "/config"] diff --git a/docker/Dockerfile.dist b/docker/Dockerfile.dist new file mode 100644 index 0000000..c99d314 --- /dev/null +++ b/docker/Dockerfile.dist @@ -0,0 +1,21 @@ +FROM python:3.13-alpine + +ADD dist/rns-*.whl /tmp/ + +ENV PIP_ROOT_USER_ACTION=ignore +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 +ENV PIP_NO_CACHE_DIR=1 +RUN pip install /tmp/rns-*.whl + +RUN mkdir /config + +RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns dialout +RUN chown rns:rns /config + +USER rns:rns + +VOLUME ["/config"] + +ENV PYTHONUNBUFFERED=1 + +ENTRYPOINT ["/usr/local/bin/rnsd", "--config", "/config"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..0098c7f --- /dev/null +++ b/docker/README.md @@ -0,0 +1,48 @@ +# Docker Images + +Docker resources Reticulum service and tooling + +## End-user + +As an end-user you can make use of the `Dockerfile` to create a simple docker image based on the latest `rns` package available in [PyPi](https://pypi.org/project/rns/) + +### Building + +To build the image: + +- Copy the `Dockerfile` to a directory and in that directory run: + - `docker build -t reticulum:latest .` + +- From the root of this repository run: + - `docker build -t reticulum:latest -f docker/Dockerfile .` + +### Running + +#### Docker Run +You can run the container in various ways, a quick way to test would be interactively: + +- Create a directory to hold the configuration and other files - `mkdir config` +- Start the container - `docker run --rm --name reticulum -v ./config:/config -it reticulum:latest` + +This will create a container named `reticulum`, mount the config directory to the directory you created above in your current working directory (`./config`) and automatically delete que container (`--rm`) when you detach from the session (files in the config directory will be retained) + +You can edit the config file at `./config/config` to configure rns as usual + +Once the container is running, you can use other rns tools via `docker exec`: + +`docker exec -it reticulum rnpath` + + +#### Docker Compose + +You can also use the included example `docker-compose.yml` file to manage the container in a more automated way. It has some comments but if you are not familiar with it, it is probably a good idea to read the [official `docker compose` docs](https://docs.docker.com/compose/) + + +## Developer + +The file `Dockerfile.dist` is meant to be used for CI, its similar to the end-user Dockerfile except that it will grab and install wheel files from the `/dist` directory instead +This could be used in this order: +- `make build_wheel` +- Build the container with `Dockerfile.dist` + - Via github workflows + - Manually `docker build -t reticulum:latest -f docker/Dockerfile.dist .` diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..410efd2 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,29 @@ +services: + reticulum: + container_name: reticulum + image: reticulum:latest + restart: unless-stopped + # Mount the config directory on the host in the same location as the docker-compose.yml + # to allow data persistency + volumes: + - ./config:/config:rw + # Define ports to expose, for example a TCP Listener + ports: + - "4242:4242/tcp" + networks: + - reticulum + # Define resource limits, useful if more services exist on the same host + # to avoid accidental resource contention, monitor and adjust as needed + deploy: + resources: + limits: + memory: "200M" + +# We define a custom network to allow easy communication between containers, +# for example if you want to run a nomadnet node and make use of the reticulum +# running in this container, you can add nomadnet container to this same network +# and use the service name as the hostname (eg: "reticulum") +# see: https://docs.docker.com/compose/how-tos/networking/#use-a-pre-existing-network +networks: + reticulum: + name: reticulum From a00af3301059d6d0356f98ce035006dbe854c6dd Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sat, 3 May 2025 21:17:53 +0100 Subject: [PATCH 02/16] add docker build action --- .github/workflows/build.yml | 33 ++++++++++++++++++++++++++++++--- Dockerfile | 14 -------------- docker/Dockerfile.dist | 2 +- 3 files changed, 31 insertions(+), 18 deletions(-) delete mode 100644 Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9cf0727..82e82d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,12 +2,12 @@ name: Build Reticulum on: push: - branches: + branches: - '*' tags: - "[0-9]+.[0-9]+.[0-9]+*" pull_request: - branches: + branches: - master paths-ignore: - .gitignore @@ -16,7 +16,7 @@ on: permissions: contents: write -concurrency: +concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true @@ -94,3 +94,30 @@ jobs: generate_release_notes: true prerelease: ${{ contains(github.ref, '-') }} fail_on_unmatched_files: true + + build-containers-release: + needs: release + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + environment: ${{ contains(github.ref, '-') && 'development' || 'production' }} + steps: + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + path: .artifacts + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6, linux/386, linux/ppc64le, linux/s390x, linux/riscv64 + push: true + tags: lbatalha/reticulum:${{ github.ref_name }} diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 32da7e0..0000000 --- a/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM python:3.13-alpine - -RUN pip --no-cache-dir --disable-pip-version-check --no-input -q install rns - -RUN mkdir /config - -RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns -RUN chown rns:rns /config - -USER rns:rns - -VOLUME ["/config"] - -ENTRYPOINT ["/usr/local/bin/rnsd", "--config", "/config"] diff --git a/docker/Dockerfile.dist b/docker/Dockerfile.dist index c99d314..0406a65 100644 --- a/docker/Dockerfile.dist +++ b/docker/Dockerfile.dist @@ -1,6 +1,6 @@ FROM python:3.13-alpine -ADD dist/rns-*.whl /tmp/ +ADD .artifacts/package/rns-*.whl /tmp/ ENV PIP_ROOT_USER_ACTION=ignore ENV PIP_DISABLE_PIP_VERSION_CHECK=1 From b6a02edc88601a77083eefc4ec16f91bbed48fc2 Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sat, 3 May 2025 21:24:22 +0100 Subject: [PATCH 03/16] fix dockerfile path --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 82e82d8..4f7fd7a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -118,6 +118,7 @@ jobs: - name: Build and push uses: docker/build-push-action@v6 with: + file: docker/Dockerfile.dist platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6, linux/386, linux/ppc64le, linux/s390x, linux/riscv64 push: true tags: lbatalha/reticulum:${{ github.ref_name }} From c09153dbc36901a1cf918e6874f29f182f6349d9 Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sat, 3 May 2025 22:00:09 +0100 Subject: [PATCH 04/16] add matrix strategy for multi-platform builds --- .github/workflows/build.yml | 95 +++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f7fd7a..5ca4e9b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,8 @@ name: Build Reticulum +env: + REGISTRY_IMAGE: ${{ github.repository_owner }}/reticulum + on: push: branches: @@ -99,8 +102,25 @@ jobs: needs: release if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + - linux/arm/v7 + - linux/arm/v6 + - linux/386 + - linux/ppc64le + - linux/riscv64 + - linux/s390x environment: ${{ contains(github.ref, '-') && 'development' || 'production' }} steps: + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: lbatalha/reticulum:${{ github.ref_name }} - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: @@ -115,10 +135,75 @@ jobs: - uses: actions/download-artifact@v4 with: path: .artifacts - - name: Build and push + # - name: Build and push + # uses: docker/build-push-action@v6 + # with: + # file: docker/Dockerfile.dist + # platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6, linux/386, linux/ppc64le + # push: true + # tags: ${{ github.repository_owner }}/reticulum:${{ github.ref_name }} + - name: Build and push by digest + id: build uses: docker/build-push-action@v6 with: - file: docker/Dockerfile.dist - platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6, linux/386, linux/ppc64le, linux/s390x, linux/riscv64 - push: true - tags: lbatalha/reticulum:${{ github.ref_name }} + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + tags: ${{ env.REGISTRY_IMAGE }} + outputs: type=image,push-by-digest=true,name-canonical=true,push=true + + - name: Export digest + run: | + mkdir -p ${{ runner.temp }}/digests + digest="${{ steps.build.outputs.digest }}" + touch "${{ runner.temp }}/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: ${{ runner.temp }}/digests/* + if-no-files-found: error + retention-days: 1 + + container-manifest-merge: + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + needs: + - build-containers-release + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: ${{ runner.temp }}/digests + pattern: digests-* + merge-multiple: true + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Create manifest list and push + working-directory: ${{ runner.temp }}/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} From aaa5bd2af259fed38df37d7b8d70da7bd4f9818a Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sat, 3 May 2025 22:03:25 +0100 Subject: [PATCH 05/16] fix dockerfile path --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5ca4e9b..1cf4448 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -146,6 +146,7 @@ jobs: id: build uses: docker/build-push-action@v6 with: + file: docker/Dockerfile.dist platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} tags: ${{ env.REGISTRY_IMAGE }} From 488e81aad5cf3cb81c50d8564bf8d91bf82dcb8a Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sat, 3 May 2025 22:03:25 +0100 Subject: [PATCH 06/16] fix dockerfile path --- docker/Dockerfile.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile.dist b/docker/Dockerfile.dist index 0406a65..38f7526 100644 --- a/docker/Dockerfile.dist +++ b/docker/Dockerfile.dist @@ -1,6 +1,6 @@ FROM python:3.13-alpine -ADD .artifacts/package/rns-*.whl /tmp/ +ADD .artifacts/package/dist/rns-*.whl /tmp/ ENV PIP_ROOT_USER_ACTION=ignore ENV PIP_DISABLE_PIP_VERSION_CHECK=1 From bf6559de05882ecd47ed4be341ca3b88146e9b57 Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sat, 3 May 2025 22:03:25 +0100 Subject: [PATCH 07/16] fix dockerfile path --- .github/workflows/build.yml | 49 +++++++++++++++++++++---------------- .gitignore | 1 + docker/Dockerfile.release | 25 +++++++++++++++++++ 3 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 docker/Dockerfile.release diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1cf4448..11793c8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: Build Reticulum env: - REGISTRY_IMAGE: ${{ github.repository_owner }}/reticulum + REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/reticulum on: push: @@ -24,18 +24,18 @@ concurrency: cancel-in-progress: true jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.x - - run: make test + # test: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - name: Set up Python + # uses: actions/setup-python@v5 + # with: + # python-version: 3.x + # - run: make test package: - needs: test + #needs: test if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest environment: ${{ contains(github.ref, '-') && 'development' || 'production' }} @@ -102,6 +102,8 @@ jobs: needs: release if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest + permissions: + packages: write strategy: fail-fast: false matrix: @@ -110,25 +112,25 @@ jobs: - linux/arm64 - linux/arm/v7 - linux/arm/v6 - - linux/386 - - linux/ppc64le - - linux/riscv64 - - linux/s390x environment: ${{ contains(github.ref, '-') && 'development' || 'production' }} steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Docker meta id: meta uses: docker/metadata-action@v5 with: - images: lbatalha/reticulum:${{ github.ref_name }} + images: ${{ env.REGISTRY_IMAGE }} - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + # - name: Set up QEMU + # uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - uses: actions/checkout@v4 @@ -138,15 +140,18 @@ jobs: # - name: Build and push # uses: docker/build-push-action@v6 # with: + # context: .git st # file: docker/Dockerfile.dist - # platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6, linux/386, linux/ppc64le + # platforms: linux/amd64,linux/arm64 # push: true - # tags: ${{ github.repository_owner }}/reticulum:${{ github.ref_name }} + # tags: ${{ env.REGISTRY_IMAGE }} + - name: Build and push by digest id: build uses: docker/build-push-action@v6 with: - file: docker/Dockerfile.dist + context: . + file: docker/Dockerfile.release platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} tags: ${{ env.REGISTRY_IMAGE }} @@ -169,6 +174,8 @@ jobs: container-manifest-merge: if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest + permissions: + packages: write needs: - build-containers-release steps: diff --git a/.gitignore b/.gitignore index 0b6903d..da30404 100755 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ tests/rnsconfig/storage tests/rnsconfig/logfile* *.data *.result +.vscode diff --git a/docker/Dockerfile.release b/docker/Dockerfile.release new file mode 100644 index 0000000..ec50403 --- /dev/null +++ b/docker/Dockerfile.release @@ -0,0 +1,25 @@ +FROM python:3.13-alpine as build + +RUN apk add --no-cache build-base linux-headers libffi-dev libressl-dev cargo + +ENV PIP_ROOT_USER_ACTION=ignore +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 +ENV PIP_NO_CACHE_DIR=1 +RUN pip install rns + +FROM python:3.13-alpine + +COPY --from=build /usr/local/bin/ /usr/local/bin/ + +RUN mkdir /config + +RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns dialout +RUN chown rns:rns /config + +USER rns:rns + +VOLUME ["/config"] + +ENV PYTHONUNBUFFERED=1 + +ENTRYPOINT ["/usr/local/bin/rnsd", "--config", "/config"] From 744f6b55e90d8e2bc2ca1477323e04421ee76f9c Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sun, 4 May 2025 00:31:16 +0100 Subject: [PATCH 08/16] test docker builds for all pushes and prs --- .github/workflows/build.yml | 17 ++++++----------- docker/Dockerfile | 8 +++++++- docker/Dockerfile.dist | 21 --------------------- docker/Dockerfile.release | 6 ++++-- 4 files changed, 17 insertions(+), 35 deletions(-) delete mode 100644 docker/Dockerfile.dist diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11793c8..fb00ad4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -99,8 +99,8 @@ jobs: fail_on_unmatched_files: true build-containers-release: - needs: release - if: startsWith(github.ref, 'refs/tags/') + #needs: test + #if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest permissions: packages: write @@ -129,6 +129,7 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + # # Uncomment to use QEMU emulation, if rarer architectures are needed # - name: Set up QEMU # uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx @@ -137,14 +138,6 @@ jobs: - uses: actions/download-artifact@v4 with: path: .artifacts - # - name: Build and push - # uses: docker/build-push-action@v6 - # with: - # context: .git st - # file: docker/Dockerfile.dist - # platforms: linux/amd64,linux/arm64 - # push: true - # tags: ${{ env.REGISTRY_IMAGE }} - name: Build and push by digest id: build @@ -172,7 +165,7 @@ jobs: retention-days: 1 container-manifest-merge: - if: startsWith(github.ref, 'refs/tags/') + #if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest permissions: packages: write @@ -203,6 +196,8 @@ jobs: images: ${{ env.REGISTRY_IMAGE }} tags: | type=ref,event=tag + type=ref,event=pr + type=ref,event=push type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} diff --git a/docker/Dockerfile b/docker/Dockerfile index e0f1b24..449e58c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,10 +1,16 @@ -FROM python:3.13-alpine +FROM python:3.13-alpine AS build + +RUN apk add --no-cache build-base linux-headers libffi-dev libressl-dev cargo ENV PIP_ROOT_USER_ACTION=ignore ENV PIP_DISABLE_PIP_VERSION_CHECK=1 ENV PIP_NO_CACHE_DIR=1 RUN pip install rns +FROM python:3.13-alpine + +COPY --from=build /usr/local/bin/ /usr/local/bin/ + RUN mkdir /config RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns dialout diff --git a/docker/Dockerfile.dist b/docker/Dockerfile.dist deleted file mode 100644 index 38f7526..0000000 --- a/docker/Dockerfile.dist +++ /dev/null @@ -1,21 +0,0 @@ -FROM python:3.13-alpine - -ADD .artifacts/package/dist/rns-*.whl /tmp/ - -ENV PIP_ROOT_USER_ACTION=ignore -ENV PIP_DISABLE_PIP_VERSION_CHECK=1 -ENV PIP_NO_CACHE_DIR=1 -RUN pip install /tmp/rns-*.whl - -RUN mkdir /config - -RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns dialout -RUN chown rns:rns /config - -USER rns:rns - -VOLUME ["/config"] - -ENV PYTHONUNBUFFERED=1 - -ENTRYPOINT ["/usr/local/bin/rnsd", "--config", "/config"] diff --git a/docker/Dockerfile.release b/docker/Dockerfile.release index ec50403..414732b 100644 --- a/docker/Dockerfile.release +++ b/docker/Dockerfile.release @@ -1,11 +1,13 @@ -FROM python:3.13-alpine as build +FROM python:3.13-alpine AS build RUN apk add --no-cache build-base linux-headers libffi-dev libressl-dev cargo +ADD .artifacts/package/rns-*.whl /tmp/ + ENV PIP_ROOT_USER_ACTION=ignore ENV PIP_DISABLE_PIP_VERSION_CHECK=1 ENV PIP_NO_CACHE_DIR=1 -RUN pip install rns +RUN pip install /tmp/rns-*.whl FROM python:3.13-alpine From 440b45c93b932f8b5afa0e13e6ce5c11e97756aa Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sun, 4 May 2025 00:31:16 +0100 Subject: [PATCH 09/16] test docker builds for all pushes and prs --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fb00ad4..7853a73 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,7 +36,7 @@ jobs: package: #needs: test - if: startsWith(github.ref, 'refs/tags/') + #if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest environment: ${{ contains(github.ref, '-') && 'development' || 'production' }} steps: @@ -99,7 +99,7 @@ jobs: fail_on_unmatched_files: true build-containers-release: - #needs: test + needs: package #if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest permissions: From 7cdff284ad858b48acd93d4e9cdc7551abcd28ba Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sun, 4 May 2025 00:31:16 +0100 Subject: [PATCH 10/16] test docker builds for all pushes and prs --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7853a73..1d62518 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -110,8 +110,8 @@ jobs: platform: - linux/amd64 - linux/arm64 - - linux/arm/v7 - - linux/arm/v6 + # - linux/arm/v7 + # - linux/arm/v6 environment: ${{ contains(github.ref, '-') && 'development' || 'production' }} steps: - name: Prepare @@ -197,7 +197,7 @@ jobs: tags: | type=ref,event=tag type=ref,event=pr - type=ref,event=push + type=ref,event=branch type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} From 6c4a699918df0808fc83559e925cbfc3eea713e1 Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sun, 4 May 2025 00:31:16 +0100 Subject: [PATCH 11/16] test docker builds for all pushes and prs --- .github/workflows/build.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1d62518..069dde9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,19 +24,18 @@ concurrency: cancel-in-progress: true jobs: - # test: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - name: Set up Python - # uses: actions/setup-python@v5 - # with: - # python-version: 3.x - # - run: make test + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.x + - run: make test package: - #needs: test - #if: startsWith(github.ref, 'refs/tags/') + needs: test runs-on: ubuntu-latest environment: ${{ contains(github.ref, '-') && 'development' || 'production' }} steps: @@ -100,7 +99,6 @@ jobs: build-containers-release: needs: package - #if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest permissions: packages: write @@ -129,7 +127,7 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # # Uncomment to use QEMU emulation, if rarer architectures are needed + # # Uncomment to use QEMU emulation, if niche architectures are needed # - name: Set up QEMU # uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx @@ -165,7 +163,6 @@ jobs: retention-days: 1 container-manifest-merge: - #if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest permissions: packages: write From a17d20bded46596c170a2f7dd4f57c687155dfb1 Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sun, 4 May 2025 01:37:56 +0100 Subject: [PATCH 12/16] add armv6 and v7 container builds --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 069dde9..3545485 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -108,8 +108,8 @@ jobs: platform: - linux/amd64 - linux/arm64 - # - linux/arm/v7 - # - linux/arm/v6 + - linux/arm/v7 + - linux/arm/v6 environment: ${{ contains(github.ref, '-') && 'development' || 'production' }} steps: - name: Prepare From 7dfa6ee596b3332ea306903cf8f7e7d16a31b49c Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sun, 4 May 2025 15:20:07 +0100 Subject: [PATCH 13/16] tweak docker files --- docker/Dockerfile | 2 +- docker/Dockerfile.release | 2 +- docker/README.md | 20 +++++++++++--------- docker/docker-compose.yml | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 449e58c..e9cea31 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,7 +9,7 @@ RUN pip install rns FROM python:3.13-alpine -COPY --from=build /usr/local/bin/ /usr/local/bin/ +COPY --from=build /usr/local/ /usr/local/ RUN mkdir /config diff --git a/docker/Dockerfile.release b/docker/Dockerfile.release index 414732b..d1c118b 100644 --- a/docker/Dockerfile.release +++ b/docker/Dockerfile.release @@ -11,7 +11,7 @@ RUN pip install /tmp/rns-*.whl FROM python:3.13-alpine -COPY --from=build /usr/local/bin/ /usr/local/bin/ +COPY --from=build /usr/local/ /usr/local/ RUN mkdir /config diff --git a/docker/README.md b/docker/README.md index 0098c7f..99b4ae1 100644 --- a/docker/README.md +++ b/docker/README.md @@ -4,11 +4,14 @@ Docker resources Reticulum service and tooling ## End-user -As an end-user you can make use of the `Dockerfile` to create a simple docker image based on the latest `rns` package available in [PyPi](https://pypi.org/project/rns/) +As an end-user you can either: -### Building +- grab prebuilt docker images from the github container registry @ `ghcr.io/markqvist/reticulum:latest` +- use of the `Dockerfile` to create a simple docker image based on the latest `rns` package available at [PyPi](https://pypi.org/project/rns/) -To build the image: +### Building from `Dockerfile` + +To build the image, choose one: - Copy the `Dockerfile` to a directory and in that directory run: - `docker build -t reticulum:latest .` @@ -24,6 +27,8 @@ You can run the container in various ways, a quick way to test would be interact - Create a directory to hold the configuration and other files - `mkdir config` - Start the container - `docker run --rm --name reticulum -v ./config:/config -it reticulum:latest` +Replace the image name to match either the one you built or pre-built github versions. + This will create a container named `reticulum`, mount the config directory to the directory you created above in your current working directory (`./config`) and automatically delete que container (`--rm`) when you detach from the session (files in the config directory will be retained) You can edit the config file at `./config/config` to configure rns as usual @@ -40,9 +45,6 @@ You can also use the included example `docker-compose.yml` file to manage the co ## Developer -The file `Dockerfile.dist` is meant to be used for CI, its similar to the end-user Dockerfile except that it will grab and install wheel files from the `/dist` directory instead -This could be used in this order: -- `make build_wheel` -- Build the container with `Dockerfile.dist` - - Via github workflows - - Manually `docker build -t reticulum:latest -f docker/Dockerfile.dist .` +The file `Dockerfile.release` is meant to be used for CI, its similar to the end-user Dockerfile except that it will grab and install wheel files from the artifacts generated by the `package` job in the build workflow. + +There are image builds available for both releases and pushes to branches to facilitate quick testing. diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 410efd2..f05db10 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,7 +1,7 @@ services: reticulum: container_name: reticulum - image: reticulum:latest + image: ghcr.io/markqvist/reticulum:latest restart: unless-stopped # Mount the config directory on the host in the same location as the docker-compose.yml # to allow data persistency From 78bead8b2d67f3ed82bda06a4d589888d53a6fe2 Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sun, 4 May 2025 16:22:49 +0100 Subject: [PATCH 14/16] improve image efficiency --- docker/Dockerfile | 11 ++++++++--- docker/Dockerfile.release | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e9cea31..d956d97 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,6 @@ -FROM python:3.13-alpine AS build +ARG python_version=3.13 + +FROM python:${python_version}-alpine AS build RUN apk add --no-cache build-base linux-headers libffi-dev libressl-dev cargo @@ -7,9 +9,12 @@ ENV PIP_DISABLE_PIP_VERSION_CHECK=1 ENV PIP_NO_CACHE_DIR=1 RUN pip install rns -FROM python:3.13-alpine +FROM python:${python_version}-alpine +ARG python_version -COPY --from=build /usr/local/ /usr/local/ +# Only copy the necessary files from the build stage, to improve layer efficiency +COPY --from=build /usr/local/bin/ /usr/local/bin/ +COPY --from=build /usr/local/lib/python${python_version}/site-packages/ /usr/local/lib/python${python_version}/site-packages/ RUN mkdir /config diff --git a/docker/Dockerfile.release b/docker/Dockerfile.release index d1c118b..ac2c56f 100644 --- a/docker/Dockerfile.release +++ b/docker/Dockerfile.release @@ -1,4 +1,6 @@ -FROM python:3.13-alpine AS build +ARG python_version=3.13 + +FROM python:${python_version}-alpine AS build RUN apk add --no-cache build-base linux-headers libffi-dev libressl-dev cargo @@ -9,9 +11,12 @@ ENV PIP_DISABLE_PIP_VERSION_CHECK=1 ENV PIP_NO_CACHE_DIR=1 RUN pip install /tmp/rns-*.whl -FROM python:3.13-alpine +FROM python:${python_version}-alpine +ARG python_version -COPY --from=build /usr/local/ /usr/local/ +# Only copy the necessary files from the build stage, to improve layer efficiency +COPY --from=build /usr/local/bin/ /usr/local/bin/ +COPY --from=build /usr/local/lib/python${python_version}/site-packages/ /usr/local/lib/python${python_version}/site-packages/ RUN mkdir /config From ada43e799bceaf07228f8c93dca759abda6508cb Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Sun, 4 May 2025 17:36:40 +0100 Subject: [PATCH 15/16] only copy rns binaries for extra efficiency --- docker/Dockerfile | 2 +- docker/Dockerfile.release | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index d956d97..928169f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,7 +13,7 @@ FROM python:${python_version}-alpine ARG python_version # Only copy the necessary files from the build stage, to improve layer efficiency -COPY --from=build /usr/local/bin/ /usr/local/bin/ +COPY --from=build /usr/local/bin/rn* /usr/local/bin/ COPY --from=build /usr/local/lib/python${python_version}/site-packages/ /usr/local/lib/python${python_version}/site-packages/ RUN mkdir /config diff --git a/docker/Dockerfile.release b/docker/Dockerfile.release index ac2c56f..97b8f7e 100644 --- a/docker/Dockerfile.release +++ b/docker/Dockerfile.release @@ -15,7 +15,7 @@ FROM python:${python_version}-alpine ARG python_version # Only copy the necessary files from the build stage, to improve layer efficiency -COPY --from=build /usr/local/bin/ /usr/local/bin/ +COPY --from=build /usr/local/bin/rn* /usr/local/bin/ COPY --from=build /usr/local/lib/python${python_version}/site-packages/ /usr/local/lib/python${python_version}/site-packages/ RUN mkdir /config From 9c36d55518ba1e348bc2000974206242a55ad4c8 Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Fri, 16 May 2025 15:01:27 +0100 Subject: [PATCH 16/16] remove irrelevant dialout user, add docker-compose device mount documentation --- docker/Dockerfile | 12 ++++++------ docker/Dockerfile.release | 2 +- docker/docker-compose.yml | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 928169f..cb61452 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,23 +2,23 @@ ARG python_version=3.13 FROM python:${python_version}-alpine AS build -RUN apk add --no-cache build-base linux-headers libffi-dev libressl-dev cargo +#RUN apk add --no-cache build-base linux-headers libffi-dev libressl-dev cargo ENV PIP_ROOT_USER_ACTION=ignore ENV PIP_DISABLE_PIP_VERSION_CHECK=1 ENV PIP_NO_CACHE_DIR=1 RUN pip install rns -FROM python:${python_version}-alpine -ARG python_version +#FROM python:${python_version}-alpine +#ARG python_version # Only copy the necessary files from the build stage, to improve layer efficiency -COPY --from=build /usr/local/bin/rn* /usr/local/bin/ -COPY --from=build /usr/local/lib/python${python_version}/site-packages/ /usr/local/lib/python${python_version}/site-packages/ +#COPY --from=build /usr/local/bin/rn* /usr/local/bin/ +#COPY --from=build /usr/local/lib/python${python_version}/site-packages/ /usr/local/lib/python${python_version}/site-packages/ RUN mkdir /config -RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns dialout +RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns RUN chown rns:rns /config USER rns:rns diff --git a/docker/Dockerfile.release b/docker/Dockerfile.release index 97b8f7e..184ab02 100644 --- a/docker/Dockerfile.release +++ b/docker/Dockerfile.release @@ -20,7 +20,7 @@ COPY --from=build /usr/local/lib/python${python_version}/site-packages/ /usr/loc RUN mkdir /config -RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns dialout +RUN addgroup -S rns --gid 1000 && adduser -S rns --uid 1000 -G rns RUN chown rns:rns /config USER rns:rns diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f05db10..b267631 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -3,11 +3,17 @@ services: container_name: reticulum image: ghcr.io/markqvist/reticulum:latest restart: unless-stopped + # You can mount devices, make sure to add the user to the group id + # which has rw access to the device on the host + devices: + - /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0:/dev/ttyACM0 + group_add: + - 986 # Mount the config directory on the host in the same location as the docker-compose.yml # to allow data persistency volumes: - ./config:/config:rw - # Define ports to expose, for example a TCP Listener + # Define ports to expose, for example a default TCP Listener ports: - "4242:4242/tcp" networks: