Skip to content

Commit

Permalink
Add wercker file and clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
nhumrich committed Aug 26, 2016
1 parent 8371106 commit f60ce04
Show file tree
Hide file tree
Showing 10 changed files with 627 additions and 30 deletions.
407 changes: 407 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM canopytax/python-base

RUN apk --update add nodejs && \
RUN apk --no-cache add nodejs && \
cd /app/tmeister/static && \
npm install && \
npm run build && \
apk del nodejs && \
cd /app && \
rm -rf /var/cache/apk/*
cd /app


EXPOSE 8445
98 changes: 98 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import sys
import os

from invoke import task
# You might need the following line so that alembic can traverse
# the application properly
# export PYTHONPATH=$(pwd)

IS_TTY = False if os.getenv('DOCKER') else sys.stdout.isatty()

@task
def clean(ctx):
patterns = (
'**/*.pyc',
'**/__pycache__',
'.cache',
)

for pattern in patterns:
ctx.run("rm -rf {}".format(pattern))


@task
def lint(ctx, full=False):
if full:
ctx.run('python3 -m pylint tmeister migrate tests', pty=IS_TTY)
else:
ctx.run('python3 -m flake8 tmeister migrate tests', pty=IS_TTY)


@task(pre=[clean])
def test(ctx, coverage=True, x=False, v=False):
"""
test the code!
:param ctx:
:param headless:
:param coverage: use --no-coverage to skip coverage results
:param x: use -x to stop at first test
:param v: use -v to increase verbosity
:return:
"""
cmd = 'python3 -m pytest --color yes'
if coverage:
print("coverage added")
cmd += ' --cov=tmeister'

if x:
cmd += ' -x'

if not v:
cmd += ' --quiet'

ctx.run(cmd, pty=IS_TTY)


@task
def install(ctx):
"""
install dependencies
NOT to be used in docker. Only for local dev
:param ctx:
:param docker: if this is installing in a docker container
"""
ctx.run('python3 -m pip install -r requirements.txt -t .pip', pty=IS_TTY)


@task
def serve(ctx):
ctx.run('python3 run.py', pty=IS_TTY)


@task
def migrate(ctx):
ctx.run('alembic upgrade head', pty=IS_TTY)


@task
def down(ctx, all=False):
if all:
num = 'base'
else:
num = '-1'
ctx.run('alembic downgrade ' + num, pty=IS_TTY)


@task(pre=[migrate])
def seed(ctx):
print('no seed script yet')


@task
def run(ctx):
ctx.run('python3 run.py', pty=IS_TTY)


@task
def hooks(ctx):
ctx.run('ln -sf $(pwd)/hooks/pre-commit.sh .git/hooks/pre-commit')
5 changes: 2 additions & 3 deletions tests/api/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
These are api tests that are completely stand-alone.
They have no dependencies to service code, and are designed to enforce the api contract.
They have no dependencies to service code,
and are designed to enforce the api contract.
"""


2 changes: 0 additions & 2 deletions tests/test_stuff.py

This file was deleted.

3 changes: 1 addition & 2 deletions tmeister/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from aioauth_client import GithubClient
from aiohttp import web
from aiohttp_session.cookie_storage import EncryptedCookieStorage

github = GithubClient(
client_id='b6281b6fe88fa4c313e6',
Expand All @@ -18,4 +17,4 @@ async def is_authorized(request):


async def handle_github_auth(request):
pass
pass
12 changes: 0 additions & 12 deletions tmeister/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,3 @@ def main():

if __name__ == '__main__':
main()












13 changes: 7 additions & 6 deletions tmeister/dataaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ async def get_toggle_states_for_env(env, list_of_features):
def _transform_toggles(toggles):
return [
{'toggle':
{'env': row.env,
'feature': row.feature,
'state': row.state}}
{'env': row.env,
'feature': row.feature,
'state': row.state}}
for row in toggles]


async def set_toggle_state(env, feature, state):
results = await pg.fetch(
db.toggles.select()
.where(db.toggles.c.feature == feature)
.where(db.toggles.c.env == env))
.where(db.toggles.c.feature == feature)
.where(db.toggles.c.env == env))

results = _transform_toggles(results)
if not results:
Expand Down Expand Up @@ -108,7 +108,8 @@ async def get_all_toggles():
END AS state
FROM environments
CROSS JOIN features
LEFT OUTER JOIN toggles ON feature = features.name AND env = environments.name;\
LEFT OUTER JOIN toggles ON feature = features.name
AND env = environments.name;\
"""

