Skip to content

Commit

Permalink
adding prefect data loading
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyweb committed Oct 23, 2020
1 parent 0027fa7 commit d1a27b2
Show file tree
Hide file tree
Showing 20 changed files with 1,623 additions and 28 deletions.
17 changes: 1 addition & 16 deletions .github/workflows/Daily_Backend_Update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,9 @@ name: Daily_Backend_Update

on:
schedule:
- cron: '0 7 * * *'
- cron: '10 7 * * *'

jobs:
dev_update:
runs-on: ubuntu-latest
steps:
- name: run update script on AWS dev
uses: appleboy/ssh-action@master
with:
username: ec2-user
host: ${{ secrets.AWS_SSH_HOST_DEV }}
key: ${{ secrets.AWS_SSH_PEM_KEY }}
command_timeout: 60m
script: |
set -e
cd 311-data/server
docker-compose run --rm api python bin/db_update.py
prod_update:
runs-on: ubuntu-latest
steps:
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/Daily_Backend_Update_Dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Daily_Backend_Update_Dev

on:
schedule:
- cron: '0 7 * * *'

jobs:
dev_update:
runs-on: ubuntu-latest
steps:
- name: run update script on AWS dev
uses: appleboy/ssh-action@master
with:
username: ec2-user
host: ${{ secrets.AWS_SSH_HOST_DEV }}
key: ${{ secrets.AWS_SSH_PEM_KEY }}
command_timeout: 60m
script: |
set -e
cd 311-data/server
docker-compose run --rm prefect python flow.py
31 changes: 21 additions & 10 deletions server/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.7-slim-buster

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE 1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED 1

# Install gcc and g++ to build pysupercluster (may not need)
RUN apt-get update \
&& apt-get install -y \
gcc \
g++ \
&& apt-get clean

WORKDIR /home/api
# Install pip requirements
ADD requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY requirements.txt .
# Add the application code
WORKDIR /app
ADD . /app

RUN pip install --no-cache-dir -r /home/api/requirements.txt
# Switch to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
RUN useradd appuser && chown -R appuser /app
USER appuser

# Tell Prefect where to look for the config
ENV PYTHONPATH=.:/app/code
ENV APP_HOST=0.0.0.0
# need add the src folder to sys.path for compatibility
ENV PYTHONPATH=.:/home/api/code:/home/api/src

EXPOSE 5000

COPY . .

CMD gunicorn lacity_data_api.asgi:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:5000
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD python code/run.py
11 changes: 9 additions & 2 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ services:
ports:
- target: ${APP_PORT}
published: ${API_HOST_PORT}
# command:
# - gunicorn lacity_data_api.asgi:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:5000
command: gunicorn lacity_data_api.asgi:app -w 4 -k uvicorn.workers.UvicornWorker --log-level info -b 0.0.0.0:5000
# volumes:
# - ./api/:/home/api
depends_on:
- db
- redis

prefect:
container_name: 311-prefect
build: ./prefect
environment:
PREFECT__CONTEXT__SECRETS__DSN: postgresql://${DB_USER}:${DB_PASS}@db:5432/${DB_NAME}
depends_on:
- db

volumes:
backend_data:
31 changes: 31 additions & 0 deletions server/prefect/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
**/output/
**/results/
**/dask-worker-space/
**/.github
**/docs

**/__pycache__
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md
136 changes: 136 additions & 0 deletions server/prefect/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Added stuff for project
results/
output/
dask-worker-space/
.vscode/
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
26 changes: 26 additions & 0 deletions server/prefect/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.7-slim-buster

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE 1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED 1

# Install gcc to build psutil wheel used by Dask
RUN apt-get update -y && apt-get install -y gcc

# Install pip requirements
ADD requirements.txt .
RUN python -m pip install -r requirements.txt

# Add the application code
WORKDIR /app
ADD . /app

# Switch to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
RUN useradd appuser && chown -R appuser /app
USER appuser

# Tell Prefect where to look for the config
ENV PREFECT__USER_CONFIG_PATH ./config.toml
17 changes: 17 additions & 0 deletions server/prefect/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"
flake8 = "*"

[packages]
prefect = "*"
sodapy = "*"
psycopg2-binary = "*"
pendulum = "*"

[requires]
python_version = "3.7"
Loading

0 comments on commit d1a27b2

Please sign in to comment.