diff --git a/Dockerfile b/Dockerfile index 976825f..7ed3e91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,27 @@ -FROM python:3.11-alpine +### COMPILE ### +FROM python:3.11-alpine AS compile-image -RUN mkdir -p /rss-ntfy /etc/rss-ntfy -WORKDIR /rss-ntfy +RUN python -m venv /opt/venv +# Make sure we use the virtualenv: +ENV PATH="/opt/venv/bin:$PATH" -ADD ./rss-ntfy/* /rss-ntfy/ -COPY requirements.txt /rss-ntfy/ +COPY requirements.txt . +RUN pip install --upgrade --requirement requirements.txt -RUN pip install --no-cache-dir --upgrade pip -RUN pip install --no-cache-dir -r requirements.txt -ENV PYTHONUNBUFFERED=1 +### BUILD ### + +FROM python:3.11-alpine AS build-image +RUN adduser -D rss-ntfy +USER rss-ntfy +WORKDIR /home/rss-ntfy + +ADD --chown=rss-ntfy ./rss-ntfy/ ./rss-ntfy/ +COPY --from=compile-image --chown=rss-ntfy /opt/venv /opt/venv -CMD ["python", "-u", "/rss-ntfy/rss-ntfy.py"] +RUN chmod +x ./rss-ntfy/bot.py + +# Make sure we use the virtualenv: +ENV PATH="/opt/venv/bin:$PATH" +ENV PYTHONUNBUFFERED=1 +CMD ./rss-ntfy/bot.py diff --git a/docker-compose.yml b/docker-compose.yml index 3c86e27..568c985 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,8 +7,7 @@ services: context: . volumes: - ./config:/etc/rss-ntfy - - histfiles:/root/:rw + - histfiles:/data:rw volumes: histfiles: - diff --git a/rss-ntfy/rss-ntfy.py b/rss-ntfy/bot.py similarity index 99% rename from rss-ntfy/rss-ntfy.py rename to rss-ntfy/bot.py index 6e69bcd..a832684 100755 --- a/rss-ntfy/rss-ntfy.py +++ b/rss-ntfy/bot.py @@ -81,7 +81,7 @@ def update_config(init=False): global CONFIG, DEFAULT_CONFIG config_path = "/etc/rss-ntfy/config.yml" - schema_path = "schema.json" + schema_path = "./rss-ntfy/schema.json" try: custom_config = load_config(config_path) @@ -134,7 +134,7 @@ def update_config(init=False): def init_config(): global CONFIG, DEFAULT_CONFIG - default_config = "default.yml" + default_config = "./rss-ntfy/default.yml" defaults = load_config(default_config) DEFAULT_CONFIG = defaults @@ -532,13 +532,13 @@ def main(): cache_path = config.get('cache_location') cache_location = os.path.expanduser(cache_path) - Path(f"{cache_location}/rss-ntfy/").mkdir(parents=True, exist_ok=True) + Path(f"{cache_location}/").mkdir(parents=True, exist_ok=True) for service_name, service_config in CONFIG['services'].items(): logger.info(f"service: {service_name}") logger.debug(f'"service_config": {json.dumps(service_config)}') - service_hist = f"{cache_location}/rss-ntfy/{service_name}_hist" + service_hist = f"{cache_location}/{service_name}_hist" Path(service_hist).touch(exist_ok=True) for feed_config in CONFIG['feeds'][service_name]: diff --git a/rss-ntfy/default.yml b/rss-ntfy/default.yml index 28ed6e5..f6a55a9 100644 --- a/rss-ntfy/default.yml +++ b/rss-ntfy/default.yml @@ -128,7 +128,7 @@ services: ntfy_tags: ['notes'] config: - cache_location: ~/.cache + cache_location: /data run_on_startup: false log_level: info schedule: '*/30 * * * *'