Skip to main content

Easily create Concourse resource types in Python.

Project description

ConcourseTools logo

version pre-release python coverage pre-commit

A Python package for easily implementing Concourse resource types.

About

Concourse CI is an "open-source continuous thing-doer" designed to enable general automation with intuitive and re-usable components. Resources represent all external inputs and outputs to and from the pipeline, and many of these have been implemented in open source. In order to best leverage the Python ecosystem of open-source packages, Concourse Tools abstracts away the implementation details of Concourse resource types to allow users to focus on writing the code they want to run.

Installation

Install from GitHub, or from PyPI:

$ pip install concoursetools

Usage

Start by familiarising yourself with the Concourse resource "rules" in the documentation. To recreate that example, start by creating a new concourse.py file in your repository. The first step is to create a Version subclass:

from dataclasses import dataclass
from concoursetools import TypedVersion


@dataclass()
class GitVersion(TypedVersion):
    ref: str

Next, create a subclass of ConcourseResource:

from concoursetools import ConcourseResource


class GitResource(ConcourseResource[GitVersion]):

    def __init__(self, uri: str, branch: str, private_key: str) -> None:
        super().__init__(GitVersion)
        self.uri = uri
        self.branch = branch
        self.private_key = private_key

Here, the parameters in the __init__ method will be taken from the source configuration for the resource. Now, implement the three methods required to define the behaviour of the resource:

from pathlib import Path
from typing import Any
from concoursetools import BuildMetadata


class GitResource(ConcourseResource[GitVersion]):
    ...

    def fetch_new_versions(self, previous_version: GitVersion | None) -> list[GitVersion]:
        ...

    def download_version(self, version: GitVersion, destination_dir: pathlib.Path,
                         build_metadata: BuildMetadata, **kwargs: Any) -> tuple[GitVersion, dict[str, str]]:
        ...

    def publish_new_version(self, sources_dir: pathlib.Path, build_metadata: BuildMetadata,
                            **kwargs: Any) -> tuple[GitVersion, dict[str, str]]:
        ...

The keyword arguments in download_version and publish_new_version correspond to params in the get step, and get_params in the put step respectively.

Once you are happy with the resource, generate the Dockerfile using the Concourse Tools CLI:

$ python3 -m concoursetools dockerfile .

Finally, upload the Docker image to a registry, and use it in your pipelines!

For more information - and for more in-depth examples - see the documentation.

Bugs and Contributions

Concourse Tools is in beta, and still under somewhat-active development. Contributions, fixes, suggestions and bug reports are all welcome: Please familiarise yourself with our contribution guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

concoursetools-0.8.0rc1.tar.gz (62.9 kB view details)

Uploaded Source

Built Distribution

concoursetools-0.8.0rc1-py3-none-any.whl (51.4 kB view details)

Uploaded Python 3

File details

Details for the file concoursetools-0.8.0rc1.tar.gz.

File metadata

  • Download URL: concoursetools-0.8.0rc1.tar.gz
  • Upload date:
  • Size: 62.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for concoursetools-0.8.0rc1.tar.gz
Algorithm Hash digest
SHA256 7d17cec57c0f7a14f9093cf43896622516749b52e490bdcc6928d9ff2d00b1eb
MD5 f7579ba95dcd4e876ecd19c1c39e1021
BLAKE2b-256 d90c7356717f99d98b3dc16bb1ea50a5d191833a0706419c52f2de7329715f7d

See more details on using hashes here.

File details

Details for the file concoursetools-0.8.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for concoursetools-0.8.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 5df07d3526338fffac751b39c1b4c523d5c313bb861f1318345d53cb32071660
MD5 5cab7929ec65ae6d8dae3783a6545b6b
BLAKE2b-256 b03be888338c0cbeb9ae9dbc9bf4e718b681856d30d9d716381e9016e3097d61

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page