Skip to content

Commit b5553cd

Browse files
committed
Initial commit
1 parent 23d7777 commit b5553cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+5460
-0
lines changed

.flake8

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
ignore = F401
3+
exclude = .git,__pycache__,build,dist,tests,migrations,serverless-build,.aws-sam
4+
max-complexity = 10

.github/workflows/sandbox-deploy.yaml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Sandbox
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
8+
jobs:
9+
db-migrations:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
- name: Setup Python
15+
uses: actions/setup-python@v1
16+
with:
17+
python-version: "3.7"
18+
- name: Install dependencies
19+
run: pip install -r requirements.txt
20+
# - name: Downgrade
21+
# run: alembic -x data=true downgrade base
22+
# env:
23+
# DATABASE_URL: ${{ secrets.SANDBOX_DB_URL }}
24+
- name: Upgrade
25+
run: alembic -x data=true upgrade head
26+
env:
27+
DATABASE_URL: ${{ secrets.SANDBOX_DB_URL }}
28+
build-server:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v2
33+
- name: Setup Python
34+
uses: actions/setup-python@v1
35+
with:
36+
python-version: "3.7"
37+
- name: Install EB CLI
38+
run: pip install awsebcli
39+
- name: Deploy
40+
run: eb deploy
41+
env:
42+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
43+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
44+
build-serverless:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v2
49+
- name: Setup Python
50+
uses: actions/setup-python@v1
51+
with:
52+
python-version: "3.7"
53+
- name: Install EB CLI
54+
run: pip install aws-sam-cli
55+
- name: Create layers directories
56+
run: |
57+
mkdir serverless-build/
58+
mkdir -p serverless-build/apolo-layer/python/
59+
- name: Install dependencies in layer
60+
run: pip install -r requirements.txt -t serverless-build/dependencies/python/lib/python3.7/site-packages
61+
- name: Copy apolo to layer
62+
run: cp -r apolo serverless-build/apolo-layer/python/
63+
- name: SAM build
64+
run: sam build
65+
env:
66+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
67+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
68+
AWS_DEFAULT_REGION: sa-east-1
69+
- name: SAM deploy
70+
run: >
71+
sam deploy --config-env sandbox --parameter-overrides "DatabaseURL=${DATABASE_URL} DigestoToken=${DIGESTO_TOKEN} DigestoURL=${DIGESTO_URL}"
72+
env:
73+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
74+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
75+
AWS_DEFAULT_REGION: sa-east-1
76+
DATABASE_URL: ${{ secrets.SANDBOX_DB_URL }}
77+
DIGESTO_TOKEN: ${{ secrets.DIGESTO_TOKEN_HML }}
78+
DIGESTO_URL: ${{ secrets.DIGESTO_URL }}

