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

Commit

Permalink
Update builds and instructions to align with AWS ElasticBeanstalk
Browse files Browse the repository at this point in the history
Add .python-version file set to 3.4.2 to match AWS EB version
Updated Docker setup to align more with Elastic Beanstalk by using Amazon AMI base image and running app behind Apache mod_wsgi
Updated README for pyenv and removed S3 instructions
Update Travis config to set EQ_SECERET_KEY (possible cause of Selenium failures?)
Dockerfile based on onsdigital/docker-aws-apache-wsgi:python-3.4.2-onbuild base image
  • Loading branch information
collisdigital committed Feb 13, 2017
1 parent de378e8 commit e673527
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 57 deletions.
1 change: 1 addition & 0 deletions .python-version
@@ -0,0 +1 @@
3.4.2
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,6 @@ dist: trusty
python: '3.4'
env:
global:
- EQ_SCHEMA_BUCKET=""
- EQ_ENABLE_CACHE=True
# Codacy
- secure: q3hyZhRj24C5sT7T0ViTDCwhT8eVjpanTf6BkPPBI43/6NBJeF1vi4/LkfJMQa0qwYibu5zB8jtkk2VsqGRMGvj9fMufOKXGqebOsPYWUJl1MZM3t7OZS57xF9wBUenZwx1oyb/VPrFB56ctGny1XEbF4l47NmbKWD1iMWG1f3Y6PCJ7o8o62v0irmfbdYFTsWjipCQlCrKZm+KVWZD25egIDJMDpq9e0nYNoSW+5fMXDGOtV20/U/rcmW5Lfn06ppJ0C4CaKHuM+MzZtZJwtiCI2TqF0ihQl7ry7YgpqEZLPHQYQ5npIpecxP1f/6ebcAPdKKkJ2Ccutrv/7IFlJo7rWLTB7mzJ4ep11HCdo3mL+JREp1HUJLeEngXFC3lKRXPHKukUxe4Lkz1/g6kdwCUZxajGTwML84FHmqoZxKGMKhMN+0n6rO8wEUR32q4+JbO5z/oQGhtjQZkogq8vWY6+/aq328hsbmy72s23AiX+BQUHqk2QFs3T9FQiqwn4OqqX4JKzmHs838LT+dUTFgH+mWo0lalxa3Pr7cJAwhn97VSnIdU9JTC8RyPWbAHkah78PXlL9guHI1nzQTjTcMm/yTlmtE2NxTSY+ZGIV+O5pcJm3HkAjZvNi/0jjDWwBHs/rZgj1t7Eoueh8dPTSZ12LmqKuBpvkrzLKcs2zt4=
Expand Down
36 changes: 9 additions & 27 deletions Dockerfile
@@ -1,31 +1,13 @@
FROM ubuntu:14.04
FROM onsdigital/docker-aws-apache-wsgi:python-3.4.2-onbuild

ENV RUNTIME_PACKAGES="python3 postgresql python-psycopg2"
ENV BUILD_PACKAGES="curl build-essential python3-dev libpq-dev ca-certificates libffi-dev libssl-dev git"

WORKDIR /code

EXPOSE 5000

RUN apt-key adv --keyserver pgp.mit.edu --recv D101F7899D41F3C3

RUN echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update && apt-get install -y $RUNTIME_PACKAGES $BUILD_PACKAGES \
&& curl -sS https://bootstrap.pypa.io/get-pip.py | python3 \
&& curl -sL https://deb.nodesource.com/setup_6.x | bash -

RUN apt-get install -y nodejs yarn
RUN yarn global add gulp-cli

ADD requirements.txt /code/requirements.txt
ADD package.json /code/package.json
ADD app/assets /code/app/assets

RUN pip3 install -U -I -r /code/requirements.txt

ADD . /code
# Install branched Python Cryptography to fix Apache issue
# TO BE REMOVED ONCE OFFICIAL PACKAGE (1.8?) RELEASED
RUN yum install -y git && \
pip install -e git+https://github.com/reaperhulk/cryptography.git@password-cb#egg=cryptography

# Compile frontend
RUN yarn compile

