Skip to content

Commit

Permalink
Merge pull request #14 from joeflack4/develop
Browse files Browse the repository at this point in the history
Updates to CI, requirements, root endpoint, and minor updates.
  • Loading branch information
joeflack4 authored Jul 17, 2018
2 parents 366eb41 + fc5e718 commit 654c908
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 50 deletions.
104 changes: 61 additions & 43 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
# Examples https://circleci.com/docs/2.0/sample-config/
#
version: 2 # use CircleCI 2.0
version: 2 # Uses CircleCI 2.0
jobs:
build:
branches:
only:
- develop
- master
- /pr*/

# working_directory no longer required: https://discuss.circleci.com/t/working-directory-is-no-longer-required-defaults-to-project/14363/2
# working_directory: ~/repo

docker:
# specify the version you desire here
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
# primary container where `steps` are run
# Primary container where `steps` are run
# - use `-browsers` prefix for selenium tests, e.g. `circleci/python:3.6.1-browsers`
- image: circleci/python:3.6.1 # 2 spaces after this -
# environment variables for pma-api?
environment:
# Separate environment variables should not matter for CircleCI build, because Heroku has its own env variables setup.
# For more information, however, on dynamic env variables, see: https://discuss.circleci.com/t/per-branch-env-vars/13214
APP_SETTINGS: production
FLASK_APP: production
# Do I need '+psycopg2'? Do I need port ':5432'?
# DATABASE_URL: "postgres://ubuntu@localhost:5432/db_name"
# DATABASE_URL: postgresql+psycopg2://pmaapi:pmaapi@localhost/pmaapi
DATABASE_URL: postgresql+psycopg2://pmaapi@localhost/pmaapi
# DATABASE_URL: postgresql+psycopg2://pmaapi:pmaapi@localhost/pmaapi

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# As of 2018/07/16, our Heroku deployment is on 9.6.9, and local on ~9.6.0.0.
# - image: circleci/postgres:9.4
# Specify service dependencies here as separate images/machines if necessary.
# - Documented at https://circleci.com/docs/2.0/circleci-images/
# - As of 2018/07/16, our Heroku deployment is on 9.6.9, and local on ~9.6.0.0.
- image: circleci/postgres:9.6.2 # 2 spaces after this -
# environment variables for database, https://hub.docker.com/_/postgres/
environment:
# POSTGRES_USER: root
# POSTGRES_DB: circle_test
POSTGRES_USER: pmaapi
POSTGRES_DB: pmaapi
# POSTGRES_PASSWORD: pmaapi
Expand Down Expand Up @@ -72,32 +57,65 @@ jobs:
command: |
. env/bin/activate
make db
environment: # do I need this here if it's already in the Python image?
# Do I need '+psycopg2'? Do I need port ':5432'?
# DATABASE_URL: "postgres://ubuntu@localhost:5432/db_name"
# DATABASE_URL: postgresql+psycopg2://pmaapi:pmaapi@localhost/pmaapi
environment:
DATABASE_URL: postgresql+psycopg2://pmaapi@localhost/pmaapi

# # Is this useful for our setup?
# - run:
# name: Waiting for Postgres to be ready
# command: |
# for i in `seq 1 10`;
# do
# nc -z localhost 5432 && echo Success && exit 0
# echo -n .
# sleep 1
# done
# echo Failed waiting for Postgres && exit 1

- run:
name: run tests
command: |
. env/bin/activate
make test
- store_artifacts: # TODO: what is this?
- store_artifacts:
path: test-reports
destination: test-reports

# See https://circleci.com/docs/2.0/deployment-integrations/ for deploy examples
# CI deployment setup notes
# - https://circleci.com/docs/2.0/deployment-integrations/#heroku
# - https://circleci.com/docs/2.0/project-walkthrough/#deploying-to-heroku
# - https://circleci.com/docs/2.0/env-vars/#setting-an-environment-variable-in-a-project
deploy-staging:
machine: true
steps:
- checkout
- run:
name: Deploy staging branch staging server.
command: |
git push https://heroku:[email protected]/$HEROKU_APP_NAME_STAGING.git master -f
deploy-production:
machine: true
steps:
- checkout
- run:
name: Deploy production branch production server.
command: |
git push https://heroku:[email protected]/$HEROKU_APP_NAME_PRODUCTION.git master -f
workflows:
version: 2
build-deploy:
jobs:
- build:
filters:
branches:
only:
- master
- develop
- /pr*/
- staging
- production
- deploy-production:
requires:
- build
filters:
branches:
only:
- production
- deploy-staging:
requires:
- build
filters:
branches:
only:
- staging
10 changes: 8 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,16 @@ staging: # connects to server shell
heroku run bash --app pma-api-staging

