Skip to content

Commit

Permalink
Merge e915aca into 0383073
Browse files Browse the repository at this point in the history
  • Loading branch information
dougthor42 committed Jan 10, 2019
2 parents 0383073 + e915aca commit e610060
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 5 deletions.
167 changes: 167 additions & 0 deletions .dockerignore
@@ -0,0 +1,167 @@
# In an ideal world, this file would simply import the .gitignore
# file and basically be done. However, sadly that doesn't work for
# a variety of reasons:
# 1) You can't import one .ignore file into another
# 2) The .dockerignore file has slightly different syntax than .gitignore.
# https://zzz.buzz/2018/05/23/differences-of-rules-between-gitignore-and-dockerignore/
# For now I'm going to assume that there are no problems and simply
# $(cat .gitignore >> .dockerignore)

# The .git directory
.git/

# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python

### Python ###
# 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/
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
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/
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/

### Python Patch ###
.venv/

# End of https://www.gitignore.io/api/python

# Other Virtual Envs.
.venv*/

# Development Configuration
config/
internal.db

# Created by https://www.gitignore.io/api/vim
# Edit at https://www.gitignore.io/?templates=vim

### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

# End of https://www.gitignore.io/api/vim
66 changes: 66 additions & 0 deletions README.md
Expand Up @@ -48,6 +48,72 @@ It's been designed to handle infrequent, variable interval data. Sometimes
real-world data just doesn't appear at nice, regular intervals.


## Installing


### Docker

The easiest way to get up and running with **Trendlines** is with Docker:

```bash
$ docker run p 5000:80 dougthor42/trendlines:latest
```

Then open a browser to `http://localhost:5000/` and you're all set. Add some data
(see below) and refresh the page.

> **Note:** Data will not persist when the container is destroyed!

### Docker Compose

> **WIP!**
If you're doing more than just playing around, you'll likely want to set up
Docker Compose. I've included an example Compose file
[here](/docker/docker-compose.yml).

Before using the example Compose file, you'll need to:

1. Make a directory to store the config file (and database file if using
SQLite)
2. Make sure that dir is writable by docker-compose.
3. Create the configuration `trendlines.cfg` within that directory.

```bash
$ mkdir /var/www/trendlines
$ chmod -R a+w /var/www/trendlines
$ touch /var/www/trendlines/trendlines.cfg
```

Next, edit your new `trendlines.cfg` file as needed. At the very least, the
following is needed:

```python
# /var/www/trendlines/trendlines.cfg
SECRET_KEY = b"don't use the value written in this README file!"
DATABASE = "/data/internal.db"
```

You should be all set to bring Docker Compose up:

```bash
$ docker-compose -f path/to/docker-compose.yml up -d
```

Again, open up a browser to `http://localhost` and you're good to go. Add some
data as outlined below and start playing around.

**Note:** If you get an error complaining about "Error starting userland proxy:
Bind for 0.0.0.0:80: Unexpected error Permission denied", then try changing
the port in docker-compose.yml to something else. I like 5000 myself:

```yaml
ports:
- 5000:80
```


## Usage

TODO.
Expand Down
17 changes: 17 additions & 0 deletions apache/trendlines.conf
@@ -0,0 +1,17 @@
<VirtualHost *:80>
ServerName trendlines

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

WSGIDaemonProcess trendlines user=www-data group=www-data
WSGIScriptAlias / /var/www/wsgi.py
<Location />
WSGIProcessGroup trendlines
</Location>

# Expose the logs to StdOut and StdErr so that docker
# can read them.
ErrorLog /proc/self/fd/1
LogLevel info
CustomLog /proc/self/fd/2 combined
</VirtualHost>
7 changes: 7 additions & 0 deletions apache/wsgi.py
@@ -0,0 +1,7 @@
#!/usr/local/bin/python3
import os

from trendlines import create_app

os.environ['TRENDLINES_CONFIG_FILE'] = "/data/trendlines.cfg"
application = create_app()
56 changes: 56 additions & 0 deletions docker/Dockerfile
@@ -0,0 +1,56 @@
FROM python:3.7.1-slim-stretch

LABEL maintainer="doug.thor@gmail.com"

ENV WSGI_VERSION="4.6.5"

# Install Requirements
RUN apt-get update \
&& apt-get install -y \
apache2 \
apache2-dev \
make \
wget \
# Install mod_wsgi from source for our specific python version
&& wget \
-O mod_wsgi-$WSGI_VERSION.tar.gz \
"https://github.com/GrahamDumpleton/mod_wsgi/archive/$WSGI_VERSION.tar.gz" \
&& tar -xzf mod_wsgi-$WSGI_VERSION.tar.gz \
&& cd mod_wsgi-$WSGI_VERSION \
&& ./configure \
&& make \
&& make install \
&& cd / \
# Cleanup
&& rm -rf mod_wsgi-$WSGI_VERSION* \
&& apt-get remove -y apache2-dev wget make \
&& apt-get clean \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*

EXPOSE 80

# Run apache in the foreground
CMD ["apache2ctl", "-D", "FOREGROUND", "-e", "INFO"]

### Now that the base stuff is done with, actually install the app.
COPY requirements.txt /requirements.txt
RUN pip install \
-r /requirements.txt \
&& rm /requirements.txt

# I hate that I copy over everything.
COPY . /trendlines
COPY apache/trendlines.conf /etc/apache2/sites-available/trendlines.conf
COPY apache/wsgi.py /var/www/wsgi.py
COPY docker/trendlines.cfg /data/trendlines.cfg

# TODO: Replace with install from pypi? Not if I want things built off master.
RUN pip install -e /trendlines

RUN a2ensite trendlines \
&& a2dissite 000-default.conf \
&& chown -R www-data:www-data /data


# vim: tabstop=4 shiftwidth=4 expandtab filetype=dockerfile
16 changes: 16 additions & 0 deletions docker/docker-compose.yml
@@ -0,0 +1,16 @@
# Need version >= 3.2 because of how we define our volumes
version: "3.2"
services:
trendlines:
image: dougthor42/trendlines:latest
restart: always
ports:
- 80:80
volumes:
- type: bind
# Host location. This can be anywhere on your file system.
source: /var/www/trendlines
# Within the container. The /data directory holds both the internal
# database file (if you're using SQLite) and the configuration file
# `trendlines.cfg`.
target: /data
9 changes: 9 additions & 0 deletions docker/trendlines.cfg
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
"""
Configuration specific to running in a docker container.
"""
DEBUG = False

DATABASE = "/data/internal.db"

# vim: filetype=python

0 comments on commit e610060

Please sign in to comment.