ENTRYPOINT python3 application.py runserver
# Because eq-survey-runner creates 'eq.log' in the current directory
# it needs write permission as the apache user
RUN chown apache:apache .
55 changes: 35 additions & 20 deletions README.md
Expand Up @@ -2,6 +2,7 @@
[![Build Status](https://travis-ci.org/ONSdigital/eq-survey-runner.svg?branch=master)](https://travis-ci.org/ONSdigital/eq-survey-runner) [![Code Issues](https://www.quantifiedcode.com/api/v1/project/1709e9d582cc479a86568a043117d4d0/badge.svg)](https://www.quantifiedcode.com/app/project/1709e9d582cc479a86568a043117d4d0) [![codecov](https://codecov.io/gh/ONSdigital/eq-survey-runner/branch/master/graph/badge.svg)](https://codecov.io/gh/ONSdigital/eq-survey-runner) [![Dependency Status](https://gemnasium.com/badges/github.com/ONSdigital/eq-survey-runner.svg)](https://gemnasium.com/github.com/ONSdigital/eq-survey-runner)[![Codacy Badge](https://api.codacy.com/project/badge/Grade/82e63fc5bc5c43e8ba1ba6d13bfb4243)](https://www.codacy.com/app/ONSDigital/eq-survey-runner)

## Run with Docker
Install Docker for your system: https://www.docker.com/

To get eq-survey-runner running the following command will build and run the containers
```
Expand All @@ -22,18 +23,47 @@ docker-compose build --no-cache
```


## Pre-Requisites
In order to run locally you'll need PostgreSQL and Node.js installed

PostgreSQL
```
brew install postgres
```

npm
```
brew install npm
```

Note that npm currently requires Python 2.x for some of the setup steps,
it doesn't work with Python 3.

## Setup
Based on python 3
It is preferable to use the version of Python locally that matches that
used on deployment. This project has a `.python_version` file for this
purpose.

If using virtualenvwrapper (if not, you should be), create a new virtual env for python3
If you are using pyenv (https://github.com/yyuu/pyenv), you can install
the correct version of Python alongside any existing versions easily:

```
mkvirtual --python=`which python3` <your env name>
pyenv install
```

Install dependencies using pip
You should also use a virtualenv (https://github.com/yyuu/pyenv-virtualenv)
to keep this project's package installations separate from others you
are working on, to create a new virtualenv:

```
pyenv virtualenv <your env name>
pyenv activate <your env name>
```

Upgrade pip and install dependencies:

```
pip install --upgrade pip setuptools
pip install -r requirements.txt
pip install -e git+https://github.com/reaperhulk/cryptography.git@password-cb#egg=cryptography
```
Expand All @@ -58,8 +88,6 @@ This will generate a JWT for you to log into the application. The script prints

The front-end toolkit uses nodejs, yarn and gulp.

Install nodejs `6.7.1`. Make sure npm is installed with `npm`.

Install yarn with:

```
Expand Down Expand Up @@ -106,7 +134,7 @@ You will need to install the EB CLI tools using PIP.
*NOTE:* The EB tools do not currently work with Python 3.5. I installed the EB CLI tools *outside* my virtual environment and installed installed them globally using the following commands

```
deactivate # to exit the virtual environment
pyenv deactivate # to exit the virtual environment
sudo pip install awsebcli # install the eb cli tools
```

Expand Down Expand Up @@ -204,19 +232,6 @@ EQ_MAX_HTTP_POST_CONTENT_LENGTH - The maximum http post content length that the
EQ_MAX_NUM_REPEATS - The maximum number of repeats the system will allow
EQ_DEVELOPER_LOGGING - Enable developer style logging described here http://structlog.readthedocs.io/en/stable/development.html
```
## Loading schemas from S3

To enable an instance of the survey runner to load form schemas from AWS S3,
set the environment variable `EQ_SCHEMA_BUCKET` and ensure the correct IAM
permissions are set for the ec2 instances that are created by elasticbeanstalk
OR ensure you have the correct boto aws credentials set in `~/.aws/credentials`.

To disable S3 support: set `EQ_SCHEMA_BUCKET` to an empty string '' e.g.

```export EQ_SCHEMA_BUCKET=''```

This will then make the schemas available in the dev page and enable the runner
to look inside the bucket to load schemas for rendering.

## JWT Integration
Integration with the survey runner requires the use of a signed JWT using public and private key pair (see https://jwt.io,
Expand Down
7 changes: 3 additions & 4 deletions application.py
Expand Up @@ -83,10 +83,9 @@ def add_service(logger, method_name, event_dict): # pylint: disable=unused-argu
from app import create_app # NOQA
application = create_app()

manager = Manager(application)
port = int(os.environ.get('PORT', 5000))
manager.add_command("runserver", Server(host='0.0.0.0', port=port))


if __name__ == '__main__':
manager = Manager(application)
port = int(os.environ.get('PORT', 5000))
manager.add_command("runserver", Server(host='0.0.0.0', port=port))
manager.run()
10 changes: 5 additions & 5 deletions docker-compose.yml
Expand Up @@ -14,7 +14,7 @@ services:
RABBITMQ_DEFAULT_PASS: digitaleq

db:
image: postgres:9.5
image: postgres:9.4
environment:
POSTGRES_PASSWORD: digitaleq
POSTGRES_USER: digitaleq
Expand All @@ -29,20 +29,20 @@ services:
environment:
EQ_CLOUDWATCH_LOGGING: "False"
EQ_DEV_MODE: "True"
EQ_ENABLE_CACHE: "False"
EQ_DEVELOPER_LOGGING: "True"
EQ_RABBITMQ_ENABLED: "True"
EQ_SCHEMA_BUCKET: ""
EQ_SECRET_KEY: "NOT_SECRET_DOCKER_KEY"
EQ_SERVER_SIDE_STORAGE_DATABASE_URL: postgres://digitaleq:digitaleq@db:5432/runner
EQ_RABBITMQ_URL: amqp://digitaleq:digitaleq@rabbit:5672/%2F
restart: always
volumes:
- ./app:/code/app
depends_on:
- db
- rabbit
networks:
- eq-env
ports:
- "5000:5000"
- "80:80"


networks:
Expand Down

0 comments on commit e673527

Please sign in to comment.