Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ruiconti committed Mar 15, 2021
1 parent 23d7777 commit b5553cd
Show file tree
Hide file tree
Showing 81 changed files with 5,460 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
ignore = F401
exclude = .git,__pycache__,build,dist,tests,migrations,serverless-build,.aws-sam
max-complexity = 10
78 changes: 78 additions & 0 deletions .github/workflows/sandbox-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Sandbox

on:
push:
branches:
- dev

jobs:
db-migrations:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: "3.7"
- name: Install dependencies
run: pip install -r requirements.txt
# - name: Downgrade
# run: alembic -x data=true downgrade base
# env:
# DATABASE_URL: ${{ secrets.SANDBOX_DB_URL }}
- name: Upgrade
run: alembic -x data=true upgrade head
env:
DATABASE_URL: ${{ secrets.SANDBOX_DB_URL }}
build-server:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: "3.7"
- name: Install EB CLI
run: pip install awsebcli
- name: Deploy
run: eb deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
build-serverless:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: "3.7"
- name: Install EB CLI
run: pip install aws-sam-cli
- name: Create layers directories
run: |
mkdir serverless-build/
mkdir -p serverless-build/apolo-layer/python/
- name: Install dependencies in layer
run: pip install -r requirements.txt -t serverless-build/dependencies/python/lib/python3.7/site-packages
- name: Copy apolo to layer
run: cp -r apolo serverless-build/apolo-layer/python/
- name: SAM build
run: sam build
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: sa-east-1
- name: SAM deploy
run: >
sam deploy --config-env sandbox --parameter-overrides "DatabaseURL=${DATABASE_URL} DigestoToken=${DIGESTO_TOKEN} DigestoURL=${DIGESTO_URL}"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: sa-east-1
DATABASE_URL: ${{ secrets.SANDBOX_DB_URL }}
DIGESTO_TOKEN: ${{ secrets.DIGESTO_TOKEN_HML }}
DIGESTO_URL: ${{ secrets.DIGESTO_URL }}
95 changes: 95 additions & 0 deletions .github/workflows/staging-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Staging

on:
push:
branches:
- main

jobs:
db-migrations:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: "3.7"
- name: Install dependencies
run: pip install -r requirements.txt
# in staging we only go up
- name: Upgrade
run: alembic -x data=true upgrade head
env:
DATABASE_URL: ${{ secrets.STAGING_DB_URL }}
build-server:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: "3.7"
- name: Install EB CLI
run: pip install awsebcli
- name: Deploy
run: eb deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Set envars
run: >
eb setenv ENVIRONMENT="STAGING" SMTP_HOST=$SMTP_HOST
SMTP_PORT=$SMTP_PORT DIGESTO_TOKEN=$DIGESTO_TOKEN
DIGESTO_URL=$DIGESTO_URL SMTP_PASSWORD=$SMTP_PASSWORD
EMAILS_SENDER_EMAIL=$EMAILS_SENDER_EMAIL
EMAILS_FROM_NAME=$EMAILS_FROM_NAME DATABASE_URL=$DATABASE_URL
JWT_SECRET_KEY=$JWT_SECRET_KEY
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SMTP_HOST: ${{ secrets.SMTP_HOST }}
SMTP_PORT: ${{ secrets.SMTP_PORT }}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
EMAILS_SENDER_EMAIL: ${{ secrets.EMAILS_SENDER_EMAIL }}
EMAILS_FROM_NAME: ${{ secrets.EMAILS_FROM_NAME }}
DATABASE_URL: ${{ secrets.STAGING_DB_URL }}
DIGESTO_TOKEN: ${{ secrets.DIGESTO_TOKEN_HML }}
DIGESTO_URL: ${{ secrets.DIGESTO_URL }}
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY_STAGING }}
build-serverless:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: "3.7"
- name: Install EB CLI
run: pip install aws-sam-cli
- name: Create layers directories
run: |
mkdir serverless-build/
mkdir -p serverless-build/apolo-layer/python/
- name: Install dependencies in layer
run: pip install -r requirements.txt -t serverless-build/dependencies/python/lib/python3.7/site-packages
- name: Copy apolo to layer
run: cp -r apolo serverless-build/apolo-layer/python/
- name: SAM build
run: sam build
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: sa-east-1
- name: SAM deploy
run: >
sam deploy --config-env staging --parameter-overrides "DatabaseURL=${DATABASE_URL} DigestoToken=${DIGESTO_TOKEN} DigestoURL=${DIGESTO_URL}"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: sa-east-1
DATABASE_URL: ${{ secrets.STAGING_DB_URL }}
DIGESTO_TOKEN: ${{ secrets.DIGESTO_TOKEN_HML }}
DIGESTO_URL: ${{ secrets.DIGESTO_URL }}
74 changes: 74 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Tests

on:
push:
branches:
- master
- dev
pull_request:
types: [opened, synchronize, edited]
branches:
- master
- dev

jobs:
tests:
runs-on: ubuntu-latest

services:
postgres:
env:
POSTGRES_DB: apolo
image: postgres:11.5
ports: [ "5432:5432" ]
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: "3.7"
- name: Cache pip
uses: actions/cache@v1
with:
path: ~/.cache/pip # This path is specific to Ubuntu
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install dependencies
run: pip install -r requirements.txt
- name: Linting checks
# removed < mypy --config-file mypy.ini . > for now
run: |
flake8 .
- name: Prepare test postgres database
env:
PYTHONPATH: .
run: alembic -x data=true upgrade head
- name: Test authentication
env:
SMTP_HOST: ${{ secrets.SMTP_HOST }}
SMTP_PORT: ${{ secrets.SMTP_PORT }}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
EMAILS_SENDER_EMAIL: ${{ secrets.EMAILS_SENDER_EMAIL }}
EMAILS_FROM_NAME: ${{ secrets.EMAILS_FROM_NAME }}
run: |
pytest tests/auth/unit --color=yes --showlocals -v
pytest tests/auth/integration --color=yes --showlocals -v -s
pytest tests/auth/e2e --color=yes --showlocals -v
- name: Test management
env:
DIGESTO_TOKEN: ${{ secrets.DIGESTO_TOKEN_HML }}
DIGESTO_URL: ${{ secrets.DIGESTO_URL }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
run: |
pytest tests/management/unit --color=yes --showlocals -v
pytest tests/management/integration --color=yes --showlocals -v
pytest tests/management/e2e/test_mutations.py --color=yes --showlocals -v
pytest tests/management/e2e/test_lambdas.py --color=yes --showlocals -v
pytest tests/management/e2e/test_queries.py --color=yes --showlocals -v
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# python
__pycache__/
.mypy_cache
*.egg-info/
*cache*
*.pyc

# Ommitted files and directories
management/
management.py
tests/resources/
*.html

# Elastic Beanstalk Files
.elasticbeanstalk/
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml

# SAM
.aws-sam/*

# Project specific
serverless-build/*
apolo-layer/*
dependencies/*
.~lock*

# Configuration
*.lock
*.env
*.env*
.env

# IDE
.idea/*
.vscode
85 changes: 85 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# A generic, single database configuration.

[alembic]
script_location = migrations
# path to migration scripts

# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# timezone to use when rendering the date
# within the migration file as well as the filename.
# string value is passed to dateutil.tz.gettz()
# leave blank for localtime
# timezone =

# max length of characters to apply to the
# "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; this defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path
# version_locations = %(here)s/bar %(here)s/bat alembic/versions

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

; sqlalchemy.url = driver://user:pass@localhost/dbname


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks=black
# black.type=console_scripts
# black.entrypoint=black
# black.options=-l 79

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
Loading

0 comments on commit b5553cd

Please sign in to comment.