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

Feature/docker #112

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
dist: trusty
sudo: required
group: deprecated-2017Q4

language: python
python:
- 3.5.2
services:
- docker
env:
global:
- DOCKER_COMPOSE_VERSION=1.13.0
- DJANGO=1.11.3
- DISPLAY=:99.0
- MOZ_HEADLESS=1

language: python
python:
- 3.5.2

services: postgresql
addons:
firefox: latest-nightly

before_install:
- export DJANGO_SETTINGS_MODULE=POSCaD.settings.dev
- export PYTHONPATH=$HOME/builds/amigosdapoli/donation-system
- export PIP_USE_MIRRORS=true

install:
- pip install -r requirements.txt
- pip install django==$DJANGO --quiet
- pip install psycopg2 --quiet

before_script:
- bash scripts/setup_database_linux.sh
- bash scripts/install_geckodriver.sh
- bash scripts/prepare_codeclimate_testcoverage.sh
before_install:
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- pip install coverage=4.4.2 --quiet

script:
- bash scripts/build_donation-system.sh
- coverage run --source 'POSCaD,dbwrapper' --omit 'venv/*' manage.py test
- ./scripts/prepare_codeclimate_testcoverage.sh
- docker-compose up -d
- docker-compose exec django python manage.py test
- coverage run --source 'POSCaD,dbwrapper'
- coverage xml

after_script:
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Got it from: https://fernandofreitasalves.com/criando-um-container-docker-para-um-projeto-django-existente/
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /webapps
WORKDIR /webapps
# Installing OS Dependencies
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
libsqlite3-dev
RUN pip install -U pip setuptools
COPY requirements.txt /webapps/
ADD scripts /usr/local/bin/scripts
RUN pip install -r /webapps/requirements.txt
ADD . /webapps/
# Django service
EXPOSE 8000

8 changes: 5 additions & 3 deletions POSCaD/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'poscad',
'NAME': 'admin',
'USER': 'admin',
'PASSWORD': 'admin',
'HOST': 'localhost',
'HOST': 'postgres',
'PORT': '',
}
}

if 'TRAVIS' in os.environ:
DATABASES['default']['HOST'] = 'localhost'
54 changes: 17 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The goal of this project is to help other endowment funds and non profits in gen

## Requirements

<<<<<<< HEAD
### If in Debian/Ubuntu
```
# Install Postgres
Expand All @@ -30,49 +31,28 @@ sudo apt-get install python-pip
# Set up database
bash scripts/setup_database_linux.sh
```

### If in Mac
=======
# Docker and docker compose
Install docker following the instructions for your plataform: https://docs.docker.com/install/
Don't forget the extra steps, so you don't have to root all you commands: https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user
Also, install docker compose: https://docs.docker.com/compose/install/
>>>>>>> 1921843... development: add docker image for faster start

Now, configure you stuff in the env file (`.env`)
```
# Install Postgres
brew update
brew install postgresql

# Start the postgres service
pg_ctl -D /usr/local/var/postgres start && brew services start postgresql

# Set up database
psql postgres
=>CREATE DATABASE poscad;
=>CREATE USER admin WITH PASSWORD 'admin' ;
=>ALTER ROLE admin SET client_encoding TO 'utf8';
=>ALTER ROLE admin SET default_transaction_isolation TO 'read committed';
=>ALTER ROLE admin SET timezone TO 'UTC-3';
=>GRANT ALL PRIVILEGES ON DATABASE poscad TO admin;
GATEWAY_SANDBOX=<boolean>
MERCHANT_ID=<id>
MERCHANT_KEY=<key>
```

### Start
```bash
# Clone repo
git clone https://github.com/amigosdapoli/donation-system.git
cd donation-system/

# Install requirements
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
```
If you have to, you may also change some option for the postgres service: https://hub.docker.com/_/postgres/

## Continue
Now, run:
```
# Run start database
python manage.py makemigrations
python manage.py migrate

#Run application
python manage.py runserver

docker-compose up -d
```
TODO using docker? Vagrant?
The first time, since the image isn't in the docker hub, it'll take some time.
The server will the be accessible in the URL `localhost:8000`

# Payment Gateways
Payment gateways will follow a pattern so we can add different services if needed.
Expand Down
46 changes: 46 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: '2.1'

services:
selenium:
image: selenium/standalone-chrome-debug:3.7.1
ports:
- 4444:4444
- 5900:5900

postgres:
hostname: postgres
healthcheck:
test: ["CMD", "/usr/local/bin/docker-healthcheck"]
interval: 1s
retries: 20
image: healthcheck/postgres
environment:
- POSTGRES_USER=admin
- POSTGRE_DB=poscad
volumes:
- ./scripts:/usr/local/bin/scripts

