Skip to content

Commit a82ca42

Browse files
feat: docker image for err-aprs-backend (#59)
This adds a Docker file, supporting config file, and CI for building a docker image for running an errbot with the APRS backend.
1 parent 22d1c29 commit a82ca42

File tree

7 files changed

+190
-11
lines changed

7 files changed

+190
-11
lines changed

.flake8

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/release-docker.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Runs after release-please creates a new release
2+
# Builds and pushes the docker images for the release
3+
name: Release Docker Images
4+
on:
5+
release:
6+
types: [released]
7+
8+
jobs:
9+
build-and-push-dockerimage:
10+
name: Buld and push dockerimage
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up QEMU
15+
uses: docker/setup-qemu-action@v2
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v2
18+
- name: Log in to the Container registry
19+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
20+
with:
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.THIS_PAT }}
24+
- name: Docker metadata
25+
uses: docker/metadata-action@v4
26+
id: meta
27+
with:
28+
images: |
29+
${{ github.repository }}
30+
ghcr.io/${{ github.repository }}
31+
tags: |
32+
type=raw,value=${{ github.ref_name }}
33+
# minimal (short sha)
34+
type=sha,prefix=
35+
# full length sha
36+
type=sha,format=long,prefix=
37+
- name: Build and push
38+
id: docker_build
39+
uses: docker/build-push-action@v3
40+
with:
41+
context: .
42+
file: Dockerfile
43+
push: true
44+
tags: ${{ steps.meta.outputs.tags }}
45+
labels: ${{ steps.meta.outputs.labels }}
46+
platforms: linux/amd64,linux/arm64
47+
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#registry-cache
48+
cache-from: type=gha
49+
cache-to: type=gha,mode=max

.github/workflows/test-docker.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Runs after release-please creates a new release
2+
# Builds and pushes the docker images for the release
3+
name: Test building Docker Images
4+
on:
5+
- push
6+
7+
8+
jobs:
9+
build-dockerimage:
10+
name: Buld dockerimage
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up QEMU
15+
uses: docker/setup-qemu-action@v2
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v2
18+
- name: Build and push
19+
id: docker_build
20+
uses: docker/build-push-action@v3
21+
with:
22+
context: .
23+
file: Dockerfile
24+
push: false
25+
platforms: linux/amd64,linux/arm64
26+
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#registry-cache
27+
cache-from: type=gha
28+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,5 @@ cython_debug/
162162
.python-version
163163

