Skip to content

CLI tool for creating a Python Package Repository in GCS bucket.

License

Notifications You must be signed in to change notification settings

tj-pypi/gcs-pypi

Repository files navigation

gcs_pypi

Python package

gcs_pypi is a CLI for creating a Python Package Repository in an GCS bucket.

Getting started

Installation

Install gcs_pypi using pip:

pip install gcs_pypi

Usage

GCS Bucket

  • Create a new bucket

IAM (Role & Service Account)

Setup service account with the following permissions

storage.buckets.get
storage.buckets.getIamPolicy
storage.buckets.update
storage.objects.create
storage.objects.delete
storage.objects.get
storage.objects.getIamPolicy
storage.objects.list
storage.objects.setIamPolicy

Recommended that you create a custom Role which can be inherited by the service account

Example

  • Create Role "PYPI"

  • Assign Permissions

storage.buckets.get
storage.buckets.getIamPolicy
storage.buckets.update
storage.objects.create
storage.objects.delete
storage.objects.get
storage.objects.getIamPolicy
storage.objects.list
storage.objects.setIamPolicy
  • Create a Service Account e.g pypi

  • Select the "PYPI" Role created above

  • Add a condition to limit access to only that GCS bucket

resource.name == "mybucket"

Visit Cloud IAM Conditions for more information

Distributing packages

You can now use gcspypi to create Python packages and upload them to your GCS bucket. To hide packages from the public, you can use the --private option to prevent the packages from being accessible directly via the GCS bucket (they will only be accessible via your Domain or alternatively you can specify a secret subdirectory using the --secret option:

cd /path/to/your-project/
gcspypi --bucket mybucket [--private] [--secret SECRET]

Cache Header

Set cache-control header for index.html

$ gsutil setmeta -h "cache-control:public, must-revalidate, proxy-revalidate, max-age=0" gs://[BUCKET]/index.html

Installing packages

Install your packages using pip by pointing the --extra-index-url to your Custom domain (optionally followed by a secret subdirectory):

pip install your-project --extra-index-url https://pypi.example.com/SECRET/

Alternatively, you can configure the index URL in ~/.pip/pip.conf:

[global]
extra-index-url = https://pypi.example.com/SECRET/

Credits