toggles = await pg.fetch(query)
Expand Down
4 changes: 2 additions & 2 deletions tmeister/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ async def get_toggle_states_for_env(request):
env = request.match_info['name']
features = params.get('feature', None)
if not features:
return web.json_response({'Message': "No features provided"}, status=400)
return web.json_response({'Message': "No features provided"},
status=400)
if env == 'dev':
result = {feature: True for feature in features}
else:
Expand Down Expand Up @@ -67,4 +68,3 @@ async def set_toggle_state(request):
async def get_all_toggle_states(request):
toggle_list = await dataaccess.get_all_toggles()
return web.json_response(toggle_list)

108 changes: 108 additions & 0 deletions wercker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
box: canopytax/python-base
build:
services:
- id: canopytax/postgresdb
tag: latest
username: $DOCKER_USERNAME
password: $DOCKER_PASSWORD

steps:
- script:
name: pip install
code: |
mv "$WERCKER_CACHE_DIR/pip" /root/.local || echo "Nothing in cache"
pip3 install -r requirements.txt --user -U
cp -a /root/.local "$WERCKER_CACHE_DIR/pip" || "nothing to copy"
- script:
name: build UI
code: |
apk --no-cache add nodejs
cd /app/tmeister/static
npm run build
apk del nodejs
cd /app
- script:
name: lint
code: |
invoke lint
- script:
name: run tests
code: |
invoke test -x
- script:
name: clean and copy files
code: |
invoke clean
mv /root/.local .pip
dockerhub:
steps:
- script:
name: get tags
code: |
if [ $WERCKER_GIT_BRANCH == 'master' ]; then export DOCKER_BRANCH=latest; else export DOCKER_BRANCH="$(basename $WERCKER_GIT_BRANCH)"; fi;
echo $DOCKER_BRANCH
- script:
name: prepare for dockerhub
code: |
# put pip files back in place
mv .pip /root/.local
# clean unneeded files
rm -rf .git/
rm .gitignore
rm wercker.yml
rm readme.md
rm requirements.txt
rm .pylintrc
rm .coverage
rm Dockerfile
rm docker-compose.yml
rm -rf tests/
rm -rf tmeister/static/node_modules
rm -rf tmeister/static/spec
rm -rf tmeister/static/src
rm -rf tmeister/static/bin
# move files
cp -a . /app
# clean wercker files
cd /app
rm -rf /pipeline/
# recreate output dir
mkdir -p "$WERCKER_OUTPUT_DIR"
#mkdir -p "$WERCKER_ROOT"
touch "$WERCKER_OUTPUT_DIR/touch"
- internal/docker-push:
repository: $REPO
tag: $WERCKER_GIT_COMMIT $DOCKER_BRANCH
ports: "9191"
username: $DOCKER_USERNAME
password: $DOCKER_PASSWORD
cmd: 'dumb-init ./startup.sh'

deploy:
box:
id: canopytax/deployment
username: $DOCKER_USERNAME
password: $DOCKER_PASSWORD
tag: latest
steps:
- script:
name: run migration
code: |
echo "placeholder"
- script:
name: deploy to rancher
code: |
/scripts/deploy-to-rancher.py --docker-tag "$WERCKER_GIT_COMMIT"

0 comments on commit f60ce04

Please sign in to comment.