Skip to content

Commit 72e37d9

Browse files
committed
Adding Docker Support
1 parent b579158 commit 72e37d9

File tree

7 files changed

+105
-74
lines changed

7 files changed

+105
-74
lines changed

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM python:3.6-stretch
2+
MAINTAINER Devin Matte <matted@csh.rit.edu>
3+
4+
RUN mkdir /opt/conditional
5+
6+
ADD requirements.txt /opt/conditional
7+
8+
WORKDIR /opt/conditional
9+
10+
RUN apt-get -yq update && \
11+
apt-get -yq install libsasl2-dev python-dev libldap2-dev libssl-dev && \
12+
pip install -r requirements.txt && \
13+
apt-get -yq clean all
14+
15+
ADD . /opt/conditional
16+
17+
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - && \
18+
apt-get -yq update && \
19+
apt-get -yq install nodejs npm && \
20+
npm install && \
21+
npm run production && \
22+
rm -rf node_modules && \
23+
apt-get -yq remove nodejs npm && \
24+
apt-get -yq clean all
25+
26+
CMD ["gunicorn", "conditional:app", "--bind=0.0.0.0:8080", "--access-logfile=-"]

conditional/__init__.py

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1+
# pylint: disable=wrong-import-order
2+
from ._version import __version__
3+
14
import os
2-
import subprocess
35
from datetime import datetime
6+
7+
import structlog
8+
from csh_ldap import CSHLDAP
49
from flask import Flask, redirect, request, render_template, g
5-
from flask_sqlalchemy import SQLAlchemy
610
from flask_migrate import Migrate
7-
from csh_ldap import CSHLDAP
8-
from raven import fetch_git_sha
11+
from flask_sqlalchemy import SQLAlchemy
912
from raven.contrib.flask import Sentry
10-
from raven.exceptions import InvalidGitRepository
11-
import structlog
13+
14+
from conditional import config
1215

1316
app = Flask(__name__)
1417

15-
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.py")
18+
app.config.from_object(config)
19+
if os.path.exists(os.path.join(os.getcwd(), "config.py")):
20+
app.config.from_pyfile(os.path.join(os.getcwd(), "config.py"))
1621

17-
app.config.from_pyfile(config)
1822
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
1923

20-
app.config["GIT_REVISION"] = subprocess.check_output(['git',
21-
'rev-parse',
22-
'--short',
23-
'HEAD']).decode('utf-8').rstrip()
24-
25-
2624
db = SQLAlchemy(app)
2725
migrate = Migrate(app, db)
2826
sentry = Sentry(app)
@@ -31,17 +29,20 @@
3129
app.config['LDAP_BIND_PW'],
3230
ro=app.config['LDAP_RO'])
3331

32+
3433
def start_of_year():
3534
start = datetime(datetime.today().year, 6, 1)
3635
if datetime.today() < start:
37-
start = datetime(datetime.today().year-1, 6, 1)
36+
start = datetime(datetime.today().year - 1, 6, 1)
3837
return start
3938

39+
4040
# pylint: disable=C0413
41-
from conditional.models.models import UserLog
41+
from .models.models import UserLog
42+
4243

4344
# Configure Logging
44-
def request_processor(logger, log_method, event_dict): # pylint: disable=unused-argument, redefined-outer-name
45+
def request_processor(logger, log_method, event_dict): # pylint: disable=unused-argument, redefined-outer-name
4546
if 'request' in event_dict:
4647
flask_request = event_dict['request']
4748
event_dict['user'] = flask_request.headers.get("x-webauth-user")
@@ -52,7 +53,7 @@ def request_processor(logger, log_method, event_dict): # pylint: disable=unused-
5253
return event_dict
5354

5455

55-
def database_processor(logger, log_method, event_dict): # pylint: disable=unused-argument, redefined-outer-name
56+
def database_processor(logger, log_method, event_dict): # pylint: disable=unused-argument, redefined-outer-name
5657
if 'request' in event_dict:
5758
if event_dict['method'] != 'GET':
5859
log = UserLog(
@@ -62,35 +63,35 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unused
6263
blueprint=event_dict['blueprint'],
6364
path=event_dict['path'],
6465
description=event_dict['event']
65-
)
66+
)
6667
db.session.add(log)
6768
db.session.flush()
6869
db.session.commit()
6970
del event_dict['request']
7071
return event_dict
7172

73+
7274
structlog.configure(processors=[
7375
request_processor,
7476
database_processor,
7577
structlog.processors.KeyValueRenderer()
76-
])
78+
])
7779

7880
logger = structlog.get_logger()
7981

80-
81-
from conditional.blueprints.dashboard import dashboard_bp # pylint: disable=ungrouped-imports
82-
from conditional.blueprints.attendance import attendance_bp
83-
from conditional.blueprints.major_project_submission import major_project_bp
84-
from conditional.blueprints.intro_evals import intro_evals_bp
85-
from conditional.blueprints.intro_evals_form import intro_evals_form_bp
86-
from conditional.blueprints.housing import housing_bp
87-
from conditional.blueprints.spring_evals import spring_evals_bp
88-
from conditional.blueprints.conditional import conditionals_bp
89-
from conditional.blueprints.member_management import member_management_bp
90-
from conditional.blueprints.slideshow import slideshow_bp
91-
from conditional.blueprints.cache_management import cache_bp
92-
from conditional.blueprints.co_op import co_op_bp
93-
from conditional.blueprints.logs import log_bp
82+
from .blueprints.dashboard import dashboard_bp # pylint: disable=ungrouped-imports
83+
from .blueprints.attendance import attendance_bp
84+
from .blueprints.major_project_submission import major_project_bp
85+
from .blueprints.intro_evals import intro_evals_bp
86+
from .blueprints.intro_evals_form import intro_evals_form_bp
87+
from .blueprints.housing import housing_bp
88+
from .blueprints.spring_evals import spring_evals_bp
89+
from .blueprints.conditional import conditionals_bp
90+
from .blueprints.member_management import member_management_bp
91+
from .blueprints.slideshow import slideshow_bp
92+
from .blueprints.cache_management import cache_bp
93+
from .blueprints.co_op import co_op_bp
94+
from .blueprints.logs import log_bp
9495

