Commit 2e878abd authored by Stefano Alberto Russo's avatar Stefano Alberto Russo
Browse files

Added first Web App skeleton. Updated README.

parent ca0a98b3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14,3 +14,5 @@ __pycache__/
# Data
data*

# DB conf
images/webapp/db_conf.sh
+43 −3
Original line number Diff line number Diff line
@@ -27,9 +27,25 @@ Run

	$ rosetta/run

Check status

	$ rosetta/ps
Play

    You can now point your browser to http://localhost:8080

Clean

	# rosetta/clean

### Extras

Check status (not yet fully supported)

    # rosetta/status


Run Web App unit tests (with Rosetta running)

    ./run_webapp_unit_tests.sh


### Building errors
@@ -37,3 +53,27 @@ Check status
It is common for the build process to fail with a "404 not found" error on an apt-get instrucions, as apt repositories often change their IP addresses. In such case, try:

    $ rosetta/build nocache


### Development mode

Django development server is running on port 8080 of the "webapp" service.

To enable live code changes, add or comment out the following in docker-compose.yaml under the "volumes" section of the "webapp" service:

    - ./images/webapp/code:/opt/webapp_code
    
This will mount the code from images/webapp/code as a volume inside the webapp container itself allowing to make immediately effective codebase edits.

Note that when you edit the Django ORM model, you need to rerun the migrate the database, either by just rerunning the webapp service:

    $ rosetta/rerun webapp

..ora by entering in the webapp service container and manually migrate:

    $ rosetta/shell webapp
    $ source /env.sh
    $ source /db_conf.sh
    $ cd /opt/webapp_code
    $ python3 manage.py makemigrations
    $ python3 manage.py migrate  
 No newline at end of file
+23 −0
Original line number Diff line number Diff line
@@ -33,3 +33,26 @@ services:
      - ./data/dregistry:/var/lib/registry
    ports:
      - "5000:5000"

  webapp:
    image: "rosetta/webapp"
    container_name: webapp
    hostname: webapp
    environment:
      - SAFEMODE=False
      - DJANGO_LOG_LEVEL=CRITICAL
      - ROSETTA_LOG_LEVEL=DEBUG 
    ports:
      - "8080:8080"
    volumes:
      - ./data_rosetta/webapp/data:/data
      - ./data_rosetta/webapp/log:/var/log/webapp
      #- ./images/webapp/code:/opt/webapp_code







+129 −0
Original line number Diff line number Diff line
# From https://github.com/github/gitignore/blob/master/Python.gitignore

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

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don’t work, or not
#   install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
virtual/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

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

# Pyre type checker
.pyre/

# 
.docker_bash_history
+90 −0
Original line number Diff line number Diff line
FROM rosetta/base
MAINTAINER Stefano Alberto Russo <stefano.russo@gmail.com>

# Always start with an apt-get update when extending base images,
# otherwise apt repositories might get outdated (404 not found)
# and building without cache does not re-build base images.
RUN apt-get update

#------------------------------
# Apt requirements
#------------------------------

# Install Curl
RUN apt-get install curl -y

# Download get-pip script
RUN curl -O https://bootstrap.pypa.io/get-pip.py

# Install Python3 and Pip3 (python3-distutils required for pip3)
RUN apt-get install python3 python3-distutils -y 

# Install Python and pip in this order (first Python 3 and then Python 2), or 
# you will end ap with python defaulting to python2 and pip defaulting to pip3
# Otherwise, do somethign like "ln -s /usr/local/bin/pip3 /usr/local/bin/pip"

# Install Python3 and Pip3 (ython3-distutils required for pip3)
RUN apt-get install python3 python3-distutils -y 
RUN python3 get-pip.py 'pip==10.0.1'

# Install Python2 and Pip2
RUN apt-get install python -y
RUN python get-pip.py 'pip==10.0.1'

# Python 3 dev (for pycrypto)
RUN apt-get install python3-dev -y

# Install postgres driver required for psycopg2
RUN apt-get install libpq-dev -y


#------------------------------
# Install Django project
#------------------------------

# Prepare dir
RUN mkdir /opt/webapp_code

# Install Python requirements..
COPY requirements.txt /tmp/
RUN cd /opt/webapp_code && pip3 install -r /tmp/requirements.txt

# Patch Django 2.2 non-ascii chars in /usr/local/lib/python3.6/dist-packages/django/views/templates/technical_500.html
RUN sed -i 's/[\x80-\xFF]/./g' /usr/local/lib/python3.6/dist-packages/django/views/templates/technical_500.html

# Install App code
COPY code /opt/webapp_code

# Fix permissions
RUN chown -R rosetta:rosetta /opt/webapp_code

# Copy db conf
COPY db_conf.sh /db_conf.sh

# Prepare for logs
RUN mkdir /var/log/webapp/ && chown rosetta:rosetta /var/log/webapp/


#------------------------------
# Supervisord
#------------------------------

COPY run_webapp.sh /etc/supervisor/conf.d/
RUN chmod 755 /etc/supervisor/conf.d/run_webapp.sh
COPY supervisord_webapp.conf /etc/supervisor/conf.d/


#------------------------------
# Prestartup
#------------------------------

COPY prestartup_webapp.sh /prestartup/








Loading