Skip to content

Commit

Permalink
Dockerized Faculty Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ssilverm committed Mar 30, 2021
1 parent 414c979 commit cb65910
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 49 deletions.
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.dockerignore
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
venv*
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.log
.git
*.template
.env*
fake-s3
15 changes: 15 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
TOOL_TITLE=Faculty Tools
THEME_DIR=
API_URL=https://example.com/
SECRET_KEY=CHANGEME
LTI_KEY=CHANGEME
LTI_SECRET=CHANGEME
OAUTH2_URI=https://127.0.0.1:9001/oauthlogin
OAUTH2_ID=CHANGEME
OAUTH2_KEY=CHANGEME
GOOGLE_ANALYTICS=GA-000000
CONFIG=config.DevelopmentConfig
DATABASE_URI=mysql://root:secret@db/faculty_tools

REQUIREMENTS=test_requirements.txt

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# config/settings
logs
settings.py
whitelist.json
.env

# local theming
themes/*
Expand Down
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM tiangolo/uwsgi-nginx-flask:python3.7
ARG REQUIREMENTS
RUN apt-get update && apt-get -y install libffi-dev gcc python3-dev libffi-dev libssl-dev libxml2-dev libxmlsec1-dev libxmlsec1-openssl
RUN apt-get -y install ca-certificates
WORKDIR /app
COPY requirements.txt /app/
COPY test_requirements.txt /app/
RUN echo $REQUIREMENTS
RUN pip install -r $REQUIREMENTS
COPY ./ /app/
68 changes: 27 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

# Documentation for Faculty Tools

## Settings
## Setting up Faculty Tools with Docker & Docker-Compose

Create a new `settings.py` file from the template
First clone and setup the repo.

```sh
cp settings.py.template settings.py
git clone git@github.com:ucfopen/faculty-tools.git
cp whitelist.json.template whitelist.json
cp .env.template .env
mkdir logs
touch logs/faculty-tools.log
```

Edit `settings.py` to configure the application. All fields are required,
Edit `.env` to configure the application. All fields are required,
unless specifically noted.

## Developer Key
Expand Down Expand Up @@ -57,67 +61,49 @@ Add the tools you want instructors and faculty to see to `whitelist.json`.
]
```

## Virtual Environment

Create a new virtual environment.

```sh
virtualenv env
```

Activate the environment.

```sh
source env/bin/activate
```

Install everything:

```sh
pip install -r requirements.txt
```

## Create DB

Change directory into the project folder. Create the database in python shell:
We need to generate the database and tables for faculty tools to run properly. The MySQL docker image automatically creates the user, password, and database name set in the `docker-compose.yml` file.

```sh
from lti import db
docker-compose run lti python
from main import db
db.create_all()
```

If you want to look at your users table in the future, you can do so in the
python shell:

```python
from lti import Users
docker-compose run lti python
from main import Users
Users.query.all()
```

## Environment Variables

Set the flask app to `lti.py` and debug to true.
## Run the App

It's time to use docker-compose to bring up the application.

```sh
export FLASK_APP=lti.py
export FLASK_DEBUG=1
docker-compose up -d
```

Alternatively, you can run the setup script to simultaneously setup environment
variables and the virtual environment.
Go to the /xml page, [http://127.0.0.1:9001/xml](http://127.0.0.1:9001/xml) by default

```sh
source setup.sh
```
Copy the xml, install it into a course.

## Run the App
## View the Logs

Run the lti script while your virtual environment is active.
To view the logs while the application is running use this docker command:

```sh
flask run
docker-compose logs -f
```

Go to the /xml page, [http://0.0.0.0:5000/xml](http://0.0.0.0:5000/xml) by default
## Stopping the App

Copy the xml, install it into a course.
To shutdown Faculty Tools
```sh
docker-compose down
```
18 changes: 13 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import settings

import os

class Config(object):
# make the warning shut up until Flask-SQLAlchemy v3 comes out
SQLALCHEMY_TRACK_MODIFICATIONS = True
SQLALCHEMY_DATABASE_URI = settings.select_db("Config")

PYLTI_CONFIG = settings.PYLTI_CONFIG

Expand All @@ -14,14 +13,16 @@ class Config(object):
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_SAMESITE = "None"

SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URI")



class BaseConfig(object):
DEBUG = False
TESTING = False

# make the warning shut up until Flask-SQLAlchemy v3 comes out
SQLALCHEMY_TRACK_MODIFICATIONS = True
SQLALCHEMY_DATABASE_URI = settings.select_db("BaseConfig")

PYLTI_CONFIG = settings.PYLTI_CONFIG

Expand All @@ -31,16 +32,23 @@ class BaseConfig(object):
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_SAMESITE = "None"

SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URI")



class DevelopmentConfig(BaseConfig):
DEBUG = True
TESTING = True

SQLALCHEMY_DATABASE_URI = settings.select_db("DevelopmentConfig")
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URI")




class TestingConfig(BaseConfig):
DEBUG = False
TESTING = True

SQLALCHEMY_DATABASE_URI = settings.select_db("TestingConfig")
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URI")


35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.1'

services:
lti:
build:
context: .
args:
- "REQUIREMENTS=${REQUIREMENTS}"
ports:
- "9001:80"
env_file:
- .env
environment:
- MODULE_NAME=app
depends_on:
- db

db:
image: mysql:5.7
volumes:
- ft_dbdata:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: faculty_tools
MYSQL_USER: root
MYSQL_PASSWORD: secret
ports:
- "33061:3306"
volumes:
ft_dbdata: {}




File renamed without changes.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
canvasapi==0.15.0
Flask==1.1.1
Flask-SQLAlchemy==2.4.1
Flask-SQLAlchemy==2.5.1
mysqlclient
-e git+https://github.com/ucfcdl/pylti.git@roles#egg=PyLTI
git+https://github.com/ucfcdl/pylti.git@roles#egg=PyLTI
requests==2.22.0
Werkzeug>=1.0.1 # Chrome 80 SameSite fix
55 changes: 55 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
# Title of the tool. Appears in the <title> element, headers, and configuration XML
TOOL_TITLE = os.environ.get("TOOL_TITLE", "Faculty Tools")

# Which theme directory to use. Leave blank for default.
THEME_DIR = os.environ.get("THEME_DIR", "")

# Canvas instance URL. ex: https://example.instructure.com/
BASE_URL = os.environ.get("API_URL")
API_URL = BASE_URL + "api/v1/"

# Secret key to sign Flask sessions with. KEEP THIS SECRET!
secret_key = os.environ.get("SECRET_KEY")

# LTI consumer key and shared secret
CONSUMER_KEY = os.environ.get("LTI_KEY")
SHARED_SECRET = os.environ.get("LTI_SECRET")

# Configuration for pylti library. Uses the above key and secret
PYLTI_CONFIG = {
"consumers": {
CONSUMER_KEY: {
"secret": SHARED_SECRET
}
},
# Custom configurable roles
"roles": {
"staff": [
"urn:lti:instrole:ims/lis/Administrator",
"Instructor",
"ContentDeveloper",
"urn:lti:role:ims/lis/TeachingAssistant",
]
},
}

# The "Oauth2 Redirect URI" that you provided to Instructure.
oauth2_uri = os.environ.get("OAUTH2_URI") # ex. 'https://localhost:5000/oauthlogin'
# The Client_ID Instructure gave you
oauth2_id = os.environ.get("OAUTH2_ID")
# The Secret Instructure gave you
oauth2_key = os.environ.get("OAUTH2_KEY")

# Logging configuration
LOG_MAX_BYTES = 1024 * 1024 * 5 # 5 MB
LOG_BACKUP_COUNT = 2
ERROR_LOG = "logs/faculty-tools.log"

whitelist = "whitelist.json"

# Google Analytics Tracking ID (optional)
GOOGLE_ANALYTICS = os.environ.get("GOOGLE_ANALYTICS", "GA-")


configClass = os.environ.get("CONFIG", "config.DevelopmentConfig")

0 comments on commit cb65910

Please sign in to comment.