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

Added Docker Setup Option #1121

Merged
merged 24 commits into from Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions Dockerfile
@@ -0,0 +1,32 @@
FROM jhuopensource/semesterly-base:latest

RUN mkdir /code
WORKDIR /code

# Just adding basics
# ADD ./requirements.txt /code/
# ADD ./package.json /code/

# Add everything
ADD . /code/


# Nginx moved out
# COPY ./build/semesterly-nginx.conf /etc/nginx/sites-available/
# RUN rm /etc/nginx/sites-enabled/*
# RUN ln -s /etc/nginx/sites-available/semesterly-nginx.conf /etc/nginx/sites-enabled
# RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Use environment based config
COPY ./build/local_settings.py /code/semesterly/local_settings.py

# Add parser script
COPY ./build/run_parser.sh /code/run_parser.sh

RUN pip install -r /code/requirements.txt
# This is needed on newer ubuntu
RUN pip install psycopg2-binary

RUN npm install
RUN npm run build

18 changes: 18 additions & 0 deletions build/local_settings.py
@@ -0,0 +1,18 @@
import os

DEBUG = True

TEMPLATE_DEBUG = DEBUG

# This configuration relies on environment variables for DB settings

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['DB_NAME'],
'USER': os.environ['DB_USER'],
'PASSWORD': os.environ['DB_PASSWORD'],
'HOST': os.environ['DB_HOST'],
'PORT': os.environ['DB_PORT'],
}
}
21 changes: 21 additions & 0 deletions build/run_parser.sh
@@ -0,0 +1,21 @@
#!/bin/bash

echo starting;
cd /code
# TODO: No params does not honor active-only semesters, this is hardcoded for now
/usr/bin/python manage.py ingest jhu --term Spring --years 2018;
/usr/bin/python manage.py digest jhu;


/usr/bin/python manage.py ingest jhu --term Fall --years 2018;
/usr/bin/python manage.py digest jhu;

/usr/bin/python manage.py ingest jhu --term Spring --years 2019;
/usr/bin/python manage.py digest jhu;


# Run all
#/usr/bin/python manage.py ingest jhu
#/usr/bin/python manage.py digest jhu

echo done;
18 changes: 18 additions & 0 deletions build/semesterly-base/Dockerfile
@@ -0,0 +1,18 @@
FROM ubuntu:bionic

ADD ./requirements_base.txt /tmp

RUN apt-get update && \
apt-get install -y \
python-pip \
libpq-dev \
libxml2-dev \
libxslt-dev \
git \
curl \
nginx && \
# Install node 8.x
curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
apt-get install -y nodejs && \
# This saves some build time by installing base requirements
pip install -r /tmp/requirements_base.txt
5 changes: 5 additions & 0 deletions build/semesterly-base/Readme.md
@@ -0,0 +1,5 @@
This builds the base image we use. To update:

