Skip to content
This repository has been archived by the owner on Oct 15, 2018. It is now read-only.

Commit

Permalink
All components updated to v1.2.1 specification. Added Docker support …
Browse files Browse the repository at this point in the history
…and Docker-Compose file for quick start.
  • Loading branch information
hjhsalo committed Nov 19, 2016
1 parent 7ca0d77 commit 3f70b0b
Show file tree
Hide file tree
Showing 110 changed files with 13,730 additions and 1,916 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
doc
Dockerfile*
nginx.conf
uwsgi.ini
docker-compose.yml
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Gradle:
.idea/gradle.xml
.idea/libraries

.idea
# Mongo Explorer plugin:
.idea/mongoSettings.xml

Expand Down Expand Up @@ -113,7 +113,8 @@ coverage.xml
local_settings.py

# Flask stuff:
instance/
####instance/

.webassets-cache

# Scrapy stuff:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Service_Components/signed_requests"]
path = Service_Components/signed_requests
url = https://github.com/Allu2/signed_requests
98 changes: 98 additions & 0 deletions Account/Dockerfile-account
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
FROM python:2.7
MAINTAINER hjhsalo <[email protected]>

# NOTE: Baseimage python:2.7 already contains latest pip

# TODO: Compile cryptography (and everything else pip related) elsewhere and
# get rid of "build-essential libssl-dev libffi-dev python-dev"
# Maybe according to these instructions:
# https://glyph.twistedmatrix.com/2015/03/docker-deploy-double-dutch.html

# TODO: Double check and think about the order of commands. Should application
# specific stuff be moved to the end of the file?
# What are actually application specific? etc.

# TODO: Have brainstorming session on how to properly setup EXPOSE ports, hosts, etc.
# Now it is difficult to come up with sensible defaults.
# Remember to check out what Docker Compose offers.

# TODO: Make a new user and usergroup.
# Now everything including the ENTRYPOINT is being run as root which is bad
# practise and for example uWSGI complains about this.

###
# Install
# Specific structure where a single RUN is used to execute everything.
# Based on Docker Best practices -document. To force cache busting.
# https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#/apt-get
# NOTE: python-mysql.connector is MyData Account specific dependency.
RUN apt-get update && apt-get install -y \
build-essential \
libffi-dev \
libssl-dev \
python-dev \
python-mysql.connector \
&& rm -rf /var/lib/apt/lists/*


###
# Install application specific Python-dependencies.

# NOTE: If you have multiple Dockerfile steps that use different files from
# your context, COPY them individually, rather than all at once. This will
# ensure that each step’s build cache is only invalidated (forcing the step
# to be re-run) if the specifically required files change.
# https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#/add-or-copy
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt

# NOTE: As uwsgi is part the configuration in some sense, how should we make
# this optional or at least clear to the reader?
RUN pip install uwsgi

# NOTE: j2cli is needed to preprocess config files based on values
# environment variables
# https://github.com/kolypto/j2cli
# https://tryolabs.com/blog/2015/03/26/configurable-docker-containers-for-multiple-environments/
RUN pip install j2cli

###
# Setup configuration using environment variables
ENV MYSQL_HOST ${MYSQL_HOST:-'mysql-db'}
ENV MYSQL_USER ${MYSQL_USER:-'mydataaccount'}
ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'wr8gabrA'}
ENV MYSQL_DB ${MYSQL_DB:-'MyDataAccount'}
ENV MYSQL_PORT ${MYSQL_PORT:-3306}
ENV URL_PREFIX ${URL_PREFIX:-''}

###
# Create a installation directory into the container and copy the application
# to that folder.
ARG APP_INSTALL_PATH=/mydata-sdk-account

# TODO: This may not be needed. Test and refactor if necessary to keep it.
ENV APP_INSTALL_PATH ${APP_INSTALL_PATH:-/mydata-account}
RUN mkdir -p $APP_INSTALL_PATH

# Change current directory inside the container / image to this path.
WORKDIR $APP_INSTALL_PATH

# Copy everything (including previously copied filed and folders) from directory
# where Dockerfile is located to current WORKDIR inside container.
# Remember that <src> must be inside the context of the build:
# http://serverfault.com/a/666154
COPY . .

###
# Configure and run the application using entrypoint.sh.
# NOTE: Content of CMD are the default parameters passed to entrypoint.sh.
# These can be overwritten on "docker run <image> <parameters_that_replace_CMD>"
# https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#/entrypoint
COPY ./docker-entrypoint-account.sh /

ENTRYPOINT ["/docker-entrypoint-account.sh"]

# NOTE: Maybe this should be replaced with something that doesn't run anything
# and the command below should go to compose.yml ??
CMD ["uwsgi --socket 0.0.0.0:8080 --protocol=http -w wsgi --callable app --processes 2"]

2 changes: 1 addition & 1 deletion Account/account_config_template.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ MYSQL_PORT = 3306
#MYSQL_READ_DEFAULT_FILE = '' # MySQL configuration file to read, see the MySQL documentation for mysql_options().
#MYSQL_USE_UNICODE = '' # If True, CHAR and VARCHAR and TEXT columns are returned as Unicode strings, using the configured character set.
MYSQL_CHARSET = 'utf8' # If present, the connection character set will be changed to this character set, if they are not equal. Default: utf-8
#MYSQL_SQL_MODE = '' # If present, the session SQL mode will be set to the given string.
MYSQL_SQL_MODE = 'TRADITIONAL' # If present, the session SQL mode will be set to the given string.
#MYSQL_CURSORCLASS = '' # If present, the cursor class will be set to the given string.


Expand Down
7 changes: 5 additions & 2 deletions Account/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@
# =========================================
api = Api(app, prefix=app.config["URL_PREFIX"])


@app.before_request
def new_request():
print("New Request")
print("############")


@app.errorhandler(404)
def not_found(error):
# When file not found, respon with 403
return make_response(('FORBIDDEN', 403))
not_found_error = ApiError(code=404, title="Not Found", detail="Endpoint not found", status="NotFound")
error_dict = not_found_error.to_dict()
return make_json_response(errors=error_dict, status_code=str(error_dict['code']))


@app.errorhandler(ApiError)
Expand Down
Loading

0 comments on commit 3f70b0b

Please sign in to comment.