From a9d7f142e7bacfc612f2f6e763e755ccc2a04268 Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Sat, 18 May 2024 18:56:22 +0200 Subject: [PATCH] Build an image and add it to compose --- Dockerfile | 14 ++++++++++++++ docker-compose.yaml | 8 ++++++++ hedgedoc-expire.py | 10 ++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4c53c6c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM docker.io/library/debian:12-slim AS builder +RUN apt-get update && \ + apt-get install --no-install-suggests --no-install-recommends --yes pipx +ENV PATH="/root/.local/bin:${PATH}" +RUN pipx install poetry +RUN pipx inject poetry poetry-plugin-bundle +WORKDIR /src +COPY . . +RUN poetry bundle venv --python=/usr/bin/python3 --only=main /venv + +FROM gcr.io/distroless/python3-debian12 +COPY --from=builder /venv /venv +COPY hedgedoc-expire.py / +ENTRYPOINT ["/venv/bin/python", "/hedgedoc-expire.py"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 53aaa75..388d716 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -44,6 +44,14 @@ services: depends_on: - database + hedgedoc-expire: + image: hedgedoc-expire + command: "-c -r .001 -n .001" + environment: + - "POSTGRES_HOSTNAME=database" + depends_on: + - database + volumes: database: {} diff --git a/hedgedoc-expire.py b/hedgedoc-expire.py index c2aedc3..21d4ce6 100644 --- a/hedgedoc-expire.py +++ b/hedgedoc-expire.py @@ -20,8 +20,14 @@ class Config: """ Get config from environment variables """ + self.postgres_hostname = getenv('POSTGRES_HOSTNAME', 'localhost') + self.postgres_username = getenv('POSTGRES_USERNAME', 'hedgedoc') + self.postgres_password = getenv('POSTGRES_PASSWORD', 'geheim') + self.postgres_database = getenv('POSTGRES_DATABASE', 'hedgedoc') + self.postgres_port = int(getenv('POSTGRES_PORT', '5432')) + self.smtp_hostname = getenv('SMTP_HOSTNAME', 'localhost') - self.smtp_port = getenv('SMTP_PORT', '587') + self.smtp_port = int(getenv('SMTP_PORT', '587')) self.smtp_username = getenv('SMTP_USERNAME', '') self.smtp_password = getenv('SMTP_PASSWORD', '') self.smtp_from = getenv('SMTP_FROM', '') @@ -191,7 +197,7 @@ if __name__ == '__main__': config = Config() mail = EmailSender(config.smtp_hostname, config.smtp_port, config.smtp_username, config.smtp_password, config.smtp_from) - with pgsql.Connection(("localhost", 5432), "hedgedoc", "geheim") as db: + with pgsql.Connection((config.postgres_hostname, config.postgres_port), config.postgres_username, config.postgres_password) as db: if args.check: check_revisions_to_be_expired(revisions_delta) check_notes_to_be_expired(notes_delta, config)