Skip to content

SatelCreative/docker-python-base

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Satel's Docker Python base

Purpose

This docker image is a base for Satel webapp's python backend. The standard packages we use in most projects are already installed. The folder structure and commands provide the standard framework for development and deployment to production of the app.

Folder structure

The /python folder is the base folder for all the files of this images such as the entrypoint.sh. Then the subfolders organize the app files:

  • /python/app holds the source of the app
  • /python/static holds the static files served by the app such as static html files
  • /python/logs is meant for the log files generated by the app
  • /python/files is for files uploaded through the app

Commands

The entrypoint of this docker image provides standard commands for our app's docker image to call with CMD in the Dockerfile. These commands are effectively run as arguments of the entrypoint such as:

/python/entrypoint.sh startapp

The .bashrc file contains aliases so that one can also just call startapp from within the docker container.

startapp

Run the app in production mode. The app is expected to be a FastAPI app defined in /python/app/webapp/main.py such that the app is executed with the command:

uvicorn --host 0.0.0.0 --port 8000 webapp.main:app

You can replace webapp.main:app by setting the first argument of the startapp command such that for example:

startapp myapp:theapp

The command will try to load the config.sh from multiple locations:

  1. From the docker secrets folder
  2. From the current directory, being /python/app
  3. If the previous locations don't have a config.sh file, the config.sh.example file is loaded from the current directory if it exists as a fallback. This is useful for CI/CD environments for which the example values are good enough to run the tests

developapp

Run the app in development mode with watchmedo from the watchdog python package such that the app restarts whenever the code changes in /python/app. The same default location (webapp.main:app) and option to change the location as startapp are used for developapp.

The configuration file is loaded the same way as in startapp.

validatecode

This command is used during development to automatically run the pytest tests, the mypy typing check and the flake8 linting check whenever the code changes.

The flake8 linting includes isort import module sorting thanks to the flake8-isort plugin.

This code validation command executes the /python/testsuite.sh script which can be overwritten with custom code validation.

runtests

This command runs only the pytest tests for CI/CD purposes. It outputs the tests and code coverage results in the /python/app/unittesting.xml and /python/app/coverage.xml files respectively.

A coverage configuration file can be provided at python/app/coverage.conf.