Skip to content

Commit

Permalink
make it run rootless
Browse files Browse the repository at this point in the history
  • Loading branch information
Kariton committed Sep 9, 2023
1 parent f76e8b4 commit 4d347c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
31 changes: 22 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ services:
context: .
volumes:
- ./config:/etc/rss-ntfy
- histfiles:/root/:rw
- histfiles:/data:rw

volumes:
histfiles:

8 changes: 4 additions & 4 deletions rss-ntfy/rss-ntfy.py → rss-ntfy/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion rss-ntfy/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ services:
ntfy_tags: ['notes']

config:
cache_location: ~/.cache
cache_location: /data
run_on_startup: false
log_level: info
schedule: '*/30 * * * *'
Expand Down

0 comments on commit 4d347c7

Please sign in to comment.