Skip to content

Commit

Permalink
Fix Dockerfile, improve some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelwastaken committed Sep 10, 2023
1 parent d501fe8 commit 6647d6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM alpine:3.18

COPY . /apc
COPY . /sms

WORKDIR /apc
WORKDIR /sms

RUN apk update && \
apk add --no-cache python3 py3-pip && \
pip install --no-cache-dir -r requirements.txt

ENTRYPOINT ["python", "-u", "apc.py"]
ENTRYPOINT ["python", "-u", "sms.py"]
15 changes: 10 additions & 5 deletions sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,31 @@ def _load_env_vars(self):
try:
self.modem_ip = os.environ['MODEM_IP']
except ValueError:
log.exception('Missing MODEM_IP environment variable')
log.error('Missing MODEM_IP environment variable')
exit(1)

try:
self.modem_password = os.environ['MODEM_PASSWORD']
except ValueError:
log.exception('Missing MODEM_PASSWORD environment variable')
log.error('Missing MODEM_PASSWORD environment variable')
exit(1)

try:
self.smtp_sender = os.environ['SMTP_SENDER']
except ValueError:
log.exception('Missing SMTP_SENDER environment variable')
log.error('Missing SMTP_SENDER environment variable')
exit(1)

try:
self.smtp_recipients = os.environ['SMTP_RECIPIENTS'].split(',')
except ValueError:
log.exception('Missing SMTP_RECIPIENTS environment variable')
log.error('Missing SMTP_RECIPIENTS environment variable')
exit(1)
if len(self.smtp_recipients) == 0:
log.error('SMTP_RECIPIENTS environment variable must contain at least one recipient')
exit(1)

log.info(f'Loaded {len(self.smtp_recipients)} SMTP recipients: {self.smtp_recipients}')

# Optional SMTP settings
# Login is not required
Expand All @@ -93,7 +98,7 @@ def _load_env_vars(self):
try:
self.smtp_host = os.environ['SMTP_HOST']
except ValueError:
log.exception('Missing SMTP_HOST environment variable')
log.error('Missing SMTP_HOST environment variable')
exit(1)

# Get the SMTP port and ensure it's a valid port number
Expand Down

0 comments on commit 6647d6b

Please sign in to comment.