docker build -t semesterly-base .
docker tag semesterly-base:latest jhuopensource/semesterly-base:latest
docker push jhuopensource/semesterly-base:latest
73 changes: 73 additions & 0 deletions build/semesterly-base/requirements_base.txt
@@ -0,0 +1,73 @@
autopep8==1.3.1
beautifulsoup4==4.4.1
bs4==0.0.1
celery==3.1.25
Cheetah==2.4.4
colorama==0.2.5
configobj==4.7.2
coreapi==2.3.0
coverage==4.3.4
dateparser==0.6.0
Django==1.9.2
django-cachalot==1.4.1
django-celery==3.1.17
django-celery-beat==1.0.1
django-extensions==1.6.7
django-picklefield==0.3.2
djangorestframework==3.6.2
django-rest-swagger==2.1.2
django-webpack-loader==0.4.1
fake-useragent==0.1.8
fuzzywuzzy==0.10.0
google-api-python-client==1.6.1
gunicorn==17.5
hashids==1.1.0
html5lib==0.999
interruptingcow==0.6
jsondiff==1.1.0
jsonfield==2.0.1
jsonpatch==1.3
jsonpointer==1.0
jsonschema==2.5.1
lxml==3.6.0
Markdown==2.6.6
mock==2.0.0
nltk==3.2.1
numpy==1.13.1
oauth==1.0.1
oauthlib==1.1.1
pep8==1.7.0
prettytable==0.7.2
progressbar2==3.32.1
psycopg2==2.7.1
PyJWT==1.4.0
pyserial==2.6
python-amazon-simple-product-api==2.2.11
python-dateutil==2.5.3
python-memcached==1.58
python-openid==2.2.5
python-social-auth==0.2.19
python-utils==2.0.0
pytz==2016.4
pywebpush==1.7.0
PyYAML==3.10
recommonmark==0.4.0
redis==2.10.5
requests==2.20.0
requests-oauthlib==0.6.1
rollbar==0.13.11
scikit-learn==0.18.1
scipy==0.19.1
selenium==2.53.2
simplejson==3.10.0
six==1.10.0
South==0.7.5
Sphinx==1.5.1
sphinx-autobuild==0.6.0
sphinxcontrib-inlinesyntaxhighlight==0.2
sphinx-rtd-theme==0.1.9
ssh-import-id==3.21
supervisor==3.3.1
toolz==0.7.4
urllib3==1.24.1
virtualenv==1.11.4
20 changes: 20 additions & 0 deletions build/semesterly-nginx/50x.html
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>An error occurred.</h1>
<p>Sorry, the page you are looking for is currently unavailable.<br/>
Please try again later.</p>
<p>If you are the system administrator of this resource then you should check
the error log for details.</p>
</body>
</html>
11 changes: 11 additions & 0 deletions build/semesterly-nginx/Dockerfile
@@ -0,0 +1,11 @@
FROM nginx:latest

# Need curl for health checks
RUN apt-get update && apt-get install -y curl && apt-get clean

COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./50x.html /usr/share/nginx/html/50x.html

# Get assets
RUN mkdir /code
COPY --from=896112238827.dkr.ecr.us-east-1.amazonaws.com/semesterly:latest /code/static /code/static
53 changes: 53 additions & 0 deletions build/semesterly-nginx/nginx.conf
@@ -0,0 +1,53 @@

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

server {
listen 80;
server_name semesterly;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /code/static/;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8000;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

}
}
21 changes: 21 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,21 @@
version: '3'

services:
db:
image: postgres
ports:
- "5432:5432"
web:
image: semesterly
environment:
- NODE_ENV=development
build: .
command: bash -c "python manage.py migrate; npm run watch & python /code/manage.py runserver 0.0.0.0:8000"
volumes:
- .:/code
- /code/node_modules # Use local node_modules from image
ports:
- "8000:8000"
- "3000:3000"
depends_on:
- db
41 changes: 41 additions & 0 deletions docker-dev.txt
@@ -0,0 +1,41 @@
Developing Semester.ly on Docker

Steps are below on getting your local development environment running:
* Download and install docker for your environment (Windows/Mac/Linux are supporter): https://www.docker.com/get-started
* Clone this repository
* Create semesterly/local_settings.py as follows:
DEBUG = True

TEMPLATE_DEBUG = DEBUG

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': '',
'HOST': 'db',
'PORT': '5432',
}
}
* Edit semesterly/dev_credentials.py and add a value for JHU_API_KEY in single quotes like below. You can get this from sis.jhu.edu/api
'JHU_API_KEY': 'xxxxxxxx',
* add entry to your hosts file as follows (This file is in c:\Windows\System32\drivers\etc\hosts or /etc/hosts)
127.0.0.1 sem.ly jhu.sem.ly


Launch terminal or a command window and run:
* docker-compose build
* docker-compose up
You now have semesterly running. If this is the first time, you will want some data.

Getting JHU data for a given term
* In a new terminal run the following
docker exec -it $(docker ps -q -f ancestor=semesterly) /bin/bash
* OR
docker exec -it $(docker ps -q -f ancestor=semesterly) shell

This will put you inside of the shell. Now you can get courses by running these commands:
python manage.py ingest jhu --term Spring --years 2018
python manage.py digest jhu
* Open a browser and visit http://jhu.sem.ly:8000 and hack away