diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..666089a --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +#SERIAL_PORT = /dev/ttyUSB0 +NODE_IP = 192.168.253.162 +#NODE_BLE = +LAT = 47.73322 +LON = 12.11043 +RAD = 30 +# MC_HEADLESS = true +# MC_GUIONLY = true +#MC_MAPTILER_KEY = diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..c045c90 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,51 @@ +name: Docker Build and Push + +on: + push: + branches: [ "main", "master" ] + tags: [ 'v*.*.*' ] + workflow_dispatch: + +env: + REGISTRY: ghcr.io + # IMAGE_NAME musi być małymi literami. github.repository może zawierać wielkie litery. + # Dlatego w kroku budowania użyjemy metadanych, które to wyczyszczą. + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # Akcja automatycznie zamienia nazwy obrazów na małe litery. + tags: | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} + type=semver,pattern={{version}} + type=sha,format=short + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..721f3bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.11-slim + +WORKDIR /app + +# Deps +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + python3-dev \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt* ./ +RUN if [ -f requirements.txt ]; then pip install --no-cache-dir -r requirements.txt; fi + +COPY . . + +# Perms +RUN chmod +x entrypoint.sh + +# Entrypoint +ENTRYPOINT ["./entrypoint.sh"] diff --git a/README.md b/README.md index 84da19e..b2248f2 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,18 @@ This will: Stop the tool with `Ctrl+C`. +## Docker + +You can use Meshcore Reachability as a Docker container. + +Compose file is available in this repository. You can use it in Portainer Stack or directly using + +```bash +docker compose up -d +``` + +Remember to set your env vars! + ### Command line options From `--help` in `meshcore_reachability.py`: diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..96a98e4 --- /dev/null +++ b/compose.yml @@ -0,0 +1,20 @@ +services: + reachability: + image: ghcr.io/usrflo/meshcore-reachability:latest + container_name: meshcore-reachability + restart: unless-stopped + # If using serial: + # devices: + # - "/dev/ttyUSB0:/dev/ttyUSB0" + ports: + - "5342:5342" + environment: + #- SERIAL_PORT=/dev/ttyUSB0 + - NODE_IP=192.168.253.162 + - LAT=51.1234 # Twoja szeroko.. + - LON=20.2233 # Twoja d.ugo.. + - RAD=25 # Promie. w km + - MC_HEADLESS=false # Ustaw na true, je.li nie chcesz UI + #- MC_MAPTILER_KEY=your_api_key + volumes: + - /opt/meshcore-reachability:/app/data # Persist data \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..645fd4b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# entrypoint.sh + +ARGS="" + +if [ -n "$SERIAL_PORT" ]; then ARGS="$ARGS -p $SERIAL_PORT"; fi +if [ -n "$NODE_IP" ]; then ARGS="$ARGS -ip $NODE_IP"; fi +if [ -n "$NODE_BLE" ]; then ARGS="$ARGS --ble $NODE_BLE"; fi +if [ -n "$LAT" ]; then ARGS="$ARGS -lat $LAT"; fi +if [ -n "$LON" ]; then ARGS="$ARGS -lon $LON"; fi +if [ -n "$RAD" ]; then ARGS="$ARGS -rad $RAD"; fi +if [ "$MC_HEADLESS" = "true" ]; then ARGS="$ARGS --headless"; fi +if [ "$MC_GUIONLY" = "true" ]; then ARGS="$ARGS --guionly"; fi +if [ -n "$MC_MAPTILER_KEY" ]; then ARGS="$ARGS -ak $MC_MAPTILER_KEY"; fi + +# Uruchomienie aplikacji z przekazanymi argumentami +exec python meshcore_reachability.py $ARGS