Build an image and add it to compose

This commit is contained in:
Stefan Bethke 2024-05-18 18:56:22 +02:00
parent 56641f66d5
commit a9d7f142e7
3 changed files with 30 additions and 2 deletions

14
Dockerfile Normal file
View file

@ -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"]

View file

@ -44,6 +44,14 @@ services:
depends_on: depends_on:
- database - database
hedgedoc-expire:
image: hedgedoc-expire
command: "-c -r .001 -n .001"
environment:
- "POSTGRES_HOSTNAME=database"
depends_on:
- database
volumes: volumes:
database: {} database: {}

View file

@ -20,8 +20,14 @@ class Config:
""" """
Get config from environment variables 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_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_username = getenv('SMTP_USERNAME', '')
self.smtp_password = getenv('SMTP_PASSWORD', '') self.smtp_password = getenv('SMTP_PASSWORD', '')
self.smtp_from = getenv('SMTP_FROM', '') self.smtp_from = getenv('SMTP_FROM', '')
@ -191,7 +197,7 @@ if __name__ == '__main__':
config = Config() config = Config()
mail = EmailSender(config.smtp_hostname, config.smtp_port, config.smtp_username, config.smtp_password, config.smtp_from) 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: if args.check:
check_revisions_to_be_expired(revisions_delta) check_revisions_to_be_expired(revisions_delta)
check_notes_to_be_expired(notes_delta, config) check_notes_to_be_expired(notes_delta, config)