.github/workflows/staging-deploy.yaml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Staging
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
db-migrations:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
- name: Setup Python
15+
uses: actions/setup-python@v1
16+
with:
17+
python-version: "3.7"
18+
- name: Install dependencies
19+
run: pip install -r requirements.txt
20+
# in staging we only go up
21+
- name: Upgrade
22+
run: alembic -x data=true upgrade head
23+
env:
24+
DATABASE_URL: ${{ secrets.STAGING_DB_URL }}
25+
build-server:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v2
30+
- name: Setup Python
31+
uses: actions/setup-python@v1
32+
with:
33+
python-version: "3.7"
34+
- name: Install EB CLI
35+
run: pip install awsebcli
36+
- name: Deploy
37+
run: eb deploy
38+
env:
39+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
40+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41+
- name: Set envars
42+
run: >
43+
eb setenv ENVIRONMENT="STAGING" SMTP_HOST=$SMTP_HOST
44+
SMTP_PORT=$SMTP_PORT DIGESTO_TOKEN=$DIGESTO_TOKEN
45+
DIGESTO_URL=$DIGESTO_URL SMTP_PASSWORD=$SMTP_PASSWORD
46+
EMAILS_SENDER_EMAIL=$EMAILS_SENDER_EMAIL
47+
EMAILS_FROM_NAME=$EMAILS_FROM_NAME DATABASE_URL=$DATABASE_URL
48+
JWT_SECRET_KEY=$JWT_SECRET_KEY
49+
env:
50+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
51+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
52+
SMTP_HOST: ${{ secrets.SMTP_HOST }}
53+
SMTP_PORT: ${{ secrets.SMTP_PORT }}
54+
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
55+
EMAILS_SENDER_EMAIL: ${{ secrets.EMAILS_SENDER_EMAIL }}
56+
EMAILS_FROM_NAME: ${{ secrets.EMAILS_FROM_NAME }}
57+
DATABASE_URL: ${{ secrets.STAGING_DB_URL }}
58+
DIGESTO_TOKEN: ${{ secrets.DIGESTO_TOKEN_HML }}
59+
DIGESTO_URL: ${{ secrets.DIGESTO_URL }}
60+
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY_STAGING }}
61+
build-serverless:
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v2
66+
- name: Setup Python
67+
uses: actions/setup-python@v1
68+
with:
69+
python-version: "3.7"
70+
- name: Install EB CLI
71+
run: pip install aws-sam-cli
72+
- name: Create layers directories
73+
run: |
74+
mkdir serverless-build/
75+
mkdir -p serverless-build/apolo-layer/python/
76+
- name: Install dependencies in layer
77+
run: pip install -r requirements.txt -t serverless-build/dependencies/python/lib/python3.7/site-packages
78+
- name: Copy apolo to layer
79+
run: cp -r apolo serverless-build/apolo-layer/python/
80+
- name: SAM build
81+
run: sam build
82+
env:
83+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
84+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
85+
AWS_DEFAULT_REGION: sa-east-1
86+
- name: SAM deploy
87+
run: >
88+
sam deploy --config-env staging --parameter-overrides "DatabaseURL=${DATABASE_URL} DigestoToken=${DIGESTO_TOKEN} DigestoURL=${DIGESTO_URL}"
89+
env:
90+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
91+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
92+
AWS_DEFAULT_REGION: sa-east-1
93+
DATABASE_URL: ${{ secrets.STAGING_DB_URL }}
94+
DIGESTO_TOKEN: ${{ secrets.DIGESTO_TOKEN_HML }}
95+
DIGESTO_URL: ${{ secrets.DIGESTO_URL }}