9596
app.register_blueprint(dashboard_bp)
9697
app.register_blueprint(attendance_bp)
@@ -106,7 +107,8 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unused
106107
app.register_blueprint(co_op_bp)
107108
app.register_blueprint(log_bp)
108109

109-
from conditional.util.ldap import ldap_get_member
110+
from .util.ldap import ldap_get_member
111+
110112

111113
@app.route('/<path:path>')
112114
def static_proxy(path):
@@ -118,6 +120,7 @@ def static_proxy(path):
118120
def default_route():
119121
return redirect('/dashboard')
120122

123+
121124
@app.errorhandler(404)
122125
@app.errorhandler(500)
123126
def route_errors(error):
@@ -149,15 +152,17 @@ def route_errors(error):
149152
error_desc = type(error).__name__
150153

151154
return render_template('errors.html',
152-
error=error_desc,
153-
error_code=code,
154-
event_id=g.sentry_event_id,
155-
public_dsn=sentry.client.get_public_dsn('https'),
156-
**data), int(code)
155+
error=error_desc,
156+
error_code=code,
157+
event_id=g.sentry_event_id,
158+
public_dsn=sentry.client.get_public_dsn('https'),
159+
**data), int(code)
160+
157161

158162
@app.cli.command()
159163
def zoo():
160164
from conditional.models.migrate import free_the_zoo
161165
free_the_zoo(app.config['ZOO_DATABASE_URI'])
162166

167+
163168
logger.info('conditional started')

conditional/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "1.6.1"

conditional/config.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from os import environ as env
2+
from conditional import __version__
3+
4+
# Flask config
5+
DEBUG = True if env.get("CONDITIONAL_DEBUG", "false").lower() == "true" else False
6+
HOST_NAME = env.get("CONDITIONAL_HOST_NAME", "conditional.csh.rit.edu")
7+
APP_NAME = "conditional"
8+
IP = env.get("CONDITIONAL_IP", "0.0.0.0")
9+
PORT = env.get("CONDITIONAL_PORT", 6969)
10+
11+
# DB Info
12+
SQLALCHEMY_DATABASE_URI = env.get("SQLALCHEMY_DATABASE_URI", "")
13+
14+
# LDAP config
15+
LDAP_RO = True if env.get("CONDITIONAL_LDAP_RO", "true").lower() == "true" else False
16+
LDAP_BIND_DN = env.get("CONDITIONAL_LDAP_BIND_DN", "cn=conditional,ou=Apps,dc=csh,dc=rit,dc=edu")
17+
LDAP_BIND_PW = env.get("CONDITIONAL_LDAP_BIND_PW", "")
18+
19+
# Sentry config
20+
# Do not set the DSN for local development
21+
SENTRY_CONFIG = {
22+
'dsn': env.get("CONDITIONAL_SENTRY_DSN", ""),
23+
'release': __version__,
24+
}
25+
26+
# General config
27+
DUES_PER_SEMESTER = env.get("CONDITIONAL_DUES_PER_SEMESTER", 80)

config.sample.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "conditional",
3-
"version": "1.0.0",
3+
"version": "1.6.1",
44
"description": "CSH Re-evaluation (MEGA_EVALS RE:RE:LOADED)",
55
"license": "MIT",
66
"homepage": "http://csh.rit.edu/",
77
"repository": {
88
"type": "git",
9-
"url": "git://github.com/csssuf/conditional.git"
9+
"url": "git://github.com/ComputerScienceHouse/conditional.git"
1010
},
1111
"bugs": {
12-
"url": "https://github.com/csssuf/conditional/issues"
12+
"url": "https://github.com/ComputerScienceHouse/conditional/issues"
1313
},
1414
"author": "Computer Science House",
1515
"engines": {
@@ -26,7 +26,7 @@
2626
},
2727
"dependencies": {
2828
"bootstrap": "^3.3.6",
29-
"bootstrap-material-datetimepicker": "github:T00rk/bootstrap-material-datetimepicker#gh-pages",
29+
"bootstrap-material-datetimepicker": "^2.7.3",
3030
"bootstrap-sass": "^3.3.6",
3131
"bootstrap-sweetalert": "^1.0.1",
3232
"csh-material-bootstrap": "1.0.0",
@@ -35,7 +35,7 @@
3535
"dropzone": "^4.3.0",
3636
"enumify": "^1.0.4",
3737
"jquery": "^3.1.0",
38-
"load-awesome": "github:danielcardoso/load-awesome",
38+
"load-awesome": "^1.1.0",
3939
"lodash": "4.13.1",
4040
"reveal.js": "^3.3.0",
4141
"selectize": "^0.12.2",

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ csh-ldap==1.2.4.dev41
66
Flask==0.12.2
77
Flask-Migrate==2.1.1
88
Flask-SQLAlchemy==2.3.2
9+
gunicorn==19.7.1
910
isort==4.2.15
1011
itsdangerous==0.24
1112
Jinja2==2.9.6

0 commit comments

Comments
 (0)