164164
test_errbot
165+
166+
.ruff_cache

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ARG ERRBOT_VERSION=6.2.0
2+
from python:3.11-slim as builder
3+
4+
5+
COPY .github/workflows/constraints.txt /constraints.txt
6+
RUN pip install --upgrade --constraint /constraints.txt pip poetry
7+
COPY ./ /app
8+
WORKDIR /app
9+
RUN poetry build
10+
11+
from python:3.11-slim
12+
ARG ERRBOT_VERSION=6.2.0
13+
14+
COPY --from=builder /app/dist/*.whl /
15+
16+
RUN pip install --no-cache-dir errbot==$ERRBOT_VERSION err_aprs_backend-*-py3-none-any.whl --force-reinstall && \
17+
rm -rf /err_aprs_backend-*-py3-none-any.whl && \
18+
mkdir /errbot && cd /errbot && \
19+
errbot --init && \
20+
rm -rf /errbot/plugins/err-example/
21+
COPY --from=builder /app/docker/config.py /errbot/config.py
22+
23+
WORKDIR /errbot
24+
ENTRYPOINT [ "errbot" ]

docker/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Docker
2+
3+
The Docker image for err-aprs-backed is hosted in ghcr.io
4+
5+
## Environment Variables
6+
7+
Every [Config option](../CONFIG.md) has a corresponding environment variable.
8+
9+
Lists and tuples are comma separated strings.
10+
11+
## Config Choices
12+
13+
Only ACLS, CommandNotFoundFilter, VersionChecker, and Webserver core plugins are running (this causes an error in the logs on startup, ignore it).
14+
The other core plugins are not optimized for APRS due to either allowing an unauthenticated user to configure the bot, or due to message length.
15+
16+
SUPPRESS_CMD_NOT_FOUND is set to true, this means the bot will just not respond to messages it doesn't recognize as a command.
17+
18+
BOT_PREFIX_OPTIONAL_ON_CHAT is set to true, this means that commands can be run with the prefix
19+
20+
## Plugins
21+
22+
Plugins can be added to /errbot/plugins or you can reconfigure the directory by setting BOT_PLUGIN_DIR
23+
24+
## Data
25+
26+
Data by default is in /errbot/data, but you can mount a volume to store your data permanently and not lose state between container restarts.

docker/config.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import logging
2+
import os
3+
import sys
4+
5+
logger = logging.getLogger(__name__)
6+
# This is a minimal configuration to get you started with the Text mode.
7+
# If you want to connect Errbot to chat services, checkout
8+
# the options in the more complete config-template.py from here:
9+
# https://raw.githubusercontent.com/errbotio/errbot/master/errbot/config-template.py
10+
11+
BACKEND = "APRS" # Errbot will start in text mode (console only mode) and will answer commands from there.
12+
13+
BOT_DATA_DIR = os.environ.get("BOT_DATA_DIR", "/errbot/data")
14+
BOT_EXTRA_PLUGIN_DIR = os.environ.get("BOT_PLUGIN_DIR", "/errbot/plugins")
15+
BOT_EXTRA_BACKEND_DIR = os.environ.get("BOT_BACKEND_DIR", "/errbot/backend-plugins")
16+
17+
BOT_LOG_FILE = None
18+
BOT_LOG_LEVEL = logging.getLevelName(os.environ.get("LOG_LEVEL", "INFO").upper())
19+
20+
__callsign = os.environ.get("APRS_CALLSIGN", None)
21+
__password = os.environ.get("APRS_PASSWORD", None)
22+
if __callsign is None:
23+
logger.fatal("APRS_CALLSIGN environment variable is not set")
24+
sys.exit(1)
25+
if __password is None:
26+
logger.fatal("APRS_PASSWORD environment variable is not set")
27+
sys.exit(1)
28+
29+
BOT_ADMINS = __callsign
30+
31+
BOT_IDENTITY = {"callsign": __callsign, "password": __password}
32+
33+
APRS_FROM_CALLSIGN = os.environ.get("APRS_FROM_CALLSIGN", __callsign)
34+
APRS_LISTENED_CALLSIGNS = tuple(os.environ.get("APRS_LISTENED_CALLSIGNS", "").strip(",").split(","))
35+
APRS_HELP_TEXT = os.environ.get("APRS_HELP_TEXT", "APRSBot,Errbot & err-aprs-backend")
36+
APRS_MAX_DROPPED_PACKETS = os.environ.get("APRS_MAX_DROPPED_PACKETS", "25")
37+
APRS_MAX_CACHED_PACKETS = os.environ.get("APRS_MAX_CACHED_PACKETS", "2048")
38+
APRS_MAX_AGE_CACHED_PACETS_SECONDS = os.environ.get("APRS_MAX_AGE_CACHED_PACETS_SECONDS", "3600")
39+
APRS_MESSAGE_MAX_RETRIES = os.environ.get("APRS_MESSAGE_MAX_RETRIES", "7")
40+
APRS_MESSAGE_RETRY_WAIT = os.environ.get("APRS_MESSAGE_RETRY_WAIT", "90")
41+
APRS_STRIP_NEWLINES = os.environ.get("APRS_STRIP_NEWLINES", "true")
42+
APRS_LANGUAGE_FILTER = os.environ.get("APRS_LANGUAGE_FILTER", "true")
43+
APRS_LANGUAGE_FILTER_EXTRA_WORDS = os.environ.get("APRS_LANGUAGE_FILTER_EXTRA_WORDS", "").strip(",").split(",")
44+
APRS_REGISTRY_ENABLED = os.environ.get("APRS_REGISTRY_ENABLED", "false").lower()
45+
APRS_REGISTRY_URL = os.environ.get("APRS_REGISTRY_URL", "https://aprs.hemna.com/api/v1/registry")
46+
APRS_REGISTRY_FREQUENCY_SECONDS = os.environ.get("APRS_REGISTRY_FREQUENCY_SECONDS", "3600")
47+
APRS_REGISTRY_DESCRIPTION = os.environ.get("APRS_REGISTRY_DESCRIPTION", "err-aprs-backend powered bot")
48+
APRS_REGISTRY_WEBSTIRE = os.environ.get("APRS_REGISTRY_WEBSTIRE", "")
49+
50+
BOT_PREFIX = os.environ.get("BOT_PREFIX", "!")
51+
BOT_PREFIX_OPTIONAL_ON_CHAT = True
52+
SUPPRESS_CMD_NOT_FOUND = True
53+
54+
# core plugins are not APRS optimized, only load ones that work
55+
# this causes some erros in the logs
56+
CORE_PLUGINS = (
57+
"ACLs",
58+
"CommandNotFoundFilter",
59+
"VersionChecker",
60+
"Webserver",
61+
)

0 commit comments

Comments
 (0)