An example repo for a generic, dockerized Python project
Перейти к файлу
Frank Bertsch 83ff290c78 Shell doesn't call entrypoint 2019-10-15 11:43:16 -04:00
.circleci Add flake8 config file 2019-10-14 21:11:45 -04:00
bin Add entrypoint 2019-10-07 12:37:01 -04:00
python_application Run linter 2019-10-07 12:04:46 -04:00
requirements Add ci linting 2019-10-14 11:07:18 -04:00
tests Initial Commit 2019-10-07 11:32:32 -04:00
.flake8 Add flake8 config file 2019-10-14 21:11:45 -04:00
Dockerfile Update README 2019-10-07 12:03:44 -04:00
Makefile Shell doesn't call entrypoint 2019-10-15 11:43:16 -04:00
README.md Add ci linting 2019-10-14 11:07:18 -04:00
docker-compose.yml Clarify running with GCP auth 2019-10-11 15:58:38 -04:00
setup.py Run linter 2019-10-07 12:04:46 -04:00

README.md

CircleCI

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:

  1. README.md
  2. Change the python_application directory to the name of your application
  3. The hello-world step in Makefile. You can simply remove it and use make run COMMAND="python-application hello-world" (replaced with what your app is called) instead
  4. application.py (including the correponding runner in __main__.py, as well as the test in tests/test_application.py, and that test file's name)
  5. APP_NAME in Dockerfile (line 4)
  6. setup.py file (Start at line 17)
  7. The directory for linting in .circleci/config.yml (line 60)

Setup for Deployment

This deploys using Dockerhub and CircleCI. To enable deployment:

  1. Enable the project in circleci
  2. Add the DOCKER_USER, DOCKER_PASS, and DOCKERHUB_REPO environment variables in the circleci UI (under settings -> 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:

  1. Create a new service account in the BQ Console
  2. Give it access to the tools you need: e.g. BigQuery, GCS, Dataflow
  3. Create a JSON key for that service account
  4. Set that key locally as GCLOUD_SERVICE_ACCOUNT
  5. 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