From 0e4f31e7dc3e13778b986fde9843699e3becda43 Mon Sep 17 00:00:00 2001 From: Laura Batalha Date: Thu, 29 May 2025 17:19:01 +0100 Subject: [PATCH] Add Container image and github actions (#1) * add github workflow and dockerfile * fix dockerfile path * document docker usage in README * remove environment --- .github/workflows/build-container-image.yml | 135 ++++++++++++++++++++ Dockerfile | 28 ++++ LICENSE.md => LICENSE | 0 README.md | 15 ++- docker-compose.yaml | 7 + 5 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-container-image.yml create mode 100644 Dockerfile rename LICENSE.md => LICENSE (100%) create mode 100644 docker-compose.yaml diff --git a/.github/workflows/build-container-image.yml b/.github/workflows/build-container-image.yml new file mode 100644 index 0000000..8023c4f --- /dev/null +++ b/.github/workflows/build-container-image.yml @@ -0,0 +1,135 @@ +name: Build RNMon Container Images + +env: + REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/rnmon + +on: + push: + branches: + - '*' + tags: + - "[0-9]+.[0-9]+.[0-9]+*" + pull_request: + branches: + - master + paths-ignore: + - .gitignore + - LICENSE + - '*.example' + - '**.example' + +permissions: + contents: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-containers-release: + runs-on: ubuntu-latest + permissions: + packages: write + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + - linux/arm/v7 + - linux/arm/v6 + 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: ${{ 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 Docker Buildx + uses: docker/setup-buildx-action@v3 + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + path: .artifacts + + - name: Build and push by digest + id: build + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + 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: + runs-on: ubuntu-latest + permissions: + packages: write + 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=ref,event=pr + type=ref,event=branch + 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 }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9cf488f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +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 uv + +ENV UV_TOOL_DIR=/app +RUN uv tool install --compile-bytecode rnmon + +FROM python:${python_version}-alpine +ARG python_version + +# Only copy the necessary files from the build stage, to improve layer efficiency +COPY --from=build /app/rnmon /app + +RUN mkdir /config + +RUN addgroup -S app --gid 1000 && adduser -S app --uid 1000 -G app +RUN chown -R app:app /config /app + +USER app:app + +VOLUME ["/config"] + +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app/bin +ENTRYPOINT ["./python", "rnmon", "--rns-config", "/config/reticulum", "--config", "/config/scraping.yaml"] diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE diff --git a/README.md b/README.md index 1ec32e7..4ac7250 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ RNMon is a simple monitoring daemon designed to monitor the status of multiple R ## Installing -The package is available in [PyPI](https://pypi.org/project/rnmon/), install it with your python package manager of choice +### Package + +The package is available in [PyPI](https://pypi.org/project/rnmon/), install it with your python package manager of choice. I recommend using [`uv`](https://docs.astral.sh/uv/) since it cleanly manages an environment if you run or install it as a tool: @@ -17,6 +19,17 @@ Execute it simply: `uvx rnmon` Install it globally (but in its own environment): `uv tool install rnmon` and run `rnmon` +### Container + +There is a container image available at `ghcr.io/lbataha/rnmon`. +You can use the `latest` tag, or specify the version matching the git tag you want, there are also image builds available in github actions. + +The repo contains a `Dockerfile` and an example `docker-compose.yml`, but you can run it simply with: + +```shell +docker run --name rnmon -v /path/to/config:/config ghcr.io/lbataha/rnmon:latest +``` + ## Configuration Configure the daemon via `scraping.yaml`, the example config has comments explaining the options. diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..1e1c698 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,7 @@ +services: + rnmon: + container_name: rnmon + image: ghcr.io/lbatalha/rnmon:latest + restart: unless-stopped + volumes: + - ./config:/config:rw