django:
build: .
environment:
- GATEWAY_SANDBOX=${GATEWAY_SANDBOX}
- MERCHANT_ID=${MERCHANT_ID}
- MERCHANT_KEY=${MERCHANT_KEY}
- CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID}
- KONDUTO_PUBLIC_KEY=${KONDUTO_PUBLIC_KEY}
- KONDUTO_PRIVATE_KEY=${KONDUTO_PRIVATE_KEY}
- SLACK_TOKEN=
- SLACK_CHANNEL=
working_dir: /webapps
volumes:
- .:/webapps
- ./scripts:/usr/local/bin/scripts
links:
- selenium
ports:
- "8000:8000"
- "8082:8082"
depends_on:
postgres:
condition: service_healthy
command: /usr/local/bin/scripts/start.sh
43 changes: 33 additions & 10 deletions functional_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
import time
import os
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
import time, os, socket
from django.test import override_settings, tag

MAX_WAIT = 10


class NewDonorTest(LiveServerTestCase):
@tag('selenium')
@override_settings(ALLOWED_HOSTS=['django', 'testserver'])
class NewDonorTest(StaticLiveServerTestCase):
RIGHT_CC_NUMBER = "4111111111111111"
MISSING_ONE_CC_NUMBER = "411111111111111"
WRONG_CC_NUMBER = "4111111111111112"

host = 'django'

def setUp(self):
options = Options()
#options.add_argument('-headless')
self.browser = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver', firefox_options=options)
self.browser = webdriver.Remote(
command_executor='http://selenium:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME
)

os.environ['RECAPTCHA_DISABLE'] = 'True'

def tearDown(self):
Expand Down Expand Up @@ -62,9 +69,22 @@ def fill_in_personal_fields_right(self, email=None):
email_input_box = self.browser.find_element_by_id("id_email")

# ...And inputs hers
name_input_box.send_keys("Maria")
name_input_box.send_keys("Maria2")
surname_input_box.send_keys("Silva")
CPNJ_input_box.send_keys("128.164.150-23")
CPNJ_input_box.send_keys("1")
CPNJ_input_box.send_keys("2")
CPNJ_input_box.send_keys("3")
CPNJ_input_box.send_keys(".")
CPNJ_input_box.send_keys("4")
CPNJ_input_box.send_keys("5")
CPNJ_input_box.send_keys("6")
CPNJ_input_box.send_keys(".")
CPNJ_input_box.send_keys("7")
CPNJ_input_box.send_keys("9")
CPNJ_input_box.send_keys("8")
CPNJ_input_box.send_keys("-")
CPNJ_input_box.send_keys("9")
CPNJ_input_box.send_keys("1")
phone_input_box.send_keys("11998765432")
email_input_box.send_keys(email)

Expand Down Expand Up @@ -174,5 +194,8 @@ def test_fraudster_get_caught_by_antifraud(self):

self.wait_for(lambda: self.assertIn('Erro nas informações de cartão de crédito enviadas.', self.browser.page_source))

def test_userc_can_follow_statistics(self):
# Donor has there is a campaign and wants to follow progress
self.browser.get(self.live_server_url + "/statistics")


self.assertIn('Resultados consolidados', self.browser.page_source)
20 changes: 0 additions & 20 deletions functional_tests/tests_statistics.py

This file was deleted.

Empty file modified scripts/build_donation-system.sh
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions scripts/install_geckodriver.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz
tar -xzf geckodriver-v0.19.1-linux64.tar.gz
sudo mv geckodriver /usr/local/bin
sudo ls /usr/local/bin | grep gecko
mv geckodriver /usr/local/bin
ls /usr/local/bin | grep gecko
echo $MOZ_CRASHREPORTER_SHUTDOWN
echo $DISPLAY
Empty file modified scripts/prepare_codeclimate_testcoverage.sh
100644 → 100755
Empty file.
11 changes: 4 additions & 7 deletions scripts/setup_database_linux.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#! /bin/sh

sudo -u postgres psql -c "CREATE DATABASE poscad;"
sudo -u postgres psql -c "CREATE USER admin WITH CREATEUSER PASSWORD 'admin' ;"
sudo -u postgres psql -c "ALTER ROLE admin SET client_encoding TO 'utf8';"
sudo -u postgres psql -c "ALTER ROLE admin SET default_transaction_isolation TO 'read committed';"
sudo -u postgres psql -c "ALTER ROLE admin SET timezone TO 'UTC-3';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE poscad TO admin;"
sudo -u postgres psql -c "ALTER USER admin CREATEDB;"
psql -U admin -c "ALTER ROLE admin SET client_encoding TO 'utf8';"
psql -U admin -c "ALTER ROLE admin SET default_transaction_isolation TO 'read committed';"
psql -U admin -c "ALTER ROLE admin SET timezone TO 'UTC-3';"
psql -U admin -c "GRANT ALL PRIVILEGES ON DATABASE poscad TO admin;"
6 changes: 6 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
python manage.py runserver 0.0.0.0:8000