Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerizing LTI templates #16

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.log
.git
.mypy_cache
.pytest_cache
.hypothesis%
5 changes: 5 additions & 0 deletions .env-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SECRET_FLASK=CHANGEME
LTI_KEY=CHANGEME
LTI_SECRET=CHANGEME
CONFIG=config.DevelopmentConfig
REQUIREMENTS=requirements.txt
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run Python Tests and Build Image

on:
push:
branches:
- issue/15-Dockerize
- develop
- master

env:
REQUIREMENTS: requirements.txt

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Python 3
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install coveralls
- name: Setup Repo
run: |
cp .env-template .env
- name: Run flake8
run: flake8
- name: Run black
run: black --check .
- name: Lint markdown files
uses: bewuethr/mdl-action@v1

- name: Load dotenv
uses: falti/[email protected]

- name: Environment Variables from Dotenv
uses: c-py/action-dotenv-to-setenv@v3

- name: Run unittests
run: coverage run -m unittest discover




133 changes: 133 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,136 @@ venv/
error.log
*.DS_STORE
test.db

# config/settings
logs

.env



# system
*.DS_Store

# database files
*.db

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
*.log.*
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
env2/
env3/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
1 change: 1 addition & 0 deletions .mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style "markdown-style.rb"
7 changes: 5 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
Thanks for being interested! Here's our guidelines to contributing to the templates.

## Get Set Up

- Check the issues to see if your problem has already been brought up.
- Submit a ticket if it hasn't. Be sure to be clear and give instructions on how to reproduce the issue you're having.

## Getting Your Hands Dirty

- Fork the repository.
- Please try not to work on master. Instead, create a new branch named after your issue and its number:

- `git checkout -b issue/number-brief-issue-description`

## Submit!
## Submit

- Push your changes.
- Submit a pull request.
- We will review your changes and try to respond in a timely manner.

That's it!
That's it!
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.7
ARG REQUIREMENTS

COPY ./requirements.txt /code/requirements.txt
RUN pip install --upgrade pip
RUN pip install -r /code/$REQUIREMENTS

WORKDIR /code
COPY ./ /code/
EXPOSE 3104
CMD ["gunicorn", "--conf", "gunicorn_conf.py", "--bind", "0.0.0.0:9001", "views:app"]
70 changes: 43 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,47 @@

## Setup

### Virtual Environment
Create a virtual environment that uses Python 2:
### Docker

```
virtualenv venv -p /usr/bin/python2.7
source venv/bin/activate
```

Install the dependencies from the requirements file.

```
pip install -r requirements.txt
```
We are going to be creating a Docker container that uses Python 3:

### Create your local settings file
Create settings.py from settings.py.template
#### Setup environment variables

```bash
cp .env-template .env
```
cp settings.py.template settings.py
```

Note: settings.py is alreay referenced in the .gitignore and multiple python files, if you want a different settings file name be sure to update the references.

#### Add your values to the settings file.
At a minimum, CONSUMER_KEY, SHARED_SECRET, and secret_key need to be input by the developer. The secret_key is used by Flask, but the CONSUMER_KEY and SHARED_SECRET will be used in setting up the LTI. For security purposes, it's best to have randomized keys. You can generate random keys in the command line by using os.urandom(24) and inputing the resulting values into the settings.py file:
Now you can begin editing the `.env` file. At a minimum, CONSUMER_KEY, SHARED_SECRET, and SECRET_FLASK need to be input by the developer. The SECRET_FLASK is used by Flask, but the CONSUMER_KEY and SHARED_SECRET will be used in setting up the LTI. For security purposes, it's best to have randomized keys. You can generate random keys in the command line by using os.urandom(24) and inputing the resulting values into the .env file:

```
```bash
import os
os.urandom(24)
```

### Run a Development Server
Here's how you run the flask app from the terminal:
#### Build and run Docker Container

```bash
docker-compose build
docker-compose up
```
export FLASK_APP=views.py
flask run

You should see something like this in your console:

```bash
[INFO] Starting gunicorn 20.1.0
[INFO] Listening at: http://0.0.0.0:9001 (1)
[INFO] Using worker: gthread
[INFO] Booting worker with pid: 11
```

Your server should now be and running.

### Open in a Browser
Your running server will be visible at [http://127.0.0.1:5000](http://127.0.0.1:5000)

Your running server will be visible at [http://127.0.0.1:9001](http://127.0.0.1:9001)

## Install LTI in Canvas

- Have the XML, consumer key, and secret ready.
- You can use the [XML Config Builder](https://www.edu-apps.org/build_xml.html) to build XML.
- Navigate to the course that you would like the LTI to be added to. Click Settings in the course navigation bar. Then, select the Apps tab. Near the tabs on the right side, click 'View App Configurations'. It should lead to a page that lists what LTIs are inside the course. Click the button near the tabs that reads '+ App'.
Expand All @@ -57,4 +56,21 @@ Your running server will be visible at [http://127.0.0.1:5000](http://127.0.0.1:
- Account Navigation (account-level navigation)
- User Navigation (user profile)

**Note**: If you're using Canvas, your version might be finicky about SSL certificates. Keep HTTP/HTTPS in mind when creating your XML and while developing your project. Some browsers will disable non-SSL LTI content until you enable it through clicking a shield in the browser bar or something similar.
**Note**: If you're using Canvas, your version might be finicky about SSL certificates. Keep HTTP/HTTPS in mind when creating your XML and while developing your project. Some browsers will disable non-SSL LTI content until you enable it through clicking a shield in the browser bar or something similar.

## Testing

The LTI Template comes with a pre written test suite. In order to run it make sure your .env key and secret match the tests.py key and secret.

### Run the test suite

```bash
docker-compose run lti --rm coverage run -m unittest discover
```

### Generate reports

```bash
docker-compose run lti --rm coverage report
docker-compose run lti --rm coverage html
```
Loading