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.
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_applicationdirectory to the name of your application - The
hello-worldstep 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_NAMEinDockerfile(line 4)setup.pyfile (Start at line 17)- The directory for linting in
.circleci/config.yml(line 60)
This deploys using Dockerhub and CircleCI. To enable deployment:
- Enable the project in circleci
- Add the
DOCKER_USER,DOCKER_PASS, andDOCKERHUB_REPOenvironment 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
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
While iterating on development, we recommend using virtualenv to run the tests locally.
Install requirements locally:
python3 -m virtualenv venv
source venv/bin/activate
make install-requirements
Run tests locally:
pytest tests/
You can run the tests just as CI does by building the container and running the tests.
make clean && make build
make test