8000 Initial commit · devgithvb/python-backend-flask@a2c9d85 · GitHub
[go: up one dir, main page]

Skip to content

Commit a2c9d85

Browse files
committed
Initial commit
Add project files Nginx Flask, sqlalchemy bigid (#1) * Add flask * add sqlalchemy bigid * flask runs * pg pass * tweaks for docker * pgpassword Add sample User model and migration Fix pytest lib Create LICENSE Cleanup csrf doc Add gRPC/proto api stuff (#2) * add gRPC/proto api stuff add grpc server cmd cython, grpcio in dockerfile wip updates works * clean make Add lib/grpc helpers, protobuf map Commit arg for session_commit Docker cached volume instead Debian dockerfile fix fixes fix flask
0 parents  commit a2c9d85

File tree

114 files changed

+3729
-0
lines changed

Some content is hidden

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

114 files changed

+3729
-0
lines changed

.circleci/config.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
version: 2.1
2+
3+
executors:
4+
app:
5+
working_directory: ~/app
6+
docker:
7+
- image: circleci/python:3.8.1
8+
environment:
9+
PIPENV_VENV_IN_PROJECT: true
10+
DATABASE_URL: postgres://root:@localhost/alvinchow_service_test
11+
REDIS_URL: redis://localhost:6379
12+
13+
- image: circleci/postgres:11-alpine-ram
14+
environment:
15+
POSTGRES_USER: root
16+
POSTGRES_DB: alvinchow_service_test
17+
- image: circleci/redis:5.0.3
18+
19+
20+
commands:
21+
unit_tests_build:
22+
description: "Install and build the app, anything common for all unit test runs"
23+
steps:
24+
- checkout # checkout source code to working directory
25+
- run:
26+
name: Install dockerize
27+
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
28+
environment:
29+
DOCKERIZE_VERSION: v0.3.0
30+
- run:
31+
name: Wait for Postgres
32+
command: dockerize -wait tcp://localhost:5432 -timeout 1m
33+
- run:
34+
name: Wait for Redis
35+
command: dockerize -wait tcp://localhost:6379 -timeout 1m
36+
37+
- restore_cache:
38+
keys:
39+
- pip-packages-v1-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
40+
- pip-packages-v1-{{ .Branch }}-
41+
- pip-packages-v1-
42+
- run:
43+
name: Install dependencies
44+
command: |
45+
pipenv sync --dev
46+
- save_cache:
47+
paths:
48+
- ~/app/.venv
49+
key: pip-packages-v3-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
50+
- run:
51+
name: Linting
52+
command:
53+
pipenv run flake8
54+
55+
# We split into two jobs so we can do the more expensive HTML coverage only for master builds
56+
jobs:
57+
unit-tests:
58+
executor: app
59+
steps:
60+
- unit_tests_build
61+
- run:
62+
name: Run tests
63+
command: |
64+
pipenv run python runtests.py --coverage
65+
66+
unit-tests-with-coverage-html:
67+
executor: app
68+
steps:
69+
- unit_tests_build
70+
- run:
71+
name: Run tests
72+
command: |
73+
pipenv run python runtests.py --coverage-html
74+
pipenv run coverage-badge -o coverage.svg
75+
- store_artifacts:
76+
path: ~/app/htmlcov
77+
- store_artifacts:
78+
path: ~/app/coverage.svg
79+
80+
81+
82+
workflows:
83+
version: 2
84+
test:
85+
jobs:
86+
# Run normal tests for normal branches
87+
- unit-tests:
88+
filters:
89+
branches:
90+
ignore: master
91+
92+
# Also generate HTML coverage report for master commits
93+
- unit-tests-with-coverage-html:
94+
filters:
95+
branches:
96+
only:
97+
- master

.coveragerc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[run]
2+
omit =
3+
alvinchow_service/commands/*
4+
alvinchow_service/test/*
5+
alvinchow_service/api/grpc/protobuf*
6+
alvinchow_service/api/grpc/setup*.py
7+
*/test_*.py
8+
*version*.py

.dockerenv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# default values
2+
DATABASE_URL=postgres://root:password@postgres/alvinchow_service
3+
REDIS_URL=redis://redis:6379
4+
CELERY_BROKER_URL=redis://redis:6379/0
5+
PGHOST=postgres
6+
PGPASSWORD=password

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
venv
3+
.venv
4+
__pycache__

.flake8

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[flake8]
2+
exclude =
3+
venv
4+
.venv
5+
alembic
6+
alvinchow_service_protobuf
7+
alvinchow_service/api/grpc/alvinchow_service_protobuf_async
8+
9+
max-line-length = 120

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# gRPC
7+
alvinchow_service/api/grpc/alvinchow_service_protobuf
8+
alvinchow_service_protobuf_async/
9+
10+
# sed backup thing
11+
*-E
12+
# C extensions
13+
*.so
14+
15+
# Distribution / packaging
16+
dist
17+
*.egg-info/
18+
.installed.cfg
19+
*.egg
20+
21+
# Environments
22+
.venv
23+
venv
24+
25+
# mkdocs documentation
26+
/site
27+
28+
# mypy
29+
.mypy_cache/
30+
31+
local_config.py
32+
33+
# System stuff
34+
.DS_Store
35+
36+
# Tests
37+
htmlcov
38+
.coverage

Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM python:3.8.3-slim-buster
2+
3+
ARG FURY_AUTH
4+
5+
WORKDIR /home/app
6+
7+
RUN mkdir -p /home/app
8+
9+
# Install expensive things
10+
RUN \
11+
BUILD_DEPS='python3-dev g++ git' \
12+
&& apt-get update \
13+
&& apt-get install -y postgresql-client nginx \
14+
&& apt-get install -y --no-install-recommends $BUILD_DEPS \
15+
&& pip install pipenv uwsgi \
16+
&& pip install git+https://github.com/Supervisor/supervisor \
17+
&& pip install Cython==0.29.15 grpcio==1.29.0 \
18+
&& apt-get purge -y $BUILD_DEPS \
19+
&& apt-get autoremove -y \
20+
&& apt-get clean \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
# Optimization trick to cache pip libraries if not changed
24+
COPY Pipfile Pipfile.lock ./
25+
26+
RUN \
27+
BUILD_DEPS='python3-dev g++ libffi-dev libpq-dev' \
28+
&& apt-get update \
29+
&& apt-get install -y --no-install-recommends $BUILD_DEPS \
30+
&& pipenv install --system --dev \
31+
&& apt-get purge -y $BUILD_DEPS \
32+
&& apt-get autoremove -y \
33+
&& apt-get clean \
34+
&& rm -rf /var/lib/apt/lists/*
35+
36+
# Copy rest of files
37+
COPY . /home/app
38+
39+
RUN mkdir /etc/supervisor.d && ln -s /home/app/infra/supervisord.conf /etc/ && \
40+
mkdir /var/log/supervisor && \
41+
rm /etc/nginx/nginx.conf && \
42+
ln -s /home/app/infra/nginx.conf /etc/nginx/ && \
43+
groupadd web && useradd web -g web
44+
45+
RUN pip install -e .
46+
47+
# CMD "/home/app/entrypoint/run-web.sh"
48+
CMD "/home/app/entrypoint/run-admin.sh"

Dockerfile.alpine

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM python:3.8.3-alpine3.11
2+
3+
ARG FURY_AUTH
4+
5+
WORKDIR /home/app
6+
7+
RUN mkdir -p /home/app
8+
9+
# Install expensive things
10+
RUN \
11+
apk add --no-cache bash postgresql-client nginx \
12+
&& apk add --no-cache --virtual native-deps python3-dev g++ linux-headers git \
13+
&& pip install pip==20.1 \
14+
&& apk add --no-cache libstdc++ \
15+
&& pip install pipenv uwsgi \
16+
&& pip install git+https://github.com/Supervisor/supervisor \
17+
&& pip install Cython==0.29.15 grpcio==1.29.0 \
18+
&& apk del native-deps
19+
20+
# Optimization trick to cache pip libraries if not changed
21+
COPY Pipfile Pipfile.lock ./
22+
23+
RUN \
24+
apk add --no-cache --virtual build-deps libffi-dev g++ \
25+
postgresql-dev python3-dev \
26+
&& pipenv install --system --dev \
27+
&& apk del build-deps
28+
29+
# Copy rest of files
30+
COPY . /home/app
31+
32+
RUN mkdir /etc/supervisor.d && ln -s /home/app/infra/supervisord.conf /etc/ && \
33+
mkdir /var/log/supervisor && \
34+
rm /etc/nginx/nginx.conf && rm /etc/nginx/conf.d/default.conf && \
35+
ln -s /home/app/infra/nginx.conf /etc/nginx/ && \
36+
addgroup -S web && adduser -S web -G web
37+
38+
RUN pip install -e .
39+
40+
CMD "/home/app/entrypoint/run-web.sh"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Alvin Chow
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
TAG = latest
2+
DOCKER_LOCAL = alvinchow-service:$(TAG)
3+
DOCKER_REPO = something.dkr.ecr.us-west-2.amazonaws.com/alvinchow-service
4+
DOCKER_REMOTE = $(DOCKER_REPO):$(TAG)
5+
6+
.PHONY: build
7+
build:
8+
docker build -t $(DOCKER_LOCAL) --build-arg FURY_AUTH .
9+
10+
push:
11+
docker tag $(DOCKER_LOCAL) $(DOCKER_REMOTE)
12+
docker push $(DOCKER_REMOTE)
13+
14+
buildpush: build push
15+
16+
buildproto:
17+
alvinchow_service/api/grpc/makeprotobufs
18+
19+
proto: buildproto
20+
mkdir -p dist && \
21+
cp -r alvinchow_service/api/grpc/dist/*.tar.gz dist

Pipfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[[source]]
7+
name = "fury"
8+
url = "https://pypi.fury.io/alvinchow86"
9+
verify_ssl = true
10+
11+
[dev-packages]
12+
pytest = "~=4.0"
13+
pytest-mock = "~=3.1"
14+
freezegun = "~=0.3"
15+
flake8 = "==3.8"
16+
pytest-cov = "==2.8.1"
17+
pytest-alvin = "==0.0.2"
18+
19+
[packages]
20+
# Core
21+
apscheduler = "==3.6.3"
22+
pytz = "==2020.1"
23+
python-dateutil = "==2.8.1"
24+
alvin-python-lib = "==0.0.1"
25+
# Database, Caching
26+
alembic = "==1.4.2"
27+
psycopg2-binary = "==2.8.3"
28+
sqlalchemy = "==1.3.17"
29+
redis = "==3.5.2"
30+
sqlalchemy-postgres-bigid = "==0.1.0"
31+
# Web
32+
flask = "==1.1.2"
33+
# Queueing
34+
celery = {extras = ["redis"],version = "==4.4.2"}
35+
# gRPC
36+
Cython = "==0.29.15"
37+
grpcio = "==1.29.0"
38+
grpcio-status = "==1.29.0"
39+
protobuf = "==3.11.3"
40+
alvin-grpc-lib = "==0.0.1"
41+
protobuf_serialization = "==0.1.1"
42+
43+
# Monitoring
44+
sentry-sdk= "==0.14.4"
45+
blinker = "==1.4"
46+
scout-apm = "==2.14.1"
47+
# Other
48+
click = "~=7.0"
49+
ipython = "~=7.2"
50+
watchdog = "==0.9.0"
51+
rules = "==2.0.1"
52+
easydict = "==1.9"
53+
54+
[requires]
55+
python_version = "3.8"

0 commit comments

Comments
 (0)
0