83ff290c78 | ||
---|---|---|
.circleci | ||
bin | ||
python_application | ||
requirements | ||
tests | ||
.flake8 | ||
Dockerfile | ||
Makefile | ||
README.md | ||
docker-compose.yml | ||
setup.py |
README.md
Generic Dockerized Python Application
This repository is meant to be a sample application. You can:
- Use pieces of this in existing projects
- Clone and edit for a new project
The goal is to remove boilerplate that goes along with dockerizing a python application. At Mozilla, we expect these will largely be run in GKE using Airflow.
Cloning and Replacing
If you're going to clone this and start a new project, here's the parts you need to replace:
README.md
- Change the
python_application
directory to the name of your application - The
hello-world
step inMakefile
. You can simply remove it and usemake run COMMAND="python-application hello-world"
(replaced with what your app is called) instead application.py
(including the correponding runner in__main__.py
, as well as the test intests/test_application.py
, and that test file's name)APP_NAME
inDockerfile
(line 4)setup.py
file (Start at line 17)- The directory for linting in
.circleci/config.yml
(line 60)
Setup for Deployment
This deploys using Dockerhub and CircleCI. To enable deployment:
- Enable the project in circleci
- Add the
DOCKER_USER
,DOCKER_PASS
, andDOCKERHUB_REPO
environment variables in the circleci UI (undersettings
->Environment Variables
)
NOTE: When running on Mozilla infrastructure, dataops can set these for your project. Create a bug here
Running GCP Jobs
Figuring out access credentials is hard. To test out GCP work, you'll need to have a test project.
Once you have one, create a new service account:
- Create a new service account in the BQ Console
- Give it access to the tools you need: e.g. BigQuery, GCS, Dataflow
- Create a JSON key for that service account
- Set that key locally as
GCLOUD_SERVICE_ACCOUNT
- Run your job using
make run ...
, which will automatically use that service account
Development and Testing
While iterating on development, we recommend using virtualenv to run the tests locally.
Run tests locally
Install requirements locally:
python3 -m virtualenv venv
source venv/bin/activate
make install-requirements
Run tests locally:
pytest tests/
Run tests in docker
You can run the tests just as CI does by building the container and running the tests.
make clean && make build
make test