Skip to content

Commit 742d1ff

Browse files
committed
Easier deployment instructions.
1 parent a315f0c commit 742d1ff

14 files changed

+116
-69
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
venv

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
**/__pycache__
2-
venv
2+
venv
3+
/.idea/

Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.9
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY requirements.txt ./
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY . .
9+
10+
CMD [ "python", "./run.py" ]

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Requirements
2-
Python >=3.6
2+
Python >=3.6 (works with 3.9)
3+
4+
## Deployment on a docker host
5+
6+
Look at the [docker-compose.yml](docker-compose.yml) file, it starts an example LDAP server with data already loaded.
7+
8+
To run it just do:
9+
````
10+
docker-compose up --build
11+
````
12+
13+
The service is accessible at: [http://127.0.0.1:8080](http://127.0.0.1:8080)
14+
15+
Users are admin (password admin) and user (password user).
16+
17+
The email functionality is emulated with [maildev](https://github.com/maildev/maildev) that is accessible on port 1080:
18+
[http://127.0.0.1:1080](http://127.0.0.1:1080).
19+
20+
Sometimes the openldap server crashes for an unknown reason (it gets SIGKILLED somehow) and you have to restart it. As
21+
I am not using a dockerized LDAP server using this image in production, I didn't dig deeper into that.
22+
23+
## Deployment on bare-metal
324

425
Everything in requirements.txt
526

app/auth/email/__init__.py

+18-15
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,31 @@
44
from flask import url_for
55

66

7+
def validate_environment():
8+
return ('EMAIL_SERVER' in os.environ) & ('EMAIL_LOGIN' in os.environ) & ('EMAIL_PASSWORD' in os.environ) & (
9+
'EMAIL_FROM_NAME' in os.environ)
10+
11+
712
def send_email(email, code):
8-
server = smtplib.SMTP(os.environ['EMAIL_SERVER'], 587)
9-
server.starttls()
13+
server = smtplib.SMTP(os.environ['EMAIL_SERVER'], os.environ['EMAIL_PORT'])
14+
if os.environ['EMAIL_TLS'] != "False": # We have to be REALLY explicit
15+
server.starttls()
1016

1117
server.login(os.environ['EMAIL_LOGIN'], os.environ['EMAIL_PASSWORD'])
1218

13-
msg = """From: {} <{}>
14-
To: <{}>
15-
Subject: Password Reset for {}
19+
msg = f"""From: {os.environ['EMAIL_NAME']} <{os.environ['EMAIL_FROM']}>
20+
To: <{email}>
21+
Subject: Password Reset for {os.environ['SITE_NAME']}
1622
1723
1824
Hello!
1925
20-
Here is the reset code for your account on GFPAuth.
26+
Here is the reset code for your account on {os.environ['SITE_NAME']}.
2127
22-
Please go to {}{}?authcode={}
28+
Please go to {os.environ['SITE_URL']}{url_for('password.reset')}?authcode={code}
2329
24-
Thanks.""".format(os.environ['EMAIL_FROM_NAME'], os.environ['EMAIL_FROM_MAIL'],
25-
os.environ['SITE_NAME'],
26-
email,
27-
os.environ['SITE_URL'],
28-
url_for('password.reset'),
29-
code)
30-
31-
server.sendmail(os.environ['EMAIL_FROM_MAIL'], email, msg)
30+
Thanks."""
31+
32+
print(f"Sending a password reset for email: {email}")
33+
server.sendmail(os.environ['EMAIL_FROM'], email, msg)
34+
server.close()

create_venv.sh

-3
This file was deleted.

docker-compose.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
services:
2+
ldap:
3+
build: tests/openldap_container/
4+
environment:
5+
- DEBUG_LEVEL=1
6+
- DOMAIN=test.nprod.net
7+
- ORGANIZATION="Test Instance LDAP"
8+
- PASSWORD=1234567890
9+
volumes:
10+
- ./tests/openldap_container/data:/var/restore
11+
restart: always
12+
mailserver:
13+
image: maildev/maildev:2.0.0-beta3
14+
environment:
15+
- MAILDEV_INCOMING_USER=emailuser
16+
- MAILDEV_INCOMING_PASS=emailpassword
17+
ports:
18+
- 1080:1080
19+
service:
20+
build: .
21+
environment:
22+
- LDAP_HOST=ldap
23+
- LDAP_PORT=389
24+
- SECRET_KEY=foo
25+
- WTF_CSRF_SECRET_KEY=bar
26+
- MANAGER_USER=admin
27+
- MANAGER_PW=1234567890
28+
- MANAGER_PATH=dc=test,dc=nprod,dc=net
29+
- DC=dc=test,dc=nprod,dc=net
30+
- OU=ou=Users,dc=test,dc=nprod,dc=net
31+
- EMAIL_SERVER=mailserver
32+
- EMAIL_LOGIN=emailuser
33+
- EMAIL_PASSWORD=emailpassword
34+
- EMAIL_PORT=1025
35+
- EMAIL_NAME=LDAP Test instance
36+
- EMAIL_FROM=test@test.com
37+
- EMAIL_TLS=False
38+
- SITE_NAME=LDAP Test instance
39+
- SITE_URL=http://127.0.0.1:8080
40+
- DEBUG=True
41+
- PORT=8080
42+
- HOST=0.0.0.0
43+
ports:
44+
- 8080:8080

prepare_venv.sh

-4
This file was deleted.

run.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import os
22

3-
if 'WTF_CSRF_SECRET_KEY' not in os.environ:
4-
raise ArgumentError("Please set a SECRET string into the WTF_CSRF_SECRET_KEY environment variable")
5-
if 'SECRET_KEY' not in os.environ:
6-
raise ArgumentError("Please set another SECRET string into SECRET_KEY environment variable")
7-
if 'DC' not in os.environ:
8-
raise ArgumentError("Please set the DC into DC environment variable")
9-
if 'OU' not in os.environ:
10-
raise ArgumentError("Please set the OU into OU environment variable")
3+
environment_errors = {
4+
"WTF_CSRF_SECRET_KEY": "Please set a SECRET string into the WTF_CSRF_SECRET_KEY environment variable",
5+
"SECRET_KEY": "Please set a SECRET string different from the CSRF one into SECRET_KEY environment variable",
6+
"DC": "Please set the DC into DC environment variable such as: dc=test,dc=nprod,dc=net",
7+
"OU": "Please set the OU group of users into OU environment variable such as: ou=Users,dc=test,dc=nprod,dc=net"
8+
}
9+
10+
for key, error in environment_errors.items():
11+
if key not in os.environ:
12+
raise Exception(error)
13+
1114
from app import app
1215

13-
app.run(debug=os.environ['DEBUG'] == "True", port=8086, host='0.0.0.0')
16+
port = os.getenv("PORT", 8080)
17+
host = os.getenv("HOST", "0.0.0.0")
18+
19+
app.run(debug=os.environ['DEBUG'] == "True", port=port, host=host)

run_test_instance.sh

-22
This file was deleted.

start_test_ldap_server.sh

-14
This file was deleted.

tests/openldap_container/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM mwaeckerlin/openldap
2+
COPY test_data.ldif /var/restore/
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
File renamed without changes.

0 commit comments

Comments
 (0)