Skip to content

Commit

Permalink
feat: docker postfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulius Juzenas committed Jan 15, 2025
1 parent ba06fea commit 007fff5
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ nginx/config/*
config.production.json
ghost/data/*
!ghost/data/.gitkeep
api/nvdnew/settings/mail_settings.py
.DS_Store
postfix/.env
16 changes: 16 additions & 0 deletions api/nvdnew/settings/mail_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
EMAIL_HOST = 'postfix'

EMAIL_HOST_USER = ''

EMAIL_HOST_PASSWORD = ''

# Normally using port 25 is unsafe as it cannot be encrypted.
# However, all the traffic to port 25 will remain inside docker.
# After the traffic leaves docker through the mailserver, it will be on port 587.
EMAIL_PORT = '25'

EMAIL_USE_TLS = False

EMAIL_USE_SSL = False

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
13 changes: 0 additions & 13 deletions api/nvdnew/settings/mail_settings_default.py

This file was deleted.

12 changes: 12 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,17 @@ services:
- ./nginx/config:/config # Todo: Can this volume include the below?
- frontend-files:/frontend

postfix:
build:
context: ./postfix
ports:
- "587:587"
env_file:
- path: ./postfix/.env
required: true
volumes:
- postfix-spool:/var/spool/postfix # Volume for storing unset postfix emails

volumes:
frontend-files:
postfix-spool:
14 changes: 14 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,19 @@ services:
- ./nginx/config:/config # Todo: Can this volume include the below?
- frontend-files:/frontend

# Is postfix nessesary for tests? Do we actually use the tests? Do the tests even work?
# These are all good questions that I don't have the answer to and I'm too annoyed of this project to find out.
# I have included it here because why not.
postfix:
build:
context: ./postfix
ports:
- "587:587"
env_file:
- path: ./postfix/.env.default
required: true
- path: ./postfix/.env
required: false

volumes:
frontend-files:
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
- DJANGO_SETTINGS_MODULE=nvdnew.settings.dev
depends_on:
- postgres

frontend:
build:
context: ./frontend
Expand All @@ -30,10 +31,22 @@ services:
- ./frontend/src:/frontend/src
- ./frontend/static:/frontend/static
- ./frontend/test:/frontend/test

fileserver:
build: ./fileserver
ports:
- "9000:9000"
command: ["./main"]
volumes:
- ./fileserver/uploads:/root/uploads

postfix:
build:
context: ./postfix
ports:
- "587:587"
env_file:
- path: ./postfix/.env.default
required: true
- path: ./postfix/.env
required: false
8 changes: 8 additions & 0 deletions postfix/.env.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is only included as an example.
# You should create your own .env file with real values for prod!

SMTP_SERVER=smtp.some-provier.com
SMTP_PORT=587
SMTP_USERNAME=the username for the smtp server
SMTP_PASSWORD=a very secure password
SERVER_HOSTNAME=nettverksdagene.no
6 changes: 6 additions & 0 deletions postfix/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM juanluisbaptiste/postfix:latest

# Add a delay between every email sent
# Needed to avoid hitting the rate limit
# A bit hacky but it works :)
RUN echo -e "\ndefault_destination_rate_delay = 3s\n" >> /etc/postfix/main.cf

0 comments on commit 007fff5

Please sign in to comment.