Skip to content

Commit e6fca52

Browse files
authored
Merge pull request #1 from mohamedtaee/dev
Dev
2 parents 8c12f54 + 70173ff commit e6fca52

File tree

8 files changed

+41
-54
lines changed

8 files changed

+41
-54
lines changed

Dockerfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
FROM python:3.7-alpine
1+
FROM python:3.11.2-slim
22

3-
ADD requirements.txt .
3+
WORKDIR /app
44

5-
RUN apk add python3-dev build-base linux-headers pcre-dev && pip install --no-cache-dir -r requirements.txt
5+
COPY . /app
66

7-
# adding application files
8-
ADD . /webapp
7+
RUN pip install --upgrade pip
98

10-
# configure path /webapp to HOME-dir
11-
ENV HOME /webapp
12-
WORKDIR /webapp
9+
RUN pip install --no-cache-dir -r requirements.txt
1310

14-
ENTRYPOINT ["uwsgi"]
15-
CMD ["--http", "0.0.0.0:8080", "--wsgi-file", "wsgi.py", "--callable", "app", "--processes", "1", "--threads", "8"]
11+
EXPOSE 8080
12+
13+
ENV FLASK_APP=app
14+
ENV FLASK_ENV=production
15+
16+
CMD ["gunicorn", "--workers", "1", "--timeout", "5000", "--preload", "--bind", "0.0.0.0:8080", "wsgi:app"]

app/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
from config import config
33
from flask_moment import Moment
44

5-
65
moment = Moment()
76

87

98
def create_app(config_name):
109
app = Flask(__name__)
1110
app.config.from_object(config[config_name])
1211

12+
config[config_name].init_app(app)
13+
1314
config[config_name].init_app(app)
1415
moment.init_app(app)
1516

16-
from app.ui import ui as ui_blueprint
17-
app.register_blueprint(ui_blueprint)
17+
from app.ui import views as ui_views
18+
app.register_blueprint(ui_views.bp)
1819

19-
from app.api import api as api_blueprint
20-
app.register_blueprint(api_blueprint, url_prefix='/api')
20+
from app.api import endpoints as api_endpoints
21+
app.register_blueprint(api_endpoints.bp)
2122

2223
return app

app/api/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from flask import Blueprint
2-
3-
api = Blueprint('api', __name__)
4-
5-
from . import endpoints

app/api/endpoints.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import os
44
import flask
55

6-
from app.api import api
6+
bp = flask.Blueprint('api', __name__, url_prefix='/api')
77

88

9-
@api.route('/config/<name>', methods=['GET'])
9+
@bp.route('/config/<name>', methods=['GET'])
1010
def get_config(name: str):
1111
"""
1212
Reads the file with the corresponding name that was passed.
@@ -25,7 +25,7 @@ def get_config(name: str):
2525
return flask.render_template('config.html', name=name, file=_file), 200
2626

2727

28-
@api.route('/config/<name>', methods=['POST'])
28+
@bp.route('/config/<name>', methods=['POST'])
2929
def post_config(name: str):
3030
"""
3131
Accepts the customized configuration and saves it in the configuration file with the supplied name.
@@ -45,7 +45,7 @@ def post_config(name: str):
4545
return flask.make_response({'success': True}), 200
4646

4747

48-
@api.route('/domains', methods=['GET'])
48+
@bp.route('/domains', methods=['GET'])
4949
def get_domains():
5050
"""
5151
Reads all files from the configuration file directory and checks the state of the site configuration.
@@ -83,7 +83,7 @@ def get_domains():
8383
return flask.render_template('domains.html', sites_available=sites_available, sites_enabled=sites_enabled), 200
8484

8585

86-
@api.route('/domain/<name>', methods=['GET'])
86+
@bp.route('/domain/<name>', methods=['GET'])
8787
def get_domain(name: str):
8888
"""
8989
Takes the name of the domain configuration file and
@@ -116,7 +116,7 @@ def get_domain(name: str):
116116
return flask.render_template('domain.html', name=name, file=_file, enabled=enabled), 200
117117

118118

119-
@api.route('/domain/<name>', methods=['POST'])
119+
@bp.route('/domain/<name>', methods=['POST'])
120120
def post_domain(name: str):
121121
"""
122122
Creates the configuration file of the domain.
@@ -141,7 +141,7 @@ def post_domain(name: str):
141141
return response
142142

143143

144-
@api.route('/domain/<name>', methods=['DELETE'])
144+
@bp.route('/domain/<name>', methods=['DELETE'])
145145
def delete_domain(name: str):
146146
"""
147147
Deletes the configuration file of the corresponding domain.
@@ -168,7 +168,7 @@ def delete_domain(name: str):
168168
return flask.jsonify({'success': False}), 400
169169

170170

171-
@api.route('/domain/<name>', methods=['PUT'])
171+
@bp.route('/domain/<name>', methods=['PUT'])
172172
def put_domain(name: str):
173173
"""
174174
Updates the configuration file with the corresponding domain name.
@@ -191,7 +191,7 @@ def put_domain(name: str):
191191
return flask.make_response({'success': True}), 200
192192

193193

194-
@api.route('/domain/<name>/enable', methods=['POST'])
194+
@bp.route('/domain/<name>/enable', methods=['POST'])
195195
def enable_domain(name: str):
196196
"""
197197
Activates the domain in Nginx so that the configuration is applied.

app/ui/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from flask import Blueprint
2-
3-
ui = Blueprint('ui', __name__)
4-
5-
from . import views

app/ui/views.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
from app.ui import ui
2-
import flask
1+
from flask import Blueprint, current_app, render_template
32
import os
43

4+
bp = Blueprint('ui', __name__)
55

6-
@ui.route('/', methods=['GET'])
6+
7+
@bp.route('/', methods=['GET'])
78
def index():
89
"""
910
Delivers the home page of Nginx UI.
1011
1112
:return: Rendered HTML document.
1213
:rtype: str
1314
"""
14-
nginx_path = flask.current_app.config['NGINX_PATH']
15+
nginx_path = current_app.config['NGINX_PATH']
1516
config = [f for f in os.listdir(nginx_path) if os.path.isfile(os.path.join(nginx_path, f))]
16-
return flask.render_template('index.html', config=config)
17+
return render_template('index.html', config=config)

docker-compose.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
version: '3'
22
services:
3-
nginx-ui:
4-
container_name: nginx-ui
3+
flask-nginx-ui:
4+
container_name: flask-nginx-ui
55
build: .
6-
image: nginx-ui:latest
6+
image: flask-nginx-ui:latest
77
ports:
8-
- 8080:8080
8+
- "8080:8080"
99
volumes:
1010
- nginx:/etc/nginx
1111

1212
nginx:
1313
container_name: nginx
14-
image: nginx:1.18.0-alpine
14+
image: nginx:alpine3.19
1515
ports:
16-
- 80:80
16+
- "443:443"
1717
volumes:
1818
- nginx:/etc/nginx
1919

requirements.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
click==7.1.2
2-
Flask==1.1.2
3-
Flask-Moment==0.9.0
4-
itsdangerous==1.1.0
5-
Jinja2==2.11.3
6-
MarkupSafe==1.1.1
7-
pytz==2020.1
8-
uWSGI==2.0.18
9-
Werkzeug==1.0.1
1+
Flask~=3.0.3
2+
gunicorn~=22.0.0
3+
Flask-Moment~=1.0.5

0 commit comments

Comments
 (0)