production-push:
git checkout production && git push trunk production
git checkout production && \
git push trunk production

staging-push:
git checkout staging && git push trunk staging --force
git status && \
printf "\nGit status should have reported 'nothing to commit, working tree clean'. Otherwise you should cancel this command, make sure changes are committed, and run it again.\n\n" && \
git checkout develop && \
git branch -D staging && \
git checkout -b staging && \
git push -u trunk staging --force

push-production: production-push

Expand Down
11 changes: 10 additions & 1 deletion pma_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def create_app(config_name):
Returns:
Flask: Configured Flask application.
"""
# noinspection PyShadowingNames
app = PmaApiFlask(__name__)
app.config.from_object(config[config_name])

Expand All @@ -34,8 +35,16 @@ def create_app(config_name):
app.register_blueprint(root)

from .api_1_0 import api as api_1_0_blueprint
from .api_1_0.collection import get_resources
app.register_blueprint(api_1_0_blueprint, url_prefix='/v1')

app.add_url_rule('/', view_func=lambda: 'To be implemented.')
# TODO: (jef/jkp 2017-08-29) Investigate mimetypes in accept headers.
# See: flask.pocoo.org/snippets/45/ Needs: Nothing?
request_headers = 'application/json' # default for now
if request_headers == 'text/html':
# Also can re-route to /docs
app.add_url_rule('/', view_func=lambda: 'Documentation')
else:
app.add_url_rule('/', view_func=lambda: get_resources())

return app
6 changes: 2 additions & 4 deletions pma_api/api_1_0/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""API Routes."""
from flask import Blueprint, jsonify
from flask import Blueprint

from ..queries import DatalabData

api = Blueprint('api', __name__)

# pylint: disable=wrong-import-position
from . import collection, datalab
from ..response import QuerySetApiResult


@api.route('/')
Expand All @@ -22,5 +20,5 @@ def root():
# See: flask.pocoo.org/snippets/45/ Needs: Nothing?
request_headers = 'application/json' # default for now
if request_headers == 'text/html':
return 'Documentation.'
return 'Documentation.' # Also can re-route to /docs
return collection.get_resources()
36 changes: 36 additions & 0 deletions requirements-lock.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
alabaster==0.7.11
astroid==1.5.3
Babel==2.6.0
certifi==2018.4.16
chardet==3.0.4
click==6.7
docutils==0.14
Flask==0.12.2
Flask-Cors==3.0.3
Flask-Script==2.0.5
Flask-SQLAlchemy==2.2
gunicorn==19.7.1
idna==2.7
imagesize==1.0.0
isort==4.2.15
itsdangerous==0.24
Jinja2==2.9.6
lazy-object-proxy==1.3.1
MarkupSafe==1.0
mccabe==0.6.1
packaging==17.1
psycopg2==2.7.3
pycodestyle==2.3.1
pydocstyle==2.0.0
Pygments==2.2.0
pylint==1.7.2
pyparsing==2.2.0
pytz==2018.5
requests==2.19.1
six==1.10.0
snowballstemmer==1.2.1
SQLAlchemy==1.1.9
urllib3==1.23
Werkzeug==0.12.2
wrapt==1.10.11
xlrd==1.0.0
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# About
# - requirements.txt is for top-level dependencies
# - requirements-lock.txt is for all dependencies, both top-level and those also installed as requirements higher-level dependencies
# This style is used by NPM, i.e. package-lock.json. Can read up more on that to get background for the spirit of this change.
# TODO: Can probably remove some of these listed here, as not all are "top-level"
astroid==1.5.3
click==6.7
Flask==0.12.2
Expand Down

0 comments on commit 654c908

Please sign in to comment.