.github/workflows/tests.yaml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- dev
8+
pull_request:
9+
types: [opened, synchronize, edited]
10+
branches:
11+
- master
12+
- dev
13+
14+
jobs:
15+
tests:
16+
runs-on: ubuntu-latest
17+
18+
services:
19+
postgres:
20+
env:
21+
POSTGRES_DB: apolo
22+
image: postgres:11.5
23+
ports: [ "5432:5432" ]
24+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
25+
26+
steps:
27+
- uses: actions/checkout@v2
28+
- name: Setup Python
29+
uses: actions/setup-python@v1
30+
with:
31+
python-version: "3.7"
32+
- name: Cache pip
33+
uses: actions/cache@v1
34+
with:
35+
path: ~/.cache/pip # This path is specific to Ubuntu
36+
# Look to see if there is a cache hit for the corresponding requirements file
37+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
38+
restore-keys: |
39+
${{ runner.os }}-pip-
40+
${{ runner.os }}-
41+
- name: Install dependencies
42+
run: pip install -r requirements.txt
43+
- name: Linting checks
44+
# removed < mypy --config-file mypy.ini . > for now
45+
run: |
46+
flake8 .
47+
- name: Prepare test postgres database
48+
env:
49+
PYTHONPATH: .
50+
run: alembic -x data=true upgrade head
51+
- name: Test authentication
52+
env:
53+
SMTP_HOST: ${{ secrets.SMTP_HOST }}
54+
SMTP_PORT: ${{ secrets.SMTP_PORT }}
55+
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
56+
EMAILS_SENDER_EMAIL: ${{ secrets.EMAILS_SENDER_EMAIL }}
57+
EMAILS_FROM_NAME: ${{ secrets.EMAILS_FROM_NAME }}
58+
run: |
59+
pytest tests/auth/unit --color=yes --showlocals -v
60+
pytest tests/auth/integration --color=yes --showlocals -v -s
61+
pytest tests/auth/e2e --color=yes --showlocals -v
62+
- name: Test management
63+
env:
64+
DIGESTO_TOKEN: ${{ secrets.DIGESTO_TOKEN_HML }}
65+
DIGESTO_URL: ${{ secrets.DIGESTO_URL }}
66+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
67+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
68+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
69+
run: |
70+
pytest tests/management/unit --color=yes --showlocals -v
71+
pytest tests/management/integration --color=yes --showlocals -v
72+
pytest tests/management/e2e/test_mutations.py --color=yes --showlocals -v
73+
pytest tests/management/e2e/test_lambdas.py --color=yes --showlocals -v
74+
pytest tests/management/e2e/test_queries.py --color=yes --showlocals -v

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# python
2+
__pycache__/
3+
.mypy_cache
4+
*.egg-info/
5+
*cache*
6+
*.pyc
7+
8+
# Ommitted files and directories
9+
management/
10+
management.py
11+
tests/resources/
12+
*.html
13+
14+
# Elastic Beanstalk Files
15+
.elasticbeanstalk/
16+
!.elasticbeanstalk/*.cfg.yml
17+
!.elasticbeanstalk/*.global.yml
18+
19+
# SAM
20+
.aws-sam/*
21+
22+
# Project specific
23+
serverless-build/*
24+
apolo-layer/*
25+
dependencies/*
26+
.~lock*
27+
28+
# Configuration
29+
*.lock
30+
*.env
31+
*.env*
32+
.env
33+
34+
# IDE
35+
.idea/*
36+
.vscode

alembic.ini

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
script_location = migrations
5+
# path to migration scripts
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
10+
# timezone to use when rendering the date
11+
# within the migration file as well as the filename.
12+
# string value is passed to dateutil.tz.gettz()
13+
# leave blank for localtime
14+
# timezone =
15+
16+
# max length of characters to apply to the
17+
# "slug" field
18+
# truncate_slug_length = 40
19+
20+
# set to 'true' to run the environment during
21+
# the 'revision' command, regardless of autogenerate
22+
# revision_environment = false
23+
24+
# set to 'true' to allow .pyc and .pyo files without
25+
# a source .py file to be detected as revisions in the
26+
# versions/ directory
27+
# sourceless = false
28+
29+
# version location specification; this defaults
30+
# to alembic/versions. When using multiple version
31+
# directories, initial revisions must be specified with --version-path
32+
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
33+
34+
# the output encoding used when revision files
35+
# are written from script.py.mako
36+
# output_encoding = utf-8
37+
38+
; sqlalchemy.url = driver://user:pass@localhost/dbname
39+
40+
41+
[post_write_hooks]
42+
# post_write_hooks defines scripts or Python functions that are run
43+
# on newly generated revision scripts. See the documentation for further
44+
# detail and examples
45+
46+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
47+
# hooks=black
48+
# black.type=console_scripts
49+
# black.entrypoint=black
50+
# black.options=-l 79
51+
52+
# Logging configuration
53+
[loggers]
54+
keys = root,sqlalchemy,alembic
55+
56+
[handlers]
57+
keys = console
58+
59+
[formatters]
60+
keys = generic
61+
62+
[logger_root]
63+
level = WARN
64+
handlers = console
65+
qualname =
66+
67+
[logger_sqlalchemy]
68+
level = WARN
69+
handlers =
70+
qualname = sqlalchemy.engine
71+
72+
[logger_alembic]
73+
level = INFO
74+
handlers =
75+
qualname = alembic
76+
77+
[handler_console]
78+
class = StreamHandler
79+
args = (sys.stderr,)
80+
level = NOTSET
81+
formatter = generic
82+
83+
[formatter_generic]
84+
format = %(levelname)-5.5s [%(name)s] %(message)s
85+
datefmt = %H:%M:%S

0 commit comments

Comments
 (0)