Skip to content

Instantly share code, notes, and snippets.

@pauldougan
Last active May 27, 2020 12:04
Show Gist options
  • Select an option

  • Save pauldougan/408f6b33a7f6b6f51da2bdfc3d9b809b to your computer and use it in GitHub Desktop.

Select an option

Save pauldougan/408f6b33a7f6b6f51da2bdfc3d9b809b to your computer and use it in GitHub Desktop.
python notes on GOV.UK PaaS

Python Notes

Some notes on the use of python with GOV.UK PaaS

Buildpacks

The python buildpack docs are at https://docs.cloudfoundry.org/buildpacks/python/index.html

The current python buildpack is v1.7.13 https://github.com/cloudfoundry/python-buildpack/releases/tag/v1.7.13

There is a pending buildpack upgrade to v1.7.14 https://github.com/cloudfoundry/python-buildpack/releases/tag/v1.7.1

we expect the upgrade to happen by DATE

You can specify a custom buildpack by explicitly specifying the version using the -b switch on the the cli

cf push -b https://github.com/cloudfoundry/python-buildpack/#v1.7.14 foobar

Python versions

Python 2 is deprecated

supports python 3.8.2

specify the version to use in your app in the runtime.txt file

Start command

specify the start command in the Procfile

Dependencies

add dependencies to requirements.txt

module description
boto3 amazon api
cloudfoundry-client cloud foundry client
schedule run scheduled tasks

Sample code

There is a simple 50 line sample app in the incubator project that uses Flask and gunicorn https://github.com/alphagov/paas-incubator/tree/master/helloworld-examples/python-flask

Patterns of usage

Scheduled tasks

There is no intrinsic support for scheduled tasks in the paas see https://github.com/alphagov/paas-roadmap/issues/52 however the python schedule module provides a scheduling mechanism https://pypi.org/project/schedule/

Access the CF API from python

use the cloudfoundry-client module to access the cloud foundry api from python https://github.com/cloudfoundry-community/cf-python-client

Run task in a container

cf tasks supports execution in a container https://docs.cloudfoundry.org/devguide/using-tasks.html for database migrations and other batch processing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment