Skip to main content

mirror-git-to-s3

PyPI package Test suite Code coverage

Python functions and CLI to mirror public git repositories available on HTTP(S) to S3. Essentially converts smart protocol git repositories to the so-called dumb protocol. Does not use temporary disk space, and uses streaming under the hood. This should allow the mirroring to be run on systems that don't have much disk or available memory, even on repositories with large objects.

This project mirrors objects stored on Large File Storage (LFS). Note however LFS objects are not accessible via the dumb protocol. To work around this, you can use git-lfs-http-mirror that fires up a temporary local LFS server during git commands.

At the time of writing repositories with many objects can be slow to mirror.

https://user-images.githubusercontent.com/13877/226190499-e4c6f277-2a7b-4a37-b2ed-b5cd808ead3b.mov

Installation

pip install mirror-git-to-s3

Usage

To mirror one or more repositories from Python, use the mirror_repos function, passing it an iterable of (source, target) mappings.

from mirror_git_to_s3 import mirror_repos

mirror_repos((
    ('https://example.test/my-first-repo', 's3://my-bucket/my-first-repo'),
    ('https://example.test/my-second-repo', 's3://my-bucket/my-second-repo'),
))

Once a repository is mirrored to a bucket that doesn't need authentication to read, it can be cloned using standard git commands using the virtual host or path of the S3 bucket.

git clone https://my-bucket.s3.eu-west-2.amazonaws.com/my-first-repo

Under the hood, boto3 is used to communicate with S3. The boto3 client is constructed automatically, but you can override the default by using the get_s3_client argument.

import boto3
from mirror_git_to_s3 import mirror_repos

mirror_repos(mappings(), get_s3_client=lambda: boto3.client('s3'))

This can be used to mirror to S3-compatible storage.

import boto3
from mirror_git_to_s3 import mirror_repos

mirror_repos(mappings(), get_s3_client=lambda: boto3.client('s3', endpoint_url='http://my-host.com/'))

To mirror repositories from the the command line pairs of --source --target options can be passed to mirror-git-to-s3.

mirror-git-to-s3 \
    --source 'https://example.test/my-first-repo' --target 's3://my-bucket/my-first-repo' \
    --source 'https://example.test/my-second-repo' --target 's3://my-bucket/my-second-repo'

At the time of writing, there is no known standard way of discovering a set of associated git repositories, hence to remain general, this project must be told the source and target addresses of each repository explicitly.

Under the hood

The project requests a git packfile with all objects from each source, separates it into its component git objects, and stores each separately in S3 as an S3 object.

  • The packfile is requested via a single POST request. Its response is stream-processed to avoid loading it all into memory at once.

  • An attempt is made to split processing of the response into separate threads where possible. Stream processing is somewhat at-odds with parallel processing, but there are still parts that can be moved to separate threads.

  • Where parallism is not possible, for example when a delta object in the packfile has to wait for its base object, a threading.Event is used for the thread to wait.

  • Delta object processing is quite slow. A delta object is an object whose contents aren't given directly in the packfile, but rather as instructions based on the contents of another object. Each instruction can result in a request to S3, which has a high latency. Efforts are made to reduce the effects of this, such as fetching more data than needed each time and caching the results, but this can probably still be improved.

  • So far a deadlock has not been observed, but this depends on the packfile being returned in an order where base objects are always before the deltas that depend on them.

Metadata

Release files for mirror-git-to-s3 0.0.24

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mirror-git-to-s3 0.0.24
File Size Uploaded Provenance
mirror_git_to_s3-0.0.24.tar.gz 10.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mirror-git-to-s3 0.0.24
File Interpreter ABI Platform
mirror_git_to_s3-0.0.24-py3-none-any.whl Python 3 none any Details

Total release size: 20.8 kB

Release files / mirror_git_to_s3-0.0.24.tar.gz

Download URL mirror_git_to_s3-0.0.24.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5b3ec9d1a480e043983a2beb900fadbbd8798833b5da84f794b9ece350ab9107
BLAKE2b-256 checksum
How to use checksums
7eb60131ac0dada42516e644dddb4c31f2d106e56530fe2758b5180b87df673c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2024.

Transparency log

Release files / mirror_git_to_s3-0.0.24-py3-none-any.whl

Download URL mirror_git_to_s3-0.0.24-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f8f5a484b28170e3a98b224f3dc8c2aa527bdc9222d9d4a422f8d2c24faf0fb
BLAKE2b-256 checksum
How to use checksums
cffaaf8819042de0ab6551c327aad86b931dd788754d47a95e4072c723d8bc58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2024.

Transparency log

Security for mirror-git-to-s3 0.0.24

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mirror_git_to_s3-0.0.